Skip to content

Commit

Permalink
adding peer matching for telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
Srayman committed Jun 20, 2020
1 parent 649dd4e commit d72f873
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions peer_matching.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python3

import requests
import json
import argparse

parser = argparse.ArgumentParser()
parser.add_argument('--node', type=str, default='[::1]:7076')
args = parser.parse_args()


def node(data):
return requests.post('http://'+args.node, json=data).json()

get_peers = node({"action":"peers", "peer_details":"true"})
telemetry = node({"action":"node_telemetry", "raw":"true"})

all_peers = get_peers["peers"]

other_peers = {k: v["protocol_version"] for k,v in all_peers.items() if v["protocol_version"] != '18'}
peers = {k: v["protocol_version"] for k,v in all_peers.items() if v["protocol_version"] == '18'}

match = []
unmatch = []

for peer in telemetry["metrics"]:
ip = '['+peer["address"]+']:'+peer["port"]
if ip in peers:
network = peers.pop(ip)
match.append(ip)
else:
unmatch.append(ip)

print("{} Match\n{}\n\n\n{} Unmatch\n{}\n\n".format(len(match), match, len(unmatch), unmatch))

print("{} Unknown\n{}".format(len(peers), peers))

0 comments on commit d72f873

Please sign in to comment.