-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
jeff
committed
Mar 27, 2023
1 parent
b48e8b2
commit 084c5e8
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/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 | ||
|
||
for addr in sys.argv[1:]: | ||
snode_pubkeys = set() | ||
jreq = { | ||
"jsonrpc": "2.0", | ||
"id": "0", | ||
"method": "get_service_nodes", | ||
"params": {"service_node_pubkeys": []}, | ||
} | ||
|
||
# collect all snodes for this oper | ||
resp = requests.post("https://public.loki.foundation/json_rpc", json=jreq) | ||
for snode in resp.json().get("result").get("service_node_states", []): | ||
if snode.get("operator_address") == addr: | ||
snodes.add(snode.get("pubkey_ed25519")) | ||
|
||
# print the config snippet to stdout | ||
print(f"# pin edges to use oper {addr}") | ||
print("[network]") | ||
for line in snodes: | ||
# convert base16 (hex) to zbase32 and add .snode suffix | ||
print( | ||
"strict-connect={}.snode".format( | ||
oxenc.to_base32z(binascii.unhexlify(line.strip())) | ||
) | ||
) |