diff --git a/root/root.cpp b/root/root.cpp index 7bc8e8f5e..025f42433 100644 --- a/root/root.cpp +++ b/root/root.cpp @@ -90,9 +90,14 @@ struct PeerInfo static Identity self; static std::atomic_bool run; + +static std::vector< SharedPtr > newPeers; + static std::unordered_map< Identity,SharedPtr,IdentityHasher > peersByIdentity; static std::unordered_map< Address,std::set< SharedPtr >,AddressHasher > peersByVirtAddr; static std::unordered_map< InetAddress,std::set< SharedPtr >,InetAddressHasher > peersByPhysAddr; + +static std::mutex newPeers_l; static std::mutex peersByIdentity_l; static std::mutex peersByVirtAddr_l; static std::mutex peersByPhysAddr_l; @@ -130,20 +135,18 @@ static void handlePacket(const int sock,const InetAddress *const ip,const Packet peer.set(new PeerInfo); if (self.agree(id,peer->key)) { if (pkt.dearmor(peer->key)) { - if (true) { - peer->id = id; - { - std::lock_guard pbi_l(peersByIdentity_l); - peersByIdentity.emplace(id,peer); - } - { - std::lock_guard pbv_l(peersByVirtAddr_l); - peersByVirtAddr[id.address()].emplace(peer); - } - //printf("%s has %s (new)" ZT_EOL_S,ip->toString(ipstr),pkt.source().toString(astr)); - } else { - printf("%s HELLO rejected: invalid identity (locallyValidate() failed)" ZT_EOL_S,ip->toString(ipstr)); - return; + peer->id = id; + { + std::lock_guard np_l(newPeers_l); + newPeers.push_back(peer); + } + { + std::lock_guard pbi_l(peersByIdentity_l); + peersByIdentity.emplace(id,peer); + } + { + std::lock_guard pbv_l(peersByVirtAddr_l); + peersByVirtAddr[id.address()].emplace(peer); } } else { printf("%s HELLO rejected: packet authentication failed" ZT_EOL_S,ip->toString(ipstr)); @@ -406,6 +409,9 @@ int main(int argc,char **argv) } while (run) { + peersByIdentity_l.lock(); + printf("* have %lu peers" ZT_EOL_S,(unsigned long)peersByIdentity.size()); + peersByIdentity_l.unlock(); sleep(1); }