mirror of
https://github.com/oxen-io/lokinet
synced 2023-12-14 06:53:00 +01:00
fixes for testnet
This commit is contained in:
parent
3d76e3d4bd
commit
bb7b46c43d
3 changed files with 21 additions and 152 deletions
49
contrib/testnet/genconf.py
Normal file → Executable file
49
contrib/testnet/genconf.py
Normal file → Executable file
|
@ -18,7 +18,6 @@ def clientNodeName(id): return 'client-node-%03d' % id
|
|||
|
||||
def main():
|
||||
ap = AP()
|
||||
ap.add_argument('--lokid', type=str, required=True)
|
||||
ap.add_argument('--valgrind', type=bool, default=False)
|
||||
ap.add_argument('--dir', type=str, default='testnet_tmp')
|
||||
ap.add_argument('--svc', type=int, default=20,
|
||||
|
@ -32,6 +31,7 @@ def main():
|
|||
ap.add_argument('--ip', type=str, default=None)
|
||||
ap.add_argument('--ifname', type=str, default='lo')
|
||||
ap.add_argument('--netid', type=str, default=None)
|
||||
ap.add_argument('--loglevel', type=str, default='info')
|
||||
args = ap.parse_args()
|
||||
|
||||
if args.valgrind:
|
||||
|
@ -43,6 +43,7 @@ def main():
|
|||
for nodeid in range(args.svc):
|
||||
config = CP()
|
||||
config['router'] = {
|
||||
'data-dir': '.',
|
||||
'net-threads': '1',
|
||||
'worker-threads': '4',
|
||||
'nickname': svcNodeName(nodeid),
|
||||
|
@ -68,10 +69,7 @@ def main():
|
|||
'enabled': 'false'
|
||||
}
|
||||
config['lokid'] = {
|
||||
'enabled': 'true',
|
||||
'username': 'svc-%03d' % nodeid,
|
||||
'password': 'lokinet',
|
||||
'jsonrpc': '127.0.0.1:5000'
|
||||
'enabled': 'false',
|
||||
}
|
||||
d = os.path.join(args.dir, svcNodeName(nodeid))
|
||||
if not os.path.exists(d):
|
||||
|
@ -80,14 +78,16 @@ def main():
|
|||
with open(fp, 'w') as f:
|
||||
config.write(f)
|
||||
for n in [0]:
|
||||
if nodeid:
|
||||
f.write("[bootstrap]\nadd-node={}\n".format(os.path.join(basedir,svcNodeName(n), 'rc.signed')))
|
||||
if nodeid is not 0:
|
||||
f.write("[bootstrap]\nadd-node={}\n".format(os.path.join(basedir,svcNodeName(n), 'self.signed')))
|
||||
else:
|
||||
f.write("[bootstrap]\nseed-node=true\n")
|
||||
|
||||
|
||||
for nodeid in range(args.clients):
|
||||
config = CP()
|
||||
|
||||
config['router'] = {
|
||||
'data-dir': '.',
|
||||
'net-threads': '1',
|
||||
'worker-threads': '2',
|
||||
'nickname': clientNodeName(nodeid)
|
||||
|
@ -95,6 +95,10 @@ def main():
|
|||
if args.netid:
|
||||
config['router']['netid'] = args.netid
|
||||
|
||||
config["logging"] = {
|
||||
"level": args.loglevel
|
||||
}
|
||||
|
||||
config['netdb'] = {
|
||||
'dir': 'netdb'
|
||||
}
|
||||
|
@ -107,34 +111,18 @@ def main():
|
|||
d = os.path.join(args.dir, clientNodeName(nodeid))
|
||||
if not os.path.exists(d):
|
||||
os.mkdir(d)
|
||||
hiddenservice = os.path.join(d, 'service.ini')
|
||||
config['services'] = {
|
||||
'testnet': hiddenservice
|
||||
}
|
||||
fp = os.path.join(d, 'client.ini')
|
||||
with open(fp, 'w') as f:
|
||||
config.write(f)
|
||||
for n in [0]:
|
||||
otherID = (n + nodeid) % args.svc
|
||||
f.write("[bootstrap]\nadd-node={}\n".format(os.path.join(basedir,svcNodeName(otherID), 'rc.signed')))
|
||||
with open(hiddenservice, 'w') as f:
|
||||
f.write('''[test-service]
|
||||
tag=test
|
||||
prefetch-tag=test
|
||||
type=null
|
||||
''')
|
||||
f.write("[bootstrap]\nadd-node={}\n".format(os.path.join(basedir,svcNodeName(otherID), 'self.signed')))
|
||||
|
||||
with open(args.out, 'w') as f:
|
||||
f.write('''[program:mock-lokid]
|
||||
command = {} {}
|
||||
autorestart = true
|
||||
redirect_stderr=true
|
||||
stdout_logfile={}/lokid.txt
|
||||
stdout_logfile_maxbytes=0
|
||||
'''.format(args.lokid, args.svc, args.dir))
|
||||
basedir = os.path.join(args.dir, 'svc-node-%(process_num)03d')
|
||||
f.write('''[program:svc-node]
|
||||
directory = {}
|
||||
command = {} daemon.ini
|
||||
command = {} -r {}/daemon.ini
|
||||
autorestart=true
|
||||
redirect_stderr=true
|
||||
#stdout_logfile=/dev/fd/1
|
||||
|
@ -142,10 +130,11 @@ stdout_logfile={}/svc-node-%(process_num)03d-log.txt
|
|||
stdout_logfile_maxbytes=0
|
||||
process_name = svc-node-%(process_num)03d
|
||||
numprocs = {}
|
||||
'''.format(os.path.join(args.dir, 'svc-node-%(process_num)03d'), exe, args.dir, args.svc))
|
||||
'''.format(basedir, exe, basedir, args.dir, args.svc))
|
||||
basedir = os.path.join(args.dir, 'client-node-%(process_num)03d')
|
||||
f.write('''[program:Client-node]
|
||||
directory = {}
|
||||
command = bash -c "sleep 5 && {} client.ini"
|
||||
command = bash -c "sleep 5 && {} {}/client.ini"
|
||||
autorestart=true
|
||||
redirect_stderr=true
|
||||
#stdout_logfile=/dev/fd/1
|
||||
|
@ -153,7 +142,7 @@ stdout_logfile={}/client-node-%(process_num)03d-log.txt
|
|||
stdout_logfile_maxbytes=0
|
||||
process_name = client-node-%(process_num)03d
|
||||
numprocs = {}
|
||||
'''.format(os.path.join(args.dir, 'client-node-%(process_num)03d'), exe, args.dir, args.clients))
|
||||
'''.format(basedir, exe, basedir, args.dir, args.clients))
|
||||
f.write('[supervisord]\ndirectory=.\n')
|
||||
|
||||
|
||||
|
|
|
@ -1,121 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
|
||||
import os
|
||||
from base64 import b64decode
|
||||
|
||||
from flask import Flask, jsonify, request, abort, Response, make_response
|
||||
from nacl import signing
|
||||
from nacl import encoding
|
||||
|
||||
class SVCNode:
|
||||
"""
|
||||
info on a service node
|
||||
"""
|
||||
def __init__(self):
|
||||
self._seed = os.urandom(32)
|
||||
self._ed25519_secret = signing.SigningKey(self._seed)
|
||||
|
||||
def seed(self):
|
||||
"""
|
||||
return hex seed
|
||||
"""
|
||||
return self._ed25519_secret.encode(encoding.HexEncoder).decode('ascii') + self.pubkey()
|
||||
|
||||
def pubkey(self):
|
||||
"""
|
||||
make hex public key
|
||||
"""
|
||||
return self._ed25519_secret.verify_key.encode(encoding.HexEncoder).decode('ascii')
|
||||
|
||||
def toJson(self):
|
||||
"""
|
||||
make the snode a json object for jsonrpc
|
||||
"""
|
||||
return {'pubkey_ed25519': self.pubkey(), 'active': True, 'funded': True}
|
||||
|
||||
class MockServer:
|
||||
|
||||
def __init__(self, numServiceNodes):
|
||||
self.app = Flask('lokid-rpc-mock')
|
||||
#self.app.config['SECRET_KEY'] = os.urandom(16)
|
||||
# populate service nodes
|
||||
self._serviceNodes = dict()
|
||||
for n in range(numServiceNodes):
|
||||
self.makeSNode("svc-%03d" % n)
|
||||
|
||||
self._handlers = {
|
||||
'lokinet_ping': self._lokinet_ping,
|
||||
'get_n_service_nodes' : self._get_n_service_nodes,
|
||||
'get_service_node_privkey' : self._get_service_node_privkey
|
||||
}
|
||||
#digest = HTTPDigestAuth(realm='lokid')
|
||||
|
||||
@self.app.route('/json_rpc', methods=["POST"])
|
||||
def _jsonRPC():
|
||||
j = request.get_json()
|
||||
method = j['method']
|
||||
snode = None
|
||||
if 'authorization' in request.headers:
|
||||
user = b64decode(request.headers['authorization'][6:].encode('ascii')).decode('ascii').split(':')[0]
|
||||
self.app.logger.error(user)
|
||||
if len(user) > 0:
|
||||
snode = self._serviceNodes[user]
|
||||
result = self._handlers[method](snode)
|
||||
if result:
|
||||
resp = {'jsonrpc': '2.0', 'id': j['id'], 'result': result}
|
||||
return jsonify(resp)
|
||||
else:
|
||||
r = make_response('nope', 401)
|
||||
r.headers['www-authenticate'] = 'basic'
|
||||
return r
|
||||
def after(req):
|
||||
req.content_type = "application/json"
|
||||
return req
|
||||
self.app.after_request(after)
|
||||
|
||||
def _get_n_service_nodes(self, our_snode):
|
||||
return {
|
||||
'block_hash' : 'mock',
|
||||
'service_node_states' : self.getSNodeList()
|
||||
}
|
||||
|
||||
def _get_service_node_privkey(self, our_snode):
|
||||
if our_snode is None:
|
||||
return None
|
||||
return {
|
||||
'service_node_ed25519_privkey': our_snode.seed()
|
||||
}
|
||||
|
||||
def _lokinet_ping(self, snode):
|
||||
return {
|
||||
'status' : "OK"
|
||||
}
|
||||
|
||||
def run(self):
|
||||
"""
|
||||
run mainloop and serve jsonrpc server
|
||||
"""
|
||||
self.app.run()
|
||||
|
||||
def makeSNode(self, name):
|
||||
"""
|
||||
make service node entry
|
||||
"""
|
||||
self._serviceNodes[name] = SVCNode()
|
||||
|
||||
|
||||
def getSNodeList(self):
|
||||
l = list()
|
||||
for name in self._serviceNodes:
|
||||
l.append(self._serviceNodes[name].toJson())
|
||||
return l
|
||||
|
||||
|
||||
def main():
|
||||
import sys
|
||||
serv = MockServer(int(sys.argv[1]))
|
||||
serv.run()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -356,9 +356,10 @@ namespace llarp
|
|||
}
|
||||
|
||||
hopsSet.insert(rc);
|
||||
#ifndef TESTNET
|
||||
if (not pathConfig.Acceptable(hopsSet))
|
||||
return false;
|
||||
|
||||
#endif
|
||||
return rc.pubkey != endpointRC.pubkey;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue