More work on control bus refactor...

This commit is contained in:
Adam Ierymenko 2014-09-17 12:54:39 -07:00
parent edff13dcae
commit 2762db8408
3 changed files with 43 additions and 31 deletions

View File

@ -66,11 +66,13 @@ void NodeControlService::threadMain()
try { try {
while (_running) { while (_running) {
if (!_node->running()) { if (!_node->running()) {
break; if (_node->started())
break;
} else if ((_node->initialized())&&(_node->address())) { } else if ((_node->initialized())&&(_node->address())) {
Utils::snprintf(tmp,sizeof(tmp),"%s%.10llx",ZT_IPC_ENDPOINT_BASE,(unsigned long long)_node->address()); Utils::snprintf(tmp,sizeof(tmp),"%s%.10llx",ZT_IPC_ENDPOINT_BASE,(unsigned long long)_node->address());
_listener = new IpcListener(tmp,&_CBcommandHandler,this); _listener = new IpcListener(tmp,&_CBcommandHandler,this);
} }
Thread::sleep(100); // wait for Node to start
} }
} catch ( ... ) { } catch ( ... ) {
delete _listener; delete _listener;
@ -138,35 +140,39 @@ void NodeControlService::_doCommand(IpcConnection *ipcc,const char *commandLine)
if (pl) { if (pl) {
for(unsigned int i=0;i<pl->numPeers;++i) { for(unsigned int i=0;i<pl->numPeers;++i) {
ipcc->printf("200 listpeers %.10llx ",(unsigned long long)pl->peers[i].rawAddress); ipcc->printf("200 listpeers %.10llx ",(unsigned long long)pl->peers[i].rawAddress);
for(unsigned int j=0;j<pl->peers[i].numPaths;++j) { if (pl->peers[i].numPaths == 0)
if (j > 0) ipcc->printf("-");
ipcc->printf(","); else {
switch(pl->peers[i].paths[j].type) { for(unsigned int j=0;j<pl->peers[i].numPaths;++j) {
default: if (j > 0)
ipcc->printf("unknown;"); ipcc->printf(",");
break; switch(pl->peers[i].paths[j].type) {
case ZT1_Node_PhysicalPath::ZT1_Node_PhysicalPath_TYPE_UDP: default:
ipcc->printf("udp;"); ipcc->printf("unknown;");
break; break;
case ZT1_Node_PhysicalPath::ZT1_Node_PhysicalPath_TYPE_TCP_OUT: case ZT1_Node_PhysicalPath::ZT1_Node_PhysicalPath_TYPE_UDP:
ipcc->printf("tcp_out;"); ipcc->printf("udp;");
break; break;
case ZT1_Node_PhysicalPath::ZT1_Node_PhysicalPath_TYPE_TCP_IN: case ZT1_Node_PhysicalPath::ZT1_Node_PhysicalPath_TYPE_TCP_OUT:
ipcc->printf("tcp_in;"); ipcc->printf("tcp_out;");
break; break;
case ZT1_Node_PhysicalPath::ZT1_Node_PhysicalPath_TYPE_ETHERNET: case ZT1_Node_PhysicalPath::ZT1_Node_PhysicalPath_TYPE_TCP_IN:
ipcc->printf("eth;"); ipcc->printf("tcp_in;");
break; 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); _node->freeQueryResult(pl);
} }

View File

@ -777,7 +777,7 @@ void Node::status(ZT1_Node_Status *status)
GatherPeerStatistics gps; GatherPeerStatistics gps;
gps.now = Utils::now(); gps.now = Utils::now();
gps.status = status; gps.status = status;
_r->topology->eachPeer(gps); _r->topology->eachPeer<GatherPeerStatistics &>(gps);
if (status->alivePeers > 0) { if (status->alivePeers > 0) {
double dlsr = (double)status->directlyConnectedPeers / (double)status->alivePeers; double dlsr = (double)status->directlyConnectedPeers / (double)status->alivePeers;
@ -793,7 +793,7 @@ void Node::status(ZT1_Node_Status *status)
struct CollectPeersAndPaths struct CollectPeersAndPaths
{ {
std::vector< std::pair< SharedPtr<Peer>,std::vector<Path> > > data; std::vector< std::pair< SharedPtr<Peer>,std::vector<Path> > > data;
inline void operator()(Topology &t,const SharedPtr<Peer> &p) { data.push_back(std::pair< SharedPtr<Peer>,std::vector<Path> >(p,p->paths())); } inline void operator()(Topology &t,const SharedPtr<Peer> &p) { this->data.push_back(std::pair< SharedPtr<Peer>,std::vector<Path> >(p,p->paths())); }
}; };
struct SortPeersAndPathsInAscendingAddressOrder struct SortPeersAndPathsInAscendingAddressOrder
{ {
@ -806,7 +806,7 @@ ZT1_Node_PeerList *Node::listPeers()
RuntimeEnvironment *_r = (RuntimeEnvironment *)&(impl->renv); RuntimeEnvironment *_r = (RuntimeEnvironment *)&(impl->renv);
CollectPeersAndPaths pp; CollectPeersAndPaths pp;
_r->topology->eachPeer(pp); _r->topology->eachPeer<CollectPeersAndPaths &>(pp);
std::sort(pp.data.begin(),pp.data.end(),SortPeersAndPathsInAscendingAddressOrder()); std::sort(pp.data.begin(),pp.data.end(),SortPeersAndPathsInAscendingAddressOrder());
unsigned int returnBufSize = sizeof(ZT1_Node_PeerList); unsigned int returnBufSize = sizeof(ZT1_Node_PeerList);

View File

@ -191,6 +191,9 @@ public:
/** /**
* Apply a function or function object to all peers * 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 * @param f Function to apply
* @tparam F Function or function object type * @tparam F Function or function object type
*/ */
@ -205,6 +208,9 @@ public:
/** /**
* Apply a function or function object to all supernode peers * 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 * @param f Function to apply
* @tparam F Function or function object type * @tparam F Function or function object type
*/ */