Fixed PATH_NODE
This commit is contained in:
parent
1e7a1cec2d
commit
58e1606451
@ -215,11 +215,11 @@ def lProcessGroups(state, index, length, result):
|
|||||||
lIN = []
|
lIN = []
|
||||||
i = 0
|
i = 0
|
||||||
if not msgpack:
|
if not msgpack:
|
||||||
LOG.debug(f"TODO process_chunk Groups = no msgpack bytes={length}")
|
LOG.warn(f"process_chunk Groups = NO msgpack bytes={length}")
|
||||||
return []
|
return []
|
||||||
try:
|
try:
|
||||||
groups = msgpack.loads(result, raw=True)
|
groups = msgpack.loads(result, raw=True)
|
||||||
LOG.debug(f"TODO process_chunk Groups len={len(groups)}")
|
LOG.debug(f"process_chunk {label} len={len(groups)}")
|
||||||
for group in groups:
|
for group in groups:
|
||||||
assert len(group) == 7, group
|
assert len(group) == 7, group
|
||||||
i += 1
|
i += 1
|
||||||
@ -327,10 +327,10 @@ The Node Info data structure contains a Transport Protocol, a Socket
|
|||||||
while length > 0:
|
while length > 0:
|
||||||
status = struct.unpack_from(">B", result, delta)[0]
|
status = struct.unpack_from(">B", result, delta)[0]
|
||||||
if status >= 128:
|
if status >= 128:
|
||||||
ipv = 'TCP'
|
prot = 'TCP'
|
||||||
af = status - 128
|
af = status - 128
|
||||||
else:
|
else:
|
||||||
ipv = 'UDP'
|
prot = 'UDP'
|
||||||
af = status
|
af = status
|
||||||
if af == 2:
|
if af == 2:
|
||||||
af = 'IPv4'
|
af = 'IPv4'
|
||||||
@ -343,10 +343,10 @@ The Node Info data structure contains a Transport Protocol, a Socket
|
|||||||
total = 1 + alen + 2 + 32
|
total = 1 + alen + 2 + 32
|
||||||
port = int(struct.unpack_from(">H", result, delta+1+alen)[0])
|
port = int(struct.unpack_from(">H", result, delta+1+alen)[0])
|
||||||
pk = bin_to_hex(result[delta+1+alen+2:delta+1+alen+2+32], 32)
|
pk = bin_to_hex(result[delta+1+alen+2:delta+1+alen+2+32], 32)
|
||||||
LOG.info(f"{label} #{relay} bytes={length} status={status} ip={ipv} af={af} ip={ipaddr} port={port} pk={pk}")
|
LOG.info(f"{label} #{relay} bytes={length} status={status} prot={prot} af={af} ip={ipaddr} port={port} pk={pk}")
|
||||||
lIN += [{"Bytes": length,
|
lIN += [{"Bytes": length,
|
||||||
"Status": status,
|
"Status": status,
|
||||||
"Ip": ipv,
|
"Prot": prot,
|
||||||
"Af": af,
|
"Af": af,
|
||||||
"Ip": ipaddr,
|
"Ip": ipaddr,
|
||||||
"Port": port,
|
"Port": port,
|
||||||
@ -375,7 +375,7 @@ def lProcessDHTnodes(state, index, length, result, label="DHTnode"):
|
|||||||
while offset < slen: #loop over nodes
|
while offset < slen: #loop over nodes
|
||||||
status = struct.unpack_from(">B", result, offset+8)[0]
|
status = struct.unpack_from(">B", result, offset+8)[0]
|
||||||
assert status < 12
|
assert status < 12
|
||||||
ipv = 'UDP'
|
prot = 'UDP'
|
||||||
if status == 2:
|
if status == 2:
|
||||||
af = 'IPv4'
|
af = 'IPv4'
|
||||||
alen = 4
|
alen = 4
|
||||||
@ -389,11 +389,13 @@ def lProcessDHTnodes(state, index, length, result, label="DHTnode"):
|
|||||||
pk = bin_to_hex(result[offset+8+1+alen+2:offset+8+1+alen+2+32], 32)
|
pk = bin_to_hex(result[offset+8+1+alen+2:offset+8+1+alen+2+32], 32)
|
||||||
|
|
||||||
LOG.info(f"{label} #{relay} status={status} ipaddr={ipaddr} port={port} {pk}")
|
LOG.info(f"{label} #{relay} status={status} ipaddr={ipaddr} port={port} {pk}")
|
||||||
lIN += [{"status": status,
|
lIN += [{
|
||||||
"af": af,
|
"Status": status,
|
||||||
"ipaddr": ipaddr,
|
"Prot": prot,
|
||||||
"port": port,
|
"Af": af,
|
||||||
"pk": pk}]
|
"Ip": ipaddr,
|
||||||
|
"Port": port,
|
||||||
|
"Pk": pk}]
|
||||||
offset += subtotal
|
offset += subtotal
|
||||||
delta += total
|
delta += total
|
||||||
length -= total
|
length -= total
|
||||||
@ -425,23 +427,23 @@ def process_chunk(index, state):
|
|||||||
aIN = {"Nospam": f"{nospam}",
|
aIN = {"Nospam": f"{nospam}",
|
||||||
"Public_key": f"{public_key}",
|
"Public_key": f"{public_key}",
|
||||||
"Private_key": f"{private_key}"}
|
"Private_key": f"{private_key}"}
|
||||||
lOUT += [{"NOSPAMKEYS": aIN}]; aOUT.update({"NOSPAMKEYS": aIN})
|
lOUT += [{label: aIN}]; aOUT.update({label: aIN})
|
||||||
|
|
||||||
elif data_type == MESSENGER_STATE_TYPE_DHT:
|
elif data_type == MESSENGER_STATE_TYPE_DHT:
|
||||||
LOG.debug(f"process_chunk {dSTATE_TYPE[data_type]} length={length}")
|
LOG.debug(f"process_chunk {label} length={length}")
|
||||||
lIN = lProcessDHTnodes(state, index, length, result)
|
lIN = lProcessDHTnodes(state, index, length, result)
|
||||||
if lIN: lOUT += [{"DHT": lIN}]; aOUT.update({"DHT": lIN})
|
lOUT += [{label: lIN}]; aOUT.update({label: lIN})
|
||||||
|
|
||||||
elif data_type == MESSENGER_STATE_TYPE_FRIENDS:
|
elif data_type == MESSENGER_STATE_TYPE_FRIENDS:
|
||||||
LOG.debug(f"TODO process_chunk {length // 2216} FRIENDS {length} {length % 2216}")
|
LOG.debug(f"process_chunk {label} {length // 2216} FRIENDS {length} {length % 2216}")
|
||||||
lIN = lProcessFriends(state, index, length, result)
|
lIN = lProcessFriends(state, index, length, result)
|
||||||
if lIN: lOUT += [{"FRIENDS": lIN}]; aOUT.update({"FRIENDS": lIN})
|
lOUT += [{"FRIENDS": lIN}]; aOUT.update({"FRIENDS": lIN})
|
||||||
|
|
||||||
elif data_type == MESSENGER_STATE_TYPE_NAME:
|
elif data_type == MESSENGER_STATE_TYPE_NAME:
|
||||||
name = str(state[index + 8:index + 8 + length], 'utf-8')
|
name = str(state[index + 8:index + 8 + length], 'utf-8')
|
||||||
LOG.info("Nick_name = " +name)
|
LOG.info("Nick_name = " +name)
|
||||||
aIN = {"NAME": name}
|
aIN = {"NAME": name}
|
||||||
lOUT += [{"Nick_name": aIN}]; aOUT.update({"Nick_name": aIN})
|
lOUT += [{label: aIN}]; aOUT.update({label: aIN})
|
||||||
|
|
||||||
elif data_type == MESSENGER_STATE_TYPE_STATUSMESSAGE:
|
elif data_type == MESSENGER_STATE_TYPE_STATUSMESSAGE:
|
||||||
mess = str(state[index + 8:index + 8 + length], 'utf-8')
|
mess = str(state[index + 8:index + 8 + length], 'utf-8')
|
||||||
@ -454,31 +456,32 @@ def process_chunk(index, state):
|
|||||||
dStatus = {0: 'online', 1: 'away', 2: 'busy'}
|
dStatus = {0: 'online', 1: 'away', 2: 'busy'}
|
||||||
status = struct.unpack_from(">b", state, index)[0]
|
status = struct.unpack_from(">b", state, index)[0]
|
||||||
status = dStatus[status]
|
status = dStatus[status]
|
||||||
LOG.info(f"{dSTATE_TYPE[data_type]} = " +status)
|
LOG.info(f"{label} = " +status)
|
||||||
aIN = {f"Online_status": status}
|
aIN = {f"Online_status": status}
|
||||||
lOUT += [{"STATUS": aIN}]; aOUT.update({"STATUS": aIN})
|
lOUT += [{"STATUS": aIN}]; aOUT.update({"STATUS": aIN})
|
||||||
|
|
||||||
elif data_type == MESSENGER_STATE_TYPE_GROUPS:
|
elif data_type == MESSENGER_STATE_TYPE_GROUPS:
|
||||||
lIN = lProcessGroups(state, index, length, result)
|
lIN = lProcessGroups(state, index, length, result)
|
||||||
if lIN: lOUT += [{"GROUPS": lIN}]; aOUT.update({"GROUPS": lIN})
|
lOUT += [{"GROUPS": lIN}]; aOUT.update({"GROUPS": lIN})
|
||||||
|
|
||||||
elif data_type == MESSENGER_STATE_TYPE_TCP_RELAY:
|
elif data_type == MESSENGER_STATE_TYPE_TCP_RELAY:
|
||||||
lIN = lProcessNodeInfo(state, index, length, result, "TCPnode")
|
lIN = lProcessNodeInfo(state, index, length, result, "TCPnode")
|
||||||
if lIN: lOUT += [{"TCP_RELAY": lIN}]; aOUT.update({"TCP_RELAY": lIN})
|
lOUT += [{label: lIN}]; aOUT.update({label: lIN})
|
||||||
|
|
||||||
elif data_type == MESSENGER_STATE_TYPE_PATH_NODE:
|
elif data_type == MESSENGER_STATE_TYPE_PATH_NODE:
|
||||||
#define NUM_SAVED_PATH_NODES 8
|
#define NUM_SAVED_PATH_NODES 8
|
||||||
assert length % 8 == 0, length
|
assert length % 8 == 0, length
|
||||||
LOG.debug(f"TODO process_chunk {dSTATE_TYPE[data_type]} bytes={length}")
|
LOG.debug(f"process_chunk {label} bytes={length}")
|
||||||
lIN = lProcessNodeInfo(state, index, length, result, "PATHnode")
|
lIN = lProcessNodeInfo(state, index, length, result, "PATHnode")
|
||||||
if lIN: lOUT += [{label: lIN}]; aOUT.update({label: lIN})
|
lOUT += [{label: lIN}]; aOUT.update({label: lIN})
|
||||||
|
|
||||||
elif data_type == MESSENGER_STATE_TYPE_CONFERENCES:
|
elif data_type == MESSENGER_STATE_TYPE_CONFERENCES:
|
||||||
|
lIN = []
|
||||||
if length > 0:
|
if length > 0:
|
||||||
LOG.debug(f"TODO process_chunk {dSTATE_TYPE[data_type]} bytes={length}")
|
LOG.debug(f"TODO process_chunk {label} bytes={length}")
|
||||||
else:
|
else:
|
||||||
LOG.info(f"NO {dSTATE_TYPE[data_type]}")
|
LOG.info(f"NO {label}")
|
||||||
lOUT += [{"CONFERENCES": []}]; aOUT.update({"CONFERENCES": []})
|
lOUT += [{label: []}]; aOUT.update({label: []})
|
||||||
|
|
||||||
elif data_type != MESSENGER_STATE_TYPE_END:
|
elif data_type != MESSENGER_STATE_TYPE_END:
|
||||||
LOG.warn("UNRECOGNIZED datatype={datatype}")
|
LOG.warn("UNRECOGNIZED datatype={datatype}")
|
||||||
@ -560,7 +563,7 @@ def vBashFileNmapUdp():
|
|||||||
def vOsSystemNmapUdp(l, oArgs):
|
def vOsSystemNmapUdp(l, oArgs):
|
||||||
iErrs = 0
|
iErrs = 0
|
||||||
for elt in aOUT["DHT"]:
|
for elt in aOUT["DHT"]:
|
||||||
cmd = f"sudo nmap -Pn -n -sU -p U:{elt['port']} {elt['ipaddr']}"
|
cmd = f"sudo nmap -Pn -n -sU -p U:{elt['Port']} {elt['Ip']}"
|
||||||
iErrs += os.system(cmd +f" >> {oArgs.output} 2>&1")
|
iErrs += os.system(cmd +f" >> {oArgs.output} 2>&1")
|
||||||
if iErrs:
|
if iErrs:
|
||||||
LOG.warn(f"{oArgs.info} {iErrs} ERRORs to {oArgs.output}")
|
LOG.warn(f"{oArgs.info} {iErrs} ERRORs to {oArgs.output}")
|
||||||
@ -572,7 +575,7 @@ def vOsSystemNmapUdp(l, oArgs):
|
|||||||
def vOsSystemNmapTcp(l, oArgs):
|
def vOsSystemNmapTcp(l, oArgs):
|
||||||
iErrs = 0
|
iErrs = 0
|
||||||
for elt in l:
|
for elt in l:
|
||||||
cmd = f"sudo nmap -Pn -n -sT -p T:{elt['port']} {elt['ipaddr']}"
|
cmd = f"sudo nmap -Pn -n -sT -p T:{elt['Port']} {elt['Ip']}"
|
||||||
print(f"{oArgs.info} NO errors to {oArgs.output}")
|
print(f"{oArgs.info} NO errors to {oArgs.output}")
|
||||||
iErrs += os.system(cmd +f" >> {oArgs.output} 2>&1")
|
iErrs += os.system(cmd +f" >> {oArgs.output} 2>&1")
|
||||||
if iErrs:
|
if iErrs:
|
||||||
@ -659,11 +662,11 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
oStream = None
|
oStream = None
|
||||||
if oArgs.command == 'decrypt':
|
if oArgs.command == 'decrypt':
|
||||||
if oArgs.output:
|
assert oArgs.output, "--output required for this command"
|
||||||
oStream = open(oArgs.output, 'rb')
|
oStream = open(oArgs.output, 'wb')
|
||||||
else:
|
iRet = oStream.write(bSAVE)
|
||||||
oStream = sys.stdout
|
LOG.info(f"Wrote {iRet} to {oArgs.output}")
|
||||||
oStream.write(bSAVE)
|
iRet = 0
|
||||||
|
|
||||||
elif oArgs.command == 'nodes':
|
elif oArgs.command == 'nodes':
|
||||||
iRet = -1
|
iRet = -1
|
||||||
|
Loading…
Reference in New Issue
Block a user