Browse Source

Netconf fixes.

Adam Ierymenko 11 years ago
parent
commit
4b773b61f5
2 changed files with 20 additions and 14 deletions
  1. 18 12
      netconf-service/index.js
  2. 2 2
      node/PacketDecoder.cpp

+ 18 - 12
netconf-service/index.js

@@ -262,10 +262,9 @@ function doNetconfRequest(message)
 	}
 	}
 
 
 	var peerId = new Identity(message.data['peerId']);
 	var peerId = new Identity(message.data['peerId']);
-	var fromIpAndPort = message.data['from'];
 	var nwid = message.data['nwid'];
 	var nwid = message.data['nwid'];
 	var requestId = message.data['requestId'];
 	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');
 		console.error('missing one or more required fields in netconf-request');
 		return;
 		return;
 	}
 	}
@@ -307,13 +306,17 @@ function doNetconfRequest(message)
 				// Update existing member record with new last seen time, etc.
 				// Update existing member record with new last seen time, etc.
 				member = obj;
 				member = obj;
 				authorized = ((!ztDbTrue(network['private'])) || ztDbTrue(member['authorized']));
 				authorized = ((!ztDbTrue(network['private'])) || ztDbTrue(member['authorized']));
-				DB.hmset(memberKey,{
+				var updatedFields = {
 					'lastSeen': Date.now(),
 					'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 {
 			} else {
 				// Add member record to network for newly seen peer
 				// Add member record to network for newly seen peer
 				authorized = ztDbTrue(network['private']) ? false : true; // public networks authorize everyone by default
 				authorized = ztDbTrue(network['private']) ? false : true; // public networks authorize everyone by default
@@ -324,11 +327,14 @@ function doNetconfRequest(message)
 					'authorized': authorized ? '1' : '0',
 					'authorized': authorized ? '1' : '0',
 					'identity': peerId.toString(),
 					'identity': peerId.toString(),
 					'firstSeen': now,
 					'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);
 				DB.hmset(memberKey,member,next);
 			}
 			}
 		});
 		});

+ 2 - 2
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["meta"] = std::string((const char *)field(ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_DICT,dictLen),dictLen);
 			request["type"] = "netconf-request";
 			request["type"] = "netconf-request";
 			request["peerId"] = peer->identity().toString(false);
 			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;
 			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;
 			request["requestId"] = tmp;
 			if (!hops())
 			if (!hops())
 				request["from"] = _remoteAddress.toString();
 				request["from"] = _remoteAddress.toString();