From ebdbf9a1cd5308bf1c64d8dc912e0ea0e9ac8633 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Fri, 27 Dec 2019 17:20:04 +0100 Subject: Network server sending announcements --- src/network.h | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/network.h (limited to 'src/network.h') diff --git a/src/network.h b/src/network.h new file mode 100644 index 0000000..bf01cfb --- /dev/null +++ b/src/network.h @@ -0,0 +1,73 @@ +#pragma once + +#include + +#include +#include +#include +#include + +#include + +using std::condition_variable; +using std::mutex; +using std::optional; +using std::string; +using std::thread; +using std::variant; +using std::vector; + +namespace chrono = std::chrono; +using chrono::steady_clock; + +namespace erebos { + +struct TransportHeader +{ + enum class Type { + Acknowledged, + DataRequest, + DataResponse, + AnnounceSelf, + AnnounceUpdate, + ChannelRequest, + ChannelAccept, + ServiceType, + ServiceRef, + }; + + struct Item { + const Type type; + const variant value; + }; + + TransportHeader(const vector & items): items(items) {} + static optional load(const Ref &); + Ref store(const Storage & st) const; + + const vector items; +}; + +struct Server::Priv +{ + Priv(const Identity & self); + ~Priv(); + void doListen(); + void doAnnounce(); + + constexpr static uint16_t discoveryPort { 29665 }; + constexpr static chrono::seconds announceInterval { 60 }; + + mutex dataMutex; + condition_variable announceCondvar; + bool finish = false; + + Identity self; + thread threadListen; + thread threadAnnounce; + + int sock; + vector bcastAddresses; +}; + +} -- cgit v1.2.3