summaryrefslogtreecommitdiff
path: root/src/network.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/network.h')
-rw-r--r--src/network.h73
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;
+};
+
+}