From d8dbbf7484f5df16a3e36b35da31383cc9589081 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Fri, 30 Oct 2015 14:11:10 -0700 Subject: [PATCH] Add some debug code in TRACE mode to catch a bug. --- node/Topology.cpp | 12 +++++++----- node/Topology.hpp | 11 +++++++++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/node/Topology.cpp b/node/Topology.cpp index 031c0b1b6..5e086116b 100644 --- a/node/Topology.cpp +++ b/node/Topology.cpp @@ -120,10 +120,12 @@ Topology::~Topology() SharedPtr Topology::addPeer(const SharedPtr &peer) { - if (peer->address() == RR->identity.address()) { - TRACE("BUG: addPeer() caught and ignored attempt to add peer for self"); - throw std::logic_error("cannot add peer for self"); +#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"); + abort(); } +#endif SharedPtr np; { @@ -133,6 +135,7 @@ SharedPtr Topology::addPeer(const SharedPtr &peer) hp = peer; np = hp; } + np->use(RR->node->now()); saveIdentity(np->identity()); @@ -321,8 +324,7 @@ unsigned long Topology::countActive() const Address *a = (Address *)0; SharedPtr *p = (SharedPtr *)0; while (i.next(a,p)) { - if ((*p)->hasActiveDirectPath(now)) - ++cnt; + cnt += (unsigned long)((*p)->hasActiveDirectPath(now)); } return cnt; } diff --git a/node/Topology.hpp b/node/Topology.hpp index d6f453aca..999338666 100644 --- a/node/Topology.hpp +++ b/node/Topology.hpp @@ -234,8 +234,15 @@ public: Hashtable< Address,SharedPtr >::Iterator i(_peers); Address *a = (Address *)0; SharedPtr *p = (SharedPtr *)0; - while (i.next(a,p)) - f(*this,*p); + while (i.next(a,p)) { +#ifdef ZT_TRACE + if (!(*p)) { + ZT_TRACE("eachPeer() caught NULL peer for %s",a->toString().c_str()); + abort(); + } +#endif + f(*this,*((const SharedPtr *)p)); + } } /**