It builds now. The Switch object has been put on a diet. Now to test on the testnet before merge to master.

This commit is contained in:
Adam Ierymenko 2013-07-11 22:25:12 -04:00
parent 339b2314ea
commit 2510f594e5
2 changed files with 39 additions and 15 deletions

View file

@ -267,24 +267,31 @@ bool Switch::unite(const Address &p1,const Address &p2,bool force)
return true; return true;
} }
void Switch::contact(const SharedPtr<Peer> &peer,const InetAddress &atAddr)
{
Demarc::Port fromPort = _r->demarc->pick(atAddr);
_r->demarc->send(fromPort,atAddr,"\0",1,ZT_FIREWALL_OPENER_HOPS);
Mutex::Lock _l(_contactQueue_m);
_contactQueue.push_back(ContactQueueEntry(peer,Utils::now() + ZT_RENDEZVOUS_NAT_T_DELAY,fromPort,atAddr));
// TODO: there needs to be a mechanism to interrupt Node's waiting to
// make sure the fire happens at the right time, but it's not critical.
}
unsigned long Switch::doTimerTasks() unsigned long Switch::doTimerTasks()
{ {
unsigned long nextDelay = ~((unsigned long)0); // big number, caller will cap return value unsigned long nextDelay = ~((unsigned long)0); // big number, caller will cap return value
uint64_t now = Utils::now(); uint64_t now = Utils::now();
{ {
Mutex::Lock _l(_rendezvousQueue_m); Mutex::Lock _l(_contactQueue_m);
for(std::map< Address,RendezvousQueueEntry >::iterator i(_rendezvousQueue.begin());i!=_rendezvousQueue.end();) { for(std::list<ContactQueueEntry>::iterator qi(_contactQueue.begin());qi!=_contactQueue.end();) {
if (now >= i->second.fireAtTime) { if (now >= qi->fireAtTime) {
SharedPtr<Peer> withPeer = _r->topology->getPeer(i->first); TRACE("sending NAT-T HELLO to %s(%s)",qi->peer->address().toString().c_str(),qi->inaddr.toString().c_str());
if (withPeer) { sendHELLO(qi->peer,qi->localPort,qi->inaddr);
TRACE("sending NAT-T HELLO to %s(%s)",i->first.toString().c_str(),i->second.inaddr.toString().c_str()); _contactQueue.erase(qi++);
sendHELLO(withPeer,i->second.localPort,i->second.inaddr);
}
_rendezvousQueue.erase(i++);
} else { } else {
nextDelay = std::min(nextDelay,(unsigned long)(i->second.fireAtTime - now)); nextDelay = std::min(nextDelay,(unsigned long)(qi->fireAtTime - now));
++i; ++qi;
} }
} }
} }
@ -325,8 +332,8 @@ unsigned long Switch::doTimerTasks()
{ {
Mutex::Lock _l(_rxQueue_m); Mutex::Lock _l(_rxQueue_m);
for(std::list< SharedPtr<PacketDecoder> >::iterator i(_rxQueue.begin());i!=_rxQueue.end();) { for(std::list< SharedPtr<PacketDecoder> >::iterator i(_rxQueue.begin());i!=_rxQueue.end();) {
if ((now - i->second->receiveTime()) > ZT_RECEIVE_QUEUE_TIMEOUT) { if ((now - (*i)->receiveTime()) > ZT_RECEIVE_QUEUE_TIMEOUT) {
TRACE("RX %s -> %s timed out",i->second->source().toString().c_str(),i->second->destination().toString().c_str()); TRACE("RX %s -> %s timed out",(*i)->source().toString().c_str(),(*i)->destination().toString().c_str());
_rxQueue.erase(i++); _rxQueue.erase(i++);
} else ++i; } else ++i;
} }
@ -401,8 +408,8 @@ void Switch::doAnythingWaitingForPeer(const SharedPtr<Peer> &peer)
{ {
Mutex::Lock _l(_rxQueue_m); Mutex::Lock _l(_rxQueue_m);
for(std::list< SharedPtr<PacketDecoder> >::iterator rxi(_rxQueue.begin());rxi!=rxQueue.end();) { for(std::list< SharedPtr<PacketDecoder> >::iterator rxi(_rxQueue.begin());rxi!=_rxQueue.end();) {
if (rxi->second->tryDecode(_r)) if ((*rxi)->tryDecode(_r))
_rxQueue.erase(rxi++); _rxQueue.erase(rxi++);
else ++rxi; else ++rxi;
} }

View file

@ -238,6 +238,23 @@ private:
std::map< Array< Address,2 >,uint64_t > _lastUniteAttempt; // key is always sorted in ascending order, for set-like behavior std::map< Array< Address,2 >,uint64_t > _lastUniteAttempt; // key is always sorted in ascending order, for set-like behavior
Mutex _lastUniteAttempt_m; Mutex _lastUniteAttempt_m;
struct ContactQueueEntry
{
ContactQueueEntry() {}
ContactQueueEntry(const SharedPtr<Peer> &p,uint64_t ft,Demarc::Port lp,const InetAddress &a) :
peer(p),
fireAtTime(ft),
localPort(lp),
inaddr(a) {}
SharedPtr<Peer> peer;
uint64_t fireAtTime;
Demarc::Port localPort;
InetAddress inaddr;
};
std::list<ContactQueueEntry> _contactQueue;
Mutex _contactQueue_m;
}; };
} // namespace ZeroTier } // namespace ZeroTier