diff --git a/control/NodeControlService.cpp b/control/NodeControlService.cpp index 661c4c63d..67a98fe63 100644 --- a/control/NodeControlService.cpp +++ b/control/NodeControlService.cpp @@ -66,11 +66,13 @@ void NodeControlService::threadMain() try { while (_running) { if (!_node->running()) { - break; + if (_node->started()) + break; } else if ((_node->initialized())&&(_node->address())) { Utils::snprintf(tmp,sizeof(tmp),"%s%.10llx",ZT_IPC_ENDPOINT_BASE,(unsigned long long)_node->address()); _listener = new IpcListener(tmp,&_CBcommandHandler,this); } + Thread::sleep(100); // wait for Node to start } } catch ( ... ) { delete _listener; @@ -138,35 +140,39 @@ void NodeControlService::_doCommand(IpcConnection *ipcc,const char *commandLine) if (pl) { for(unsigned int i=0;inumPeers;++i) { ipcc->printf("200 listpeers %.10llx ",(unsigned long long)pl->peers[i].rawAddress); - for(unsigned int j=0;jpeers[i].numPaths;++j) { - if (j > 0) - ipcc->printf(","); - switch(pl->peers[i].paths[j].type) { - default: - ipcc->printf("unknown;"); - break; - case ZT1_Node_PhysicalPath::ZT1_Node_PhysicalPath_TYPE_UDP: - ipcc->printf("udp;"); - break; - case ZT1_Node_PhysicalPath::ZT1_Node_PhysicalPath_TYPE_TCP_OUT: - ipcc->printf("tcp_out;"); - break; - case ZT1_Node_PhysicalPath::ZT1_Node_PhysicalPath_TYPE_TCP_IN: - ipcc->printf("tcp_in;"); - break; - case ZT1_Node_PhysicalPath::ZT1_Node_PhysicalPath_TYPE_ETHERNET: - ipcc->printf("eth;"); - break; + if (pl->peers[i].numPaths == 0) + ipcc->printf("-"); + else { + for(unsigned int j=0;jpeers[i].numPaths;++j) { + if (j > 0) + ipcc->printf(","); + switch(pl->peers[i].paths[j].type) { + default: + ipcc->printf("unknown;"); + break; + case ZT1_Node_PhysicalPath::ZT1_Node_PhysicalPath_TYPE_UDP: + ipcc->printf("udp;"); + break; + case ZT1_Node_PhysicalPath::ZT1_Node_PhysicalPath_TYPE_TCP_OUT: + ipcc->printf("tcp_out;"); + break; + case ZT1_Node_PhysicalPath::ZT1_Node_PhysicalPath_TYPE_TCP_IN: + ipcc->printf("tcp_in;"); + break; + case ZT1_Node_PhysicalPath::ZT1_Node_PhysicalPath_TYPE_ETHERNET: + ipcc->printf("eth;"); + break; + } + ipcc->printf("%s/%d;%ld;%ld;%ld;%s", + pl->peers[i].paths[j].address.ascii, + (int)pl->peers[i].paths[j].address.port, + pl->peers[i].paths[j].lastSend, + pl->peers[i].paths[j].lastReceive, + pl->peers[i].paths[j].lastPing, + (pl->peers[i].paths[j].fixed ? "fixed" : (pl->peers[i].paths[j].active ? "active" : "inactive"))); } - ipcc->printf("%s/%d;%ld;%ld;%ld;%s", - pl->peers[i].paths[j].address.ascii, - (int)pl->peers[i].paths[j].address.port, - pl->peers[i].paths[j].lastSend, - pl->peers[i].paths[j].lastReceive, - pl->peers[i].paths[j].lastPing, - (pl->peers[i].paths[j].fixed ? "fixed" : (pl->peers[i].paths[j].active ? "active" : "inactive"))); } - ipcc->printf(ZT_EOL_S); + ipcc->printf(" %u %s"ZT_EOL_S,pl->peers[i].latency,(pl->peers[i].remoteVersion[0]) ? pl->peers[i].remoteVersion : "-"); } _node->freeQueryResult(pl); } diff --git a/node/Node.cpp b/node/Node.cpp index 36a199b95..2cc37749a 100644 --- a/node/Node.cpp +++ b/node/Node.cpp @@ -777,7 +777,7 @@ void Node::status(ZT1_Node_Status *status) GatherPeerStatistics gps; gps.now = Utils::now(); gps.status = status; - _r->topology->eachPeer(gps); + _r->topology->eachPeer(gps); if (status->alivePeers > 0) { double dlsr = (double)status->directlyConnectedPeers / (double)status->alivePeers; @@ -793,7 +793,7 @@ void Node::status(ZT1_Node_Status *status) struct CollectPeersAndPaths { std::vector< std::pair< SharedPtr,std::vector > > data; - inline void operator()(Topology &t,const SharedPtr &p) { data.push_back(std::pair< SharedPtr,std::vector >(p,p->paths())); } + inline void operator()(Topology &t,const SharedPtr &p) { this->data.push_back(std::pair< SharedPtr,std::vector >(p,p->paths())); } }; struct SortPeersAndPathsInAscendingAddressOrder { @@ -806,7 +806,7 @@ ZT1_Node_PeerList *Node::listPeers() RuntimeEnvironment *_r = (RuntimeEnvironment *)&(impl->renv); CollectPeersAndPaths pp; - _r->topology->eachPeer(pp); + _r->topology->eachPeer(pp); std::sort(pp.data.begin(),pp.data.end(),SortPeersAndPathsInAscendingAddressOrder()); unsigned int returnBufSize = sizeof(ZT1_Node_PeerList); diff --git a/node/Topology.hpp b/node/Topology.hpp index 6bbbc2974..ccf88c5ca 100644 --- a/node/Topology.hpp +++ b/node/Topology.hpp @@ -191,6 +191,9 @@ public: /** * Apply a function or function object to all peers * + * Note: explicitly template this by reference if you want the object + * passed by reference instead of copied. + * * @param f Function to apply * @tparam F Function or function object type */ @@ -205,6 +208,9 @@ public: /** * Apply a function or function object to all supernode peers * + * Note: explicitly template this by reference if you want the object + * passed by reference instead of copied. + * * @param f Function to apply * @tparam F Function or function object type */