summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
Diffstat (limited to 'src/network')
-rw-r--r--src/network/protocol.cpp8
-rw-r--r--src/network/protocol.h4
2 files changed, 12 insertions, 0 deletions
diff --git a/src/network/protocol.cpp b/src/network/protocol.cpp
index 89fa327..f001d6c 100644
--- a/src/network/protocol.cpp
+++ b/src/network/protocol.cpp
@@ -108,6 +108,7 @@ NetworkProtocol::Connection NetworkProtocol::connect(sockaddr_in6 addr)
vector<Header::Item> header {
Header::AnnounceSelf { self->ref()->digest() },
+ Header::Version { defaultVersion },
};
conn->send(self->ref()->storage(), header, {}, false);
}
@@ -143,6 +144,7 @@ void NetworkProtocol::announceTo(variant<sockaddr_in, sockaddr_in6> addr)
bytes = Header({
Header::AnnounceSelf { self->ref()->digest() },
+ Header::Version { defaultVersion },
}).toObject(self->ref()->storage()).encode();
}
@@ -409,6 +411,9 @@ optional<NetworkProtocol::Header> NetworkProtocol::Header::load(const PartialObj
if (item.name == "ACK") {
if (auto ref = item.asRef())
items.emplace_back(Acknowledged { ref->digest() });
+ } else if (item.name == "VER") {
+ if (auto ver = item.asText())
+ items.emplace_back(Version { *ver });
} else if (item.name == "REQ") {
if (auto ref = item.asRef())
items.emplace_back(DataRequest { ref->digest() });
@@ -447,6 +452,9 @@ PartialObject NetworkProtocol::Header::toObject(const PartialStorage & st) const
if (const auto * ptr = get_if<Acknowledged>(&item))
ritems.emplace_back("ACK", st.ref(ptr->value));
+ else if (const auto * ptr = get_if<Version>(&item))
+ ritems.emplace_back("VER", ptr->value);
+
else if (const auto * ptr = get_if<DataRequest>(&item))
ritems.emplace_back("REQ", st.ref(ptr->value));
diff --git a/src/network/protocol.h b/src/network/protocol.h
index 51f8d59..545585e 100644
--- a/src/network/protocol.h
+++ b/src/network/protocol.h
@@ -32,6 +32,8 @@ public:
NetworkProtocol & operator=(NetworkProtocol &&);
~NetworkProtocol();
+ static constexpr char defaultVersion[] = "0.1";
+
class Connection;
struct Header;
@@ -111,6 +113,7 @@ struct NetworkProtocol::ConnectionReadReady { Connection::Id id; };
struct NetworkProtocol::Header
{
struct Acknowledged { Digest value; };
+ struct Version { string value; };
struct DataRequest { Digest value; };
struct DataResponse { Digest value; };
struct AnnounceSelf { Digest value; };
@@ -122,6 +125,7 @@ struct NetworkProtocol::Header
using Item = variant<
Acknowledged,
+ Version,
DataRequest,
DataResponse,
AnnounceSelf,