summaryrefslogtreecommitdiff
path: root/src/network.h
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2020-01-01 21:27:11 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2020-01-04 21:29:00 +0100
commitb97b503408911130d24d7f07f9247dca8314a316 (patch)
tree3b4202b42bbe51b2cd5b3720e755a804d7872159 /src/network.h
parentebdbf9a1cd5308bf1c64d8dc912e0ea0e9ac8633 (diff)
Respond to data requests from network
Diffstat (limited to 'src/network.h')
-rw-r--r--src/network.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/network.h b/src/network.h
index bf01cfb..ad29496 100644
--- a/src/network.h
+++ b/src/network.h
@@ -14,6 +14,7 @@ using std::mutex;
using std::optional;
using std::string;
using std::thread;
+using std::unique_ptr;
using std::variant;
using std::vector;
@@ -22,6 +23,14 @@ using chrono::steady_clock;
namespace erebos {
+struct Peer
+{
+ const int sock;
+ const sockaddr_in addr;
+
+ void send(const struct TransportHeader &, const vector<Object> &);
+};
+
struct TransportHeader
{
enum class Type {
@@ -43,6 +52,8 @@ struct TransportHeader
TransportHeader(const vector<Item> & items): items(items) {}
static optional<TransportHeader> load(const Ref &);
+ static optional<TransportHeader> load(const Object &);
+ Object toObject() const;
Ref store(const Storage & st) const;
const vector<Item> items;
@@ -55,6 +66,9 @@ struct Server::Priv
void doListen();
void doAnnounce();
+ Peer & getPeer(const sockaddr_in & paddr);
+ void handlePacket(Peer &, const TransportHeader &);
+
constexpr static uint16_t discoveryPort { 29665 };
constexpr static chrono::seconds announceInterval { 60 };
@@ -66,6 +80,9 @@ struct Server::Priv
thread threadListen;
thread threadAnnounce;
+ vector<unique_ptr<Peer>> peers;
+ vector<struct TransportHeader> outgoing;
+
int sock;
vector<in_addr> bcastAddresses;
};