diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2019-12-27 17:20:04 +0100 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2019-12-27 22:59:53 +0100 |
commit | ebdbf9a1cd5308bf1c64d8dc912e0ea0e9ac8633 (patch) | |
tree | f4a09848ef09bfd816b8aefd6dc3b4e5a5440905 /src/network.h | |
parent | a02ef25970cb97ab4c29b3859799062431ae668b (diff) |
Network server sending announcements
Diffstat (limited to 'src/network.h')
-rw-r--r-- | src/network.h | 73 |
1 files changed, 73 insertions, 0 deletions
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 <erebos/network.h> + +#include <condition_variable> +#include <mutex> +#include <thread> +#include <vector> + +#include <netinet/in.h> + +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<Ref, string> value; + }; + + TransportHeader(const vector<Item> & items): items(items) {} + static optional<TransportHeader> load(const Ref &); + Ref store(const Storage & st) const; + + const vector<Item> 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<in_addr> bcastAddresses; +}; + +} |