diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2023-08-27 10:37:20 +0200 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2023-08-27 16:32:21 +0200 |
commit | a40f12cf820b3e11cc72f7b20046c8077ab0d0a5 (patch) | |
tree | 5086866402c923b3def3c55674dfa260926b564c /src/network.cpp | |
parent | 09c1e987f6ddfdefb26b6a5f359363303720d5fb (diff) |
Network: identity announce and update in protocol object
Diffstat (limited to 'src/network.cpp')
-rw-r--r-- | src/network.cpp | 30 |
1 files changed, 4 insertions, 26 deletions
diff --git a/src/network.cpp b/src/network.cpp index 7a5a804..a3d1130 100644 --- a/src/network.cpp +++ b/src/network.cpp @@ -109,14 +109,7 @@ void Server::addPeer(const string & node, const string & service) const for (addrinfo * rp = result.get(); rp != nullptr; rp = rp->ai_next) { if (rp->ai_family == AF_INET6) { - Peer & peer = p->getPeer(*(sockaddr_in6 *)rp->ai_addr); - - vector<NetworkProtocol::Header::Item> header; - { - shared_lock lock(p->selfMutex); - header.push_back(NetworkProtocol::Header::AnnounceSelf { p->self.ref()->digest() }); - } - peer.connection.send(peer.partStorage, header, {}, false); + p->getPeer(*(sockaddr_in6 *)rp->ai_addr); return; } } @@ -310,7 +303,7 @@ Server::Priv::Priv(const Head<LocalState> & local, const Identity & self): if (sock < 0) throw std::system_error(errno, std::generic_category()); - protocol = NetworkProtocol(sock); + protocol = NetworkProtocol(sock, self); int disable = 0; // Should be disabled by default, but try to make sure. On platforms @@ -415,18 +408,13 @@ void Server::Priv::doAnnounce() if (lastAnnounce + announceInterval < now) { shared_lock slock(selfMutex); - NetworkProtocol::Header header({ - NetworkProtocol::Header::AnnounceSelf { self.ref()->digest() }, - }); - - vector<uint8_t> bytes = header.toObject(pst).encode(); for (const auto & in : bcastAddresses) { sockaddr_in sin = {}; sin.sin_family = AF_INET; sin.sin_addr = in; sin.sin_port = htons(discoveryPort); - protocol.sendto(bytes, sin); + protocol.announceTo(sin); } lastAnnounce += announceInterval * ((now - lastAnnounce) / announceInterval); @@ -659,17 +647,7 @@ void Server::Priv::handleLocalHeadChange(const Head<LocalState> & head) if (auto id = head->identity()) { if (*id != self) { self = *id; - - vector<NetworkProtocol::Header::Item> hitems; - for (const auto & r : self.refs()) - hitems.push_back(NetworkProtocol::Header::AnnounceUpdate { r.digest() }); - for (const auto & r : self.updates()) - hitems.push_back(NetworkProtocol::Header::AnnounceUpdate { r.digest() }); - - NetworkProtocol::Header header(hitems); - - for (const auto & peer : peers) - peer->connection.send(peer->partStorage, header, { **self.ref() }, false); + protocol.updateIdentity(*id); } } } |