summaryrefslogtreecommitdiff
path: root/src/network/protocol.h
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2023-08-16 20:53:58 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2023-08-16 21:49:39 +0200
commitb09e73f0abcc386719a2235cc3ae61fb1cbfc5ca (patch)
tree462085ac8fb592f4a2c07446058a7e761b51dfac /src/network/protocol.h
parent2ed8103ff1c0fca7372b3c3888f590ba41c525e6 (diff)
Move network header definitions to protocol module
Diffstat (limited to 'src/network/protocol.h')
-rw-r--r--src/network/protocol.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/network/protocol.h b/src/network/protocol.h
index a9bbaff..8aa22a2 100644
--- a/src/network/protocol.h
+++ b/src/network/protocol.h
@@ -1,5 +1,7 @@
#pragma once
+#include <erebos/storage.h>
+
#include <netinet/in.h>
#include <cstdint>
@@ -7,10 +9,12 @@
#include <mutex>
#include <variant>
#include <vector>
+#include <optional>
namespace erebos {
using std::mutex;
+using std::optional;
using std::unique_ptr;
using std::variant;
using std::vector;
@@ -28,6 +32,8 @@ public:
class Connection;
+ struct Header;
+
struct NewConnection;
struct ConnectionReadReady;
struct ProtocolClosed {};
@@ -85,4 +91,34 @@ private:
struct NetworkProtocol::NewConnection { Connection conn; };
struct NetworkProtocol::ConnectionReadReady { Connection::Id id; };
+struct NetworkProtocol::Header
+{
+ enum class Type {
+ Acknowledged,
+ DataRequest,
+ DataResponse,
+ AnnounceSelf,
+ AnnounceUpdate,
+ ChannelRequest,
+ ChannelAccept,
+ ServiceType,
+ ServiceRef,
+ };
+
+ struct Item {
+ const Type type;
+ const variant<PartialRef, UUID> value;
+
+ bool operator==(const Item &) const;
+ bool operator!=(const Item & other) const { return !(*this == other); }
+ };
+
+ Header(const vector<Item> & items): items(items) {}
+ static optional<Header> load(const PartialRef &);
+ static optional<Header> load(const PartialObject &);
+ PartialObject toObject() const;
+
+ const vector<Item> items;
+};
+
}