mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-07 13:03:45 +02:00
.
This commit is contained in:
parent
64f7185e3a
commit
b1c8e6ad59
1 changed files with 20 additions and 14 deletions
|
@ -90,9 +90,14 @@ struct PeerInfo
|
||||||
|
|
||||||
static Identity self;
|
static Identity self;
|
||||||
static std::atomic_bool run;
|
static std::atomic_bool run;
|
||||||
|
|
||||||
|
static std::vector< SharedPtr<PeerInfo> > newPeers;
|
||||||
|
|
||||||
static std::unordered_map< Identity,SharedPtr<PeerInfo>,IdentityHasher > peersByIdentity;
|
static std::unordered_map< Identity,SharedPtr<PeerInfo>,IdentityHasher > peersByIdentity;
|
||||||
static std::unordered_map< Address,std::set< SharedPtr<PeerInfo> >,AddressHasher > peersByVirtAddr;
|
static std::unordered_map< Address,std::set< SharedPtr<PeerInfo> >,AddressHasher > peersByVirtAddr;
|
||||||
static std::unordered_map< InetAddress,std::set< SharedPtr<PeerInfo> >,InetAddressHasher > peersByPhysAddr;
|
static std::unordered_map< InetAddress,std::set< SharedPtr<PeerInfo> >,InetAddressHasher > peersByPhysAddr;
|
||||||
|
|
||||||
|
static std::mutex newPeers_l;
|
||||||
static std::mutex peersByIdentity_l;
|
static std::mutex peersByIdentity_l;
|
||||||
static std::mutex peersByVirtAddr_l;
|
static std::mutex peersByVirtAddr_l;
|
||||||
static std::mutex peersByPhysAddr_l;
|
static std::mutex peersByPhysAddr_l;
|
||||||
|
@ -130,8 +135,11 @@ static void handlePacket(const int sock,const InetAddress *const ip,const Packet
|
||||||
peer.set(new PeerInfo);
|
peer.set(new PeerInfo);
|
||||||
if (self.agree(id,peer->key)) {
|
if (self.agree(id,peer->key)) {
|
||||||
if (pkt.dearmor(peer->key)) {
|
if (pkt.dearmor(peer->key)) {
|
||||||
if (true) {
|
|
||||||
peer->id = id;
|
peer->id = id;
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> np_l(newPeers_l);
|
||||||
|
newPeers.push_back(peer);
|
||||||
|
}
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> pbi_l(peersByIdentity_l);
|
std::lock_guard<std::mutex> pbi_l(peersByIdentity_l);
|
||||||
peersByIdentity.emplace(id,peer);
|
peersByIdentity.emplace(id,peer);
|
||||||
|
@ -140,11 +148,6 @@ static void handlePacket(const int sock,const InetAddress *const ip,const Packet
|
||||||
std::lock_guard<std::mutex> pbv_l(peersByVirtAddr_l);
|
std::lock_guard<std::mutex> pbv_l(peersByVirtAddr_l);
|
||||||
peersByVirtAddr[id.address()].emplace(peer);
|
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;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
printf("%s HELLO rejected: packet authentication failed" ZT_EOL_S,ip->toString(ipstr));
|
printf("%s HELLO rejected: packet authentication failed" ZT_EOL_S,ip->toString(ipstr));
|
||||||
return;
|
return;
|
||||||
|
@ -406,6 +409,9 @@ int main(int argc,char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
while (run) {
|
while (run) {
|
||||||
|
peersByIdentity_l.lock();
|
||||||
|
printf("* have %lu peers" ZT_EOL_S,(unsigned long)peersByIdentity.size());
|
||||||
|
peersByIdentity_l.unlock();
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue