From b97b503408911130d24d7f07f9247dca8314a316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Wed, 1 Jan 2020 21:27:11 +0100 Subject: Respond to data requests from network --- src/network.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/network.h') 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 &); +}; + struct TransportHeader { enum class Type { @@ -43,6 +52,8 @@ struct TransportHeader TransportHeader(const vector & items): items(items) {} static optional load(const Ref &); + static optional load(const Object &); + Object toObject() const; Ref store(const Storage & st) const; const vector 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> peers; + vector outgoing; + int sock; vector bcastAddresses; }; -- cgit v1.2.3