From 3407f97096fd66aeb25f1cd26ba002d3f8a23127 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 27 Aug 2023 11:41:41 +0200 Subject: Network: announce protocol version --- src/network/protocol.cpp | 8 ++++++++ src/network/protocol.h | 4 ++++ 2 files changed, 12 insertions(+) (limited to 'src/network') 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 { Header::AnnounceSelf { self->ref()->digest() }, + Header::Version { defaultVersion }, }; conn->send(self->ref()->storage(), header, {}, false); } @@ -143,6 +144,7 @@ void NetworkProtocol::announceTo(variant addr) bytes = Header({ Header::AnnounceSelf { self->ref()->digest() }, + Header::Version { defaultVersion }, }).toObject(self->ref()->storage()).encode(); } @@ -409,6 +411,9 @@ optional 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(&item)) ritems.emplace_back("ACK", st.ref(ptr->value)); + else if (const auto * ptr = get_if(&item)) + ritems.emplace_back("VER", ptr->value); + else if (const auto * ptr = get_if(&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, -- cgit v1.2.3