From e405c7b2df25182986a75ea98dc07d8012d5b07a Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Mon, 6 Jul 2026 13:36:01 +0200 Subject: [PATCH] bitcoin: adds peers rpc Adds a peers rpc that displays the peers of a given tank. e.g. warnet bitcoin peers tank-0000 manual tank-0004 manual tank-0005 manual tank-0006 manual tank-0013 manual tank-0014 manual tank-0015 manual tank-0019 manual tank-0021 inbound tank-0001 inbound tank-0003 inbound tank-0007 inbound tank-0008 inbound tank-0016 --- src/warnet/bitcoin.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/warnet/bitcoin.py b/src/warnet/bitcoin.py index 3bb8bc779..1ee4c7a77 100644 --- a/src/warnet/bitcoin.py +++ b/src/warnet/bitcoin.py @@ -73,6 +73,36 @@ def _rpc(tank: str, method: str, params: list[str], namespace: Optional[str] = N return run_command(cmd) +@bitcoin.command() +@click.argument("tank", type=str, required=True) +@click.option("--namespace", default=None, show_default=True) +def peers(tank: str, namespace: Optional[str]): + """ + List 's peers by connection type, resolving IPs to tank names + """ + namespace = get_default_namespace_or(namespace) + + # Map pod IP -> tank name so non-manually connected peers show their names (instead of ips). + ip_to_name = {t.status.pod_ip: t.metadata.name for t in get_mission("tank") if t.status.pod_ip} + + try: + peerinfo = json.loads(_rpc(tank, "getpeerinfo", [], namespace)) + except Exception as e: + print(f"{e}") + sys.exit(1) + + rows = [ + (p["connection_type"], ip_to_name.get(p["addr"].rsplit(":", 1)[0], p["addr"])) + for p in peerinfo + ] + # manual first, inbound last, other types in between alphabetically + rows.sort(key=lambda r: (0 if r[0] == "manual" else 2 if r[0] == "inbound" else 1, r[0], r[1])) + + width = max((len(t) for t, _ in rows), default=0) + for conn_type, name in rows: + print(f"{conn_type:<{width}} {name}") + + @bitcoin.command() @click.argument("tank", type=str, required=True) @click.option("--namespace", default=None, show_default=True)