diff options
| author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2013-08-05 17:44:39 -0400 |
|---|---|---|
| committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2013-08-05 17:44:39 -0400 |
| commit | c9c63074bbd7025c624ab4987c3a32fd2e925b6a (patch) | |
| tree | 42e2f6eb22299f806c8583b58838564acefa2eea /node/NodeConfig.cpp | |
| parent | 70f368fdc36cd91a3be0218fba7b2d4c6a8bc96f (diff) | |
| download | infinitytier-c9c63074bbd7025c624ab4987c3a32fd2e925b6a.tar.gz infinitytier-c9c63074bbd7025c624ab4987c3a32fd2e925b6a.zip | |
CLI communication now working.
Diffstat (limited to 'node/NodeConfig.cpp')
| -rw-r--r-- | node/NodeConfig.cpp | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/node/NodeConfig.cpp b/node/NodeConfig.cpp index 0a6c014f..846945f3 100644 --- a/node/NodeConfig.cpp +++ b/node/NodeConfig.cpp @@ -97,11 +97,11 @@ public: { InetAddress v4(p->ipv4ActivePath(_now)); InetAddress v6(p->ipv6ActivePath(_now)); - _P("200 listpeers %s %s %s %u", + _P("200 listpeers %s %s %s %d", p->address().toString().c_str(), ((v4) ? v4.toString().c_str() : "(none)"), ((v6) ? v6.toString().c_str() : "(none)"), - (((v4)||(v6)) ? p->latency() : 0)); + (((v4)||(v6)) ? (int)p->latency() : -1)); } private: @@ -129,11 +129,20 @@ std::vector<std::string> NodeConfig::execute(const char *command) _r->topology->eachPeer(_DumpPeerStatistics(r)); } else if (cmd[0] == "listnetworks") { Mutex::Lock _l(_networks_m); + _P("200 listnetworks <nwid> <type> <dev> <ips>"); for(std::map< uint64_t,SharedPtr<Network> >::const_iterator nw(_networks.begin());nw!=_networks.end();++nw) { - _P("200 listnetworks %llu %s %s", - nw->first, + std::string tmp; + std::set<InetAddress> ips(nw->second->tap().ips()); + for(std::set<InetAddress>::iterator i(ips.begin());i!=ips.end();++i) { + if (tmp.length()) + tmp.push_back(','); + tmp.append(i->toString()); + } + _P("200 listnetworks %.16llx %s %s %s", + (unsigned long long)nw->first, + (nw->second->isOpen() ? "public" : "private"), nw->second->tap().deviceName().c_str(), - (nw->second->isOpen() ? "public" : "private")); + tmp.c_str()); } } else if (cmd[0] == "join") { _P("404 join Not implemented yet."); @@ -143,6 +152,8 @@ std::vector<std::string> NodeConfig::execute(const char *command) _P("404 %s No such command. Use 'help' for help.",cmd[0].c_str()); } + r.push_back(std::string()); // terminate with empty line + return r; } @@ -154,8 +165,9 @@ std::vector< Buffer<ZT_NODECONFIG_MAX_PACKET_SIZE> > NodeConfig::encodeControlMe std::vector< Buffer<ZT_NODECONFIG_MAX_PACKET_SIZE> > packets; Buffer<ZT_NODECONFIG_MAX_PACKET_SIZE> packet; - packet.setSize(16); // HMAC and IV + packet.setSize(16); // room for HMAC and IV packet.append((uint32_t)(conversationId & 0xffffffff)); + for(unsigned int i=0;i<payload.size();++i) { packet.append(payload[i]); // will throw if too big packet.append((unsigned char)0); @@ -174,7 +186,7 @@ std::vector< Buffer<ZT_NODECONFIG_MAX_PACKET_SIZE> > NodeConfig::encodeControlMe packets.push_back(packet); - packet.setSize(16); // HMAC and IV + packet.setSize(16); // room for HMAC and IV packet.append((uint32_t)(conversationId & 0xffffffff)); } } @@ -211,7 +223,7 @@ bool NodeConfig::decodeControlMessagePacket(const void *key,const void *data,uns unsigned int eos = i; while ((eos < pll)&&(pl[eos])) ++eos; - if (eos > i) { + if (eos >= i) { payload.push_back(std::string(pl + i,eos - i)); i = eos + 1; } else break; |
