forked from LBRYCommunity/lbry-sdk
formatting and minor fixes on scripts
This commit is contained in:
parent
c20ba29c7a
commit
c0a40605ad
5 changed files with 23 additions and 19 deletions
|
@ -8,7 +8,10 @@
|
||||||
# Thanks to Paul Cannon for IP-address resolution functions (taken from aspn.activestate.com)
|
# Thanks to Paul Cannon for IP-address resolution functions (taken from aspn.activestate.com)
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import os, sys, time, signal
|
import os
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
import signal
|
||||||
|
|
||||||
amount = 0
|
amount = 0
|
||||||
|
|
||||||
|
@ -18,8 +21,8 @@ def destroyNetwork(nodes):
|
||||||
i = 0
|
i = 0
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
i += 1
|
i += 1
|
||||||
hashAmount = i*50/amount
|
hashAmount = i * 50 / amount
|
||||||
hashbar = '#'*hashAmount
|
hashbar = '#' * hashAmount
|
||||||
output = '\r[%-50s] %d/%d' % (hashbar, i, amount)
|
output = '\r[%-50s] %d/%d' % (hashbar, i, amount)
|
||||||
sys.stdout.write(output)
|
sys.stdout.write(output)
|
||||||
time.sleep(0.15)
|
time.sleep(0.15)
|
||||||
|
@ -28,7 +31,6 @@ def destroyNetwork(nodes):
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Launch a network of dht nodes")
|
parser = argparse.ArgumentParser(description="Launch a network of dht nodes")
|
||||||
|
|
||||||
parser.add_argument("amount_of_nodes",
|
parser.add_argument("amount_of_nodes",
|
||||||
|
@ -53,17 +55,17 @@ def main():
|
||||||
print 'Network interface IP address omitted; using %s' % ipAddress
|
print 'Network interface IP address omitted; using %s' % ipAddress
|
||||||
|
|
||||||
startPort = 4000
|
startPort = 4000
|
||||||
port = startPort+1
|
port = startPort + 1
|
||||||
nodes = []
|
nodes = []
|
||||||
print 'Creating Kademlia network'
|
print 'Creating Kademlia network'
|
||||||
try:
|
try:
|
||||||
node = os.spawnlp(
|
node = os.spawnlp(
|
||||||
os.P_NOWAIT, 'lbrynet-launch-node', 'lbrynet-launch-node', str(startPort))
|
os.P_NOWAIT, 'lbrynet-launch-node', 'lbrynet-launch-node', str(startPort))
|
||||||
nodes.append(node)
|
nodes.append(node)
|
||||||
for i in range(amount-1):
|
for i in range(amount - 1):
|
||||||
time.sleep(0.15)
|
time.sleep(0.15)
|
||||||
hashAmount = i*50/amount
|
hashAmount = i * 50 / amount
|
||||||
hashbar = '#'*hashAmount
|
hashbar = '#' * hashAmount
|
||||||
output = '\r[%-50s] %d/%d' % (hashbar, i, amount)
|
output = '\r[%-50s] %d/%d' % (hashbar, i, amount)
|
||||||
sys.stdout.write(output)
|
sys.stdout.write(output)
|
||||||
node = os.spawnlp(
|
node = os.spawnlp(
|
||||||
|
@ -85,5 +87,6 @@ def main():
|
||||||
finally:
|
finally:
|
||||||
destroyNetwork(nodes)
|
destroyNetwork(nodes)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
from lbrynet.dht.node import Node
|
|
||||||
import binascii
|
import binascii
|
||||||
from twisted.internet import reactor, task
|
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
from lbrynet.core.utils import generate_id
|
|
||||||
|
|
||||||
|
from lbrynet.dht.node import Node
|
||||||
|
from twisted.internet import reactor, task
|
||||||
|
from lbrynet.core.utils import generate_id
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -34,7 +34,6 @@ def join_network(udp_port, known_nodes):
|
||||||
|
|
||||||
|
|
||||||
def get_hosts(node, h):
|
def get_hosts(node, h):
|
||||||
|
|
||||||
def print_hosts(hosts):
|
def print_hosts(hosts):
|
||||||
print "Hosts returned from the DHT: "
|
print "Hosts returned from the DHT: "
|
||||||
print hosts
|
print hosts
|
||||||
|
|
|
@ -21,8 +21,9 @@
|
||||||
# Thanks to Paul Cannon for IP-address resolution functions (taken from aspn.activestate.com)
|
# Thanks to Paul Cannon for IP-address resolution functions (taken from aspn.activestate.com)
|
||||||
|
|
||||||
|
|
||||||
|
import binascii
|
||||||
import sys, hashlib, random
|
import hashlib
|
||||||
|
import random
|
||||||
import twisted.internet.reactor
|
import twisted.internet.reactor
|
||||||
from lbrynet.dht.node import Node
|
from lbrynet.dht.node import Node
|
||||||
|
|
||||||
|
@ -35,7 +36,7 @@ hash.update("key")
|
||||||
KEY = hash.digest()
|
KEY = hash.digest()
|
||||||
# The value to store
|
# The value to store
|
||||||
VALUE = random.randint(10000, 20000)
|
VALUE = random.randint(10000, 20000)
|
||||||
import binascii
|
|
||||||
lbryid = KEY
|
lbryid = KEY
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,6 +69,7 @@ def genericErrorCallback(failure):
|
||||||
print 'An error has occurred:', failure.getErrorMessage()
|
print 'An error has occurred:', failure.getErrorMessage()
|
||||||
twisted.internet.reactor.callLater(0, stop)
|
twisted.internet.reactor.callLater(0, stop)
|
||||||
|
|
||||||
|
|
||||||
def getValue():
|
def getValue():
|
||||||
""" Retrieves the value of the specified key (KEY) from the DHT """
|
""" Retrieves the value of the specified key (KEY) from the DHT """
|
||||||
global node, KEY
|
global node, KEY
|
||||||
|
@ -100,8 +102,10 @@ def stop():
|
||||||
print '\nStopping Kademlia node and terminating script'
|
print '\nStopping Kademlia node and terminating script'
|
||||||
twisted.internet.reactor.stop()
|
twisted.internet.reactor.stop()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
if len(sys.argv) < 2:
|
if len(sys.argv) < 2:
|
||||||
print 'Usage:\n%s UDP_PORT [KNOWN_NODE_IP KNOWN_NODE_PORT]' % sys.argv[0]
|
print 'Usage:\n%s UDP_PORT [KNOWN_NODE_IP KNOWN_NODE_PORT]' % sys.argv[0]
|
||||||
print 'or:\n%s UDP_PORT [FILE_WITH_KNOWN_NODES]' % sys.argv[0]
|
print 'or:\n%s UDP_PORT [FILE_WITH_KNOWN_NODES]' % sys.argv[0]
|
||||||
|
@ -151,7 +155,7 @@ if __name__ == '__main__':
|
||||||
# Schedule the node to join the Kademlia/Entangled DHT
|
# Schedule the node to join the Kademlia/Entangled DHT
|
||||||
node.joinNetwork(knownNodes)
|
node.joinNetwork(knownNodes)
|
||||||
# Schedule the "storeValue() call to be invoked after 2.5 seconds,
|
# Schedule the "storeValue() call to be invoked after 2.5 seconds,
|
||||||
#using KEY and VALUE as arguments
|
# using KEY and VALUE as arguments
|
||||||
twisted.internet.reactor.callLater(2.5, getValue)
|
twisted.internet.reactor.callLater(2.5, getValue)
|
||||||
# Start the Twisted reactor - this fires up all networking, and
|
# Start the Twisted reactor - this fires up all networking, and
|
||||||
# allows the scheduled join operation to take place
|
# allows the scheduled join operation to take place
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
CLI for sending rpc commands to a DHT node
|
CLI for sending rpc commands to a DHT node
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
from txjsonrpc.web.jsonrpc import Proxy
|
from txjsonrpc.web.jsonrpc import Proxy
|
||||||
import argparse
|
|
||||||
|
|
||||||
|
|
||||||
def print_value(value):
|
def print_value(value):
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
Launch a DHT node which can respond to RPC commands.
|
Launch a DHT node which can respond to RPC commands.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
from lbrynet.dht.node import Node
|
from lbrynet.dht.node import Node
|
||||||
from txjsonrpc.web import jsonrpc
|
from txjsonrpc.web import jsonrpc
|
||||||
|
@ -38,7 +37,6 @@ class RPCNode(jsonrpc.JSONRPC):
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Launch a dht node which responds to rpc commands")
|
parser = argparse.ArgumentParser(description="Launch a dht node which responds to rpc commands")
|
||||||
|
|
||||||
parser.add_argument("node_port",
|
parser.add_argument("node_port",
|
||||||
|
|
Loading…
Reference in a new issue