From 4b773b61f51888f21b507bc0e70d69bfe83f2f34 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Sat, 24 May 2014 00:10:23 +0000 Subject: [PATCH] Netconf fixes. --- netconf-service/index.js | 30 ++++++++++++++++++------------ node/PacketDecoder.cpp | 4 ++-- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/netconf-service/index.js b/netconf-service/index.js index 8f7658ab5..00ffcea66 100644 --- a/netconf-service/index.js +++ b/netconf-service/index.js @@ -262,10 +262,9 @@ function doNetconfRequest(message) } var peerId = new Identity(message.data['peerId']); - var fromIpAndPort = message.data['from']; var nwid = message.data['nwid']; var requestId = message.data['requestId']; - if ((!peerId)||(!peerId.isValid())||(!fromIpAndPort)||(!nwid)||(nwid.length !== 16)||(!requestId)) { + if ((!peerId)||(!peerId.isValid())||(!nwid)||(nwid.length !== 16)||(!requestId)) { console.error('missing one or more required fields in netconf-request'); return; } @@ -307,13 +306,17 @@ function doNetconfRequest(message) // Update existing member record with new last seen time, etc. member = obj; authorized = ((!ztDbTrue(network['private'])) || ztDbTrue(member['authorized'])); - DB.hmset(memberKey,{ + var updatedFields = { 'lastSeen': Date.now(), - 'lastAt': fromIpAndPort, - 'authorized': authorized ? '1' : '0', // reset authorized to unhide in UI, since UI uses -1 to hide - 'clientVersion': (message.data['clientVersion']) ? message.data['clientVersion'] : '?.?.?', - 'clientOs': (message.data['clientOs']) ? message.data['clientOs'] : '?' - },next); + 'authorized': authorized ? '1' : '0' // reset authorized to unhide in UI, since UI uses -1 to hide + }; + if (message.data['from']) + updatedFields['lastAt'] = message.data['from']; + if (message.data['clientVersion']) + updatedFields['clientVersion'] = message.data['clientVersion']; + if (message.data['clientOs']) + updatedFields['clientOs'] = message.data['clientOs']; + DB.hmset(memberKey,updatedFields,next); } else { // Add member record to network for newly seen peer authorized = ztDbTrue(network['private']) ? false : true; // public networks authorize everyone by default @@ -324,11 +327,14 @@ function doNetconfRequest(message) 'authorized': authorized ? '1' : '0', 'identity': peerId.toString(), 'firstSeen': now, - 'lastSeen': now, - 'lastAt': fromIpAndPort, - 'clientVersion': (message.data['clientVersion']) ? message.data['clientVersion'] : '?.?.?', - 'clientOs': (message.data['clientOs']) ? message.data['clientOs'] : '?' + 'lastSeen': now }; + if (message.data['from']) + member['lastAt'] = message.data['from']; + if (message.data['clientVersion']) + member['clientVersion'] = message.data['clientVersion']; + if (message.data['clientOs']) + member['clientOs'] = message.data['clientOs']; DB.hmset(memberKey,member,next); } }); diff --git a/node/PacketDecoder.cpp b/node/PacketDecoder.cpp index 9fbc10bfc..b1b371606 100644 --- a/node/PacketDecoder.cpp +++ b/node/PacketDecoder.cpp @@ -898,9 +898,9 @@ bool PacketDecoder::_doNETWORK_CONFIG_REQUEST(const RuntimeEnvironment *_r,const request["meta"] = std::string((const char *)field(ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_DICT,dictLen),dictLen); request["type"] = "netconf-request"; request["peerId"] = peer->identity().toString(false); - Utils::snprintf(tmp,sizeof(tmp),"%llx",(unsigned long long)nwid); + Utils::snprintf(tmp,sizeof(tmp),"%.16llx",(unsigned long long)nwid); request["nwid"] = tmp; - Utils::snprintf(tmp,sizeof(tmp),"%llx",(unsigned long long)packetId()); + Utils::snprintf(tmp,sizeof(tmp),"%.16llx",(unsigned long long)packetId()); request["requestId"] = tmp; if (!hops()) request["from"] = _remoteAddress.toString();