From d72f8736a587b3da9147f1635d9c7d3e83d0c622 Mon Sep 17 00:00:00 2001 From: Srayman Date: Sat, 20 Jun 2020 13:25:22 -0400 Subject: [PATCH] adding peer matching for telemetry --- peer_matching.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 peer_matching.py diff --git a/peer_matching.py b/peer_matching.py new file mode 100644 index 0000000..fa4814f --- /dev/null +++ b/peer_matching.py @@ -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))