mirror of https://github.com/oxen-io/lokinet
add python script which generates an ini config snippet to pin edges
takes in multiple wallet addresses as arguments and outputs to stdout a config snippet that manually pins all snodes from those opers.pull/2150/head
parent
b48e8b23ea
commit
43152fd689
@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# a script to generate a lokinet ini file that pins your edges to use only snodes run under the wallet addresses of a whitelist of opers.
|
||||
#
|
||||
# usage: ./snode-pin.py walletaddr1 walletaddr2 ... walletaddrN > 00-edges.ini
|
||||
#
|
||||
# then copy 00-edges.ini into /var/lib/lokinet/conf.d/
|
||||
# create that dir if it does not exist.
|
||||
#
|
||||
|
||||
import oxenc
|
||||
import binascii
|
||||
import sys
|
||||
import requests
|
||||
|
||||
from collections import defaultdict
|
||||
|
||||
addrs = sys.argv[1:]
|
||||
snodes = defaultdict(set)
|
||||
jreq = {
|
||||
"jsonrpc": "2.0",
|
||||
"id": "0",
|
||||
"method": "get_service_nodes",
|
||||
"params": {"service_node_pubkeys": []},
|
||||
}
|
||||
|
||||
# collect all snodes
|
||||
resp = requests.post("https://public.loki.foundation/json_rpc", json=jreq)
|
||||
for snode in resp.json().get("result").get("service_node_states", []):
|
||||
addr = snode.get("operator_address", None)
|
||||
if addr in addrs:
|
||||
snodes[addr].add(snode.get("pubkey_ed25519"))
|
||||
|
||||
# print the config snippet to stdout
|
||||
for oper in snodes:
|
||||
print(f"# pin edges to use oper {oper}")
|
||||
print("[network]")
|
||||
for addr in snodes.get(oper):
|
||||
# convert base16 (hex) to zbase32 and add .snode suffix
|
||||
print(
|
||||
"strict-connect={}.snode".format(
|
||||
oxenc.to_base32z(binascii.unhexlify(addr.strip()))
|
||||
)
|
||||
)
|
Loading…
Reference in New Issue