summaryrefslogtreecommitdiff
path: root/node
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2015-10-30 15:54:40 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2015-10-30 15:54:40 -0700
commit1b4cc4af5c7c0e47f73f3728ca36dc665d0e3224 (patch)
treedd314c01c1b48ace25c093fbd4345fa0112377bb /node
parent7382c328daa33b5ff21baf78ee022f23092cda3b (diff)
downloadinfinitytier-1b4cc4af5c7c0e47f73f3728ca36dc665d0e3224.tar.gz
infinitytier-1b4cc4af5c7c0e47f73f3728ca36dc665d0e3224.zip
Fix evil bug, and instrument/assert on some other stuff, and a bit of cleanup.
Diffstat (limited to 'node')
-rw-r--r--node/Cluster.cpp2
-rw-r--r--node/Hashtable.hpp2
-rw-r--r--node/Topology.cpp33
-rw-r--r--node/Topology.hpp16
4 files changed, 21 insertions, 32 deletions
diff --git a/node/Cluster.cpp b/node/Cluster.cpp
index 93b69a08..d0daae43 100644
--- a/node/Cluster.cpp
+++ b/node/Cluster.cpp
@@ -476,7 +476,7 @@ struct _ClusterAnnouncePeers
_ClusterAnnouncePeers(const uint64_t now_,Cluster *parent_) : now(now_),parent(parent_) {}
const uint64_t now;
Cluster *const parent;
- inline void operator()(const Topology &t,const SharedPtr<Peer> &peer)
+ inline void operator()(const Topology &t,const SharedPtr<Peer> &peer) const
{
Path *p = peer->getBestPath(now);
if (p)
diff --git a/node/Hashtable.hpp b/node/Hashtable.hpp
index 1d8d9e5d..e3512fef 100644
--- a/node/Hashtable.hpp
+++ b/node/Hashtable.hpp
@@ -322,7 +322,6 @@ public:
b->next = _t[bidx];
_t[bidx] = b;
++_s;
-
return b->v;
}
@@ -351,7 +350,6 @@ public:
b->next = _t[bidx];
_t[bidx] = b;
++_s;
-
return b->v;
}
diff --git a/node/Topology.cpp b/node/Topology.cpp
index 5e086116..b8bb55f2 100644
--- a/node/Topology.cpp
+++ b/node/Topology.cpp
@@ -65,7 +65,7 @@ Topology::Topology(const RuntimeEnvironment *renv) :
if (!p)
break; // stop if invalid records
if (p->address() != RR->identity.address())
- _peers[p->address()] = p;
+ _peers.set(p->address(),p);
} catch ( ... ) {
break; // stop if invalid records
}
@@ -122,7 +122,9 @@ SharedPtr<Peer> Topology::addPeer(const SharedPtr<Peer> &peer)
{
#ifdef ZT_TRACE
if ((!peer)||(peer->address() == RR->identity.address())) {
- TRACE("BUG: addPeer() caught and ignored attempt to add peer for self or add a NULL peer");
+ if (!peer)
+ fprintf(stderr,"FATAL BUG: addPeer() caught attempt to add NULL peer"ZT_EOL_S);
+ else fprintf(stderr,"FATAL BUG: addPeer() caught attempt to add peer for self"ZT_EOL_S);
abort();
}
#endif
@@ -171,7 +173,10 @@ SharedPtr<Peer> Topology::getPeer(const Address &zta)
return ap;
}
}
- } catch ( ... ) {} // invalid identity on disk?
+ } catch ( ... ) {
+ fprintf(stderr,"EXCEPTION in getPeer() part 2\n");
+ abort();
+ } // invalid identity on disk?
return SharedPtr<Peer>();
}
@@ -180,9 +185,9 @@ Identity Topology::getIdentity(const Address &zta)
{
{
Mutex::Lock _l(_lock);
- SharedPtr<Peer> &ap = _peers[zta];
+ const SharedPtr<Peer> *const ap = _peers.get(zta);
if (ap)
- return ap->identity();
+ return (*ap)->identity();
}
return _getIdentity(zta);
}
@@ -207,18 +212,16 @@ SharedPtr<Peer> Topology::getBestRoot(const Address *avoid,unsigned int avoidCou
* causes packets searching for a route to pretty much literally
* circumnavigate the globe rather than bouncing between just two. */
- if (_rootAddresses.size() > 1) { // gotta be one other than me for this to work
- for(unsigned long p=0;p<_rootAddresses.size();++p) {
- if (_rootAddresses[p] == RR->identity.address()) {
- for(unsigned long q=1;q<_rootAddresses.size();++q) {
- SharedPtr<Peer> *nextsn = _peers.get(_rootAddresses[(p + q) % _rootAddresses.size()]);
- if ((nextsn)&&((*nextsn)->hasActiveDirectPath(now))) {
- (*nextsn)->use(now);
- return *nextsn;
- }
+ for(unsigned long p=0;p<_rootAddresses.size();++p) {
+ if (_rootAddresses[p] == RR->identity.address()) {
+ for(unsigned long q=1;q<_rootAddresses.size();++q) {
+ const SharedPtr<Peer> *const nextsn = _peers.get(_rootAddresses[(p + q) % _rootAddresses.size()]);
+ if ((nextsn)&&((*nextsn)->hasActiveDirectPath(now))) {
+ (*nextsn)->use(now);
+ return *nextsn;
}
- break;
}
+ break;
}
}
diff --git a/node/Topology.hpp b/node/Topology.hpp
index f7804c29..4c1a2ab3 100644
--- a/node/Topology.hpp
+++ b/node/Topology.hpp
@@ -114,23 +114,11 @@ public:
void saveIdentity(const Identity &id);
/**
- * @return Vector of peers that are root servers
- */
- inline std::vector< SharedPtr<Peer> > rootPeers() const
- {
- Mutex::Lock _l(_lock);
- return _rootPeers;
- }
-
- /**
* Get the current favorite root server
*
* @return Root server with lowest latency or NULL if none
*/
- inline SharedPtr<Peer> getBestRoot()
- {
- return getBestRoot((const Address *)0,0,false);
- }
+ inline SharedPtr<Peer> getBestRoot() { return getBestRoot((const Address *)0,0,false); }
/**
* Get the best root server, avoiding root servers listed in an array
@@ -237,7 +225,7 @@ public:
while (i.next(a,p)) {
#ifdef ZT_TRACE
if (!(*p)) {
- fprintf(stderr,"FATAL BUG: eachPeer() caught NULL peer for %s -- peer pointers in Topology should NEVER be NULL",a->toString().c_str());
+ fprintf(stderr,"FATAL BUG: eachPeer() caught NULL peer for %s -- peer pointers in Topology should NEVER be NULL"ZT_EOL_S,a->toString().c_str());
abort();
}
#endif