summaryrefslogtreecommitdiff
path: root/node/Peer.cpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2014-03-26 15:35:15 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2014-03-26 15:35:15 -0700
commitdaaec84c6be11b57572ff57c97efd993385890fd (patch)
tree7cc0e3ab91ceb2ff25e74a136c88ba118f472280 /node/Peer.cpp
parent73c1d43f2f1e0c22b21636e09be8a3e6f512faf0 (diff)
downloadinfinitytier-daaec84c6be11b57572ff57c97efd993385890fd.tar.gz
infinitytier-daaec84c6be11b57572ff57c97efd993385890fd.zip
Add TCP channel support for supernode list, make Peer pick the first path if all paths are equally dead.
Diffstat (limited to 'node/Peer.cpp')
-rw-r--r--node/Peer.cpp28
1 files changed, 18 insertions, 10 deletions
diff --git a/node/Peer.cpp b/node/Peer.cpp
index b9b9b0c7..dcc8d4ea 100644
--- a/node/Peer.cpp
+++ b/node/Peer.cpp
@@ -91,6 +91,7 @@ void Peer::receive(
}
// Announce multicast LIKEs to peers to whom we have a direct link
+ // Lock can't be locked here or it'll recurse and deadlock.
if ((now - _lastAnnouncedTo) >= ((ZT_MULTICAST_LIKE_EXPIRE / 2) - 1000)) {
_lastAnnouncedTo = now;
_r->sw->announceMulticastGroups(SharedPtr<Peer>(this));
@@ -107,12 +108,14 @@ bool Peer::send(const RuntimeEnvironment *_r,const void *data,unsigned int len,u
{
Mutex::Lock _l(_lock);
- if (_paths.empty())
+ std::vector<Path>::iterator p(_paths.begin());
+ if (p == _paths.end()) {
+ TRACE("send to %s failed: no paths available",_id.address().toString().c_str());
return false;
-
- uint64_t bestPathLastReceived = 0;
- std::vector<Path>::iterator bestPath;
- for(std::vector<Path>::iterator p(_paths.begin());p!=_paths.end();++p) {
+ }
+ uint64_t bestPathLastReceived = p->lastReceived();
+ std::vector<Path>::iterator bestPath = p;
+ while (++p != _paths.end()) {
uint64_t lr = p->lastReceived();
if (lr >= bestPathLastReceived) {
bestPathLastReceived = lr;
@@ -120,6 +123,8 @@ bool Peer::send(const RuntimeEnvironment *_r,const void *data,unsigned int len,u
}
}
+ TRACE("send to %s: using path: %s",_id.address().toString().c_str(),bestPath->toString().c_str());
+
if (_r->sm->send(bestPath->address(),bestPath->tcp(),data,len)) {
bestPath->sent(now);
return true;
@@ -147,19 +152,22 @@ bool Peer::sendPing(const RuntimeEnvironment *_r,uint64_t now,bool firstSinceRes
SharedPtr<Peer> self(this);
Mutex::Lock _l(_lock);
- bool allPingsUnanswered;
+ bool pingTcp;
if (!firstSinceReset) {
- allPingsUnanswered = true;
+ // Do not use TCP if one of our UDP endpoints has answered recently.
+ pingTcp = true;
for(std::vector<Path>::iterator p(_paths.begin());p!=_paths.end();++p) {
if (!p->pingUnanswered(now)) {
- allPingsUnanswered = false;
+ pingTcp = false;
break;
}
}
- } else allPingsUnanswered = false;
+ } else pingTcp = false;
+
+ TRACE("PING %s (pingTcp==%d)",_id.address().toString().c_str(),(int)pingTcp);
for(std::vector<Path>::iterator p(_paths.begin());p!=_paths.end();++p) {
- if ((allPingsUnanswered)||(!p->tcp())) {
+ if ((pingTcp)||(!p->tcp())) {
if (_r->sw->sendHELLO(self,p->address(),p->tcp())) {
p->sent(now);
p->pinged(now);