summaryrefslogtreecommitdiff
path: root/node
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2013-08-05 17:44:39 -0400
committerAdam Ierymenko <adam.ierymenko@gmail.com>2013-08-05 17:44:39 -0400
commitc9c63074bbd7025c624ab4987c3a32fd2e925b6a (patch)
tree42e2f6eb22299f806c8583b58838564acefa2eea /node
parent70f368fdc36cd91a3be0218fba7b2d4c6a8bc96f (diff)
downloadinfinitytier-c9c63074bbd7025c624ab4987c3a32fd2e925b6a.tar.gz
infinitytier-c9c63074bbd7025c624ab4987c3a32fd2e925b6a.zip
CLI communication now working.
Diffstat (limited to 'node')
-rw-r--r--node/NodeConfig.cpp28
-rw-r--r--node/NodeConfig.hpp13
-rw-r--r--node/UdpSocket.cpp19
-rw-r--r--node/UdpSocket.hpp2
4 files changed, 35 insertions, 27 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;
diff --git a/node/NodeConfig.hpp b/node/NodeConfig.hpp
index 62b23609..f89cf2cb 100644
--- a/node/NodeConfig.hpp
+++ b/node/NodeConfig.hpp
@@ -52,19 +52,6 @@ class RuntimeEnvironment;
/**
* Node configuration endpoint
- *
- * Packet format for local UDP configuration packets:
- * [16] first 16 bytes of HMAC-SHA-256 of payload
- * [ -- begin HMAC'ed envelope -- ]
- * [8] random initialization vector
- * [ -- begin cryptographic envelope -- ]
- * [4] arbitrary tag, echoed in response
- * [...] payload
- *
- * For requests, the payload consists of a single ASCII command. For
- * responses, the payload consists of one or more response lines delimited
- * by NULL (0) characters. The tag field is replicated in the result
- * packet.
*/
class NodeConfig
{
diff --git a/node/UdpSocket.cpp b/node/UdpSocket.cpp
index db2c4b56..12a0a989 100644
--- a/node/UdpSocket.cpp
+++ b/node/UdpSocket.cpp
@@ -125,7 +125,13 @@ UdpSocket::UdpSocket(
UdpSocket::~UdpSocket()
{
- close(_sock);
+ int s = _sock;
+ _sock = 0;
+ if (s > 0) {
+ ::shutdown(s,SHUT_RDWR);
+ ::close(s);
+ }
+ Thread<UdpSocket>::join(_thread);
}
bool UdpSocket::send(const InetAddress &to,const void *data,unsigned int len,int hopLimit)
@@ -148,19 +154,22 @@ bool UdpSocket::send(const InetAddress &to,const void *data,unsigned int len,int
void UdpSocket::threadMain()
throw()
{
- char buf[32768];
+ char buf[65536];
InetAddress from;
socklen_t salen;
int n;
- for(;;) {
+ while (_sock > 0) {
salen = from.saddrSpaceLen();
n = (int)recvfrom(_sock,buf,sizeof(buf),0,from.saddr(),&salen);
if (n < 0) {
if ((errno != EINTR)&&(errno != ETIMEDOUT))
break;
- } else if (n > 0)
- _packetHandler(this,_arg,from,buf,(unsigned int)n);
+ } else if (n > 0) {
+ try {
+ _packetHandler(this,_arg,from,buf,(unsigned int)n);
+ } catch ( ... ) {} // should never be thrown from here anyway...
+ }
}
}
diff --git a/node/UdpSocket.hpp b/node/UdpSocket.hpp
index 3f624387..fcf13e24 100644
--- a/node/UdpSocket.hpp
+++ b/node/UdpSocket.hpp
@@ -98,7 +98,7 @@ private:
void (*_packetHandler)(UdpSocket *,void *,const InetAddress &,const void *,unsigned int);
void *_arg;
int _localPort;
- int _sock;
+ volatile int _sock;
bool _v6;
Mutex _sendLock;
};