formatting and minor fixes on scripts

This commit is contained in:
Alex Grintsvayg 2017-03-31 14:23:35 -04:00
parent c20ba29c7a
commit c0a40605ad
5 changed files with 23 additions and 19 deletions

View file

@ -8,7 +8,10 @@
# Thanks to Paul Cannon for IP-address resolution functions (taken from aspn.activestate.com)
import argparse
import os, sys, time, signal
import os
import sys
import time
import signal
amount = 0
@ -18,8 +21,8 @@ def destroyNetwork(nodes):
i = 0
for node in nodes:
i += 1
hashAmount = i*50/amount
hashbar = '#'*hashAmount
hashAmount = i * 50 / amount
hashbar = '#' * hashAmount
output = '\r[%-50s] %d/%d' % (hashbar, i, amount)
sys.stdout.write(output)
time.sleep(0.15)
@ -28,7 +31,6 @@ def destroyNetwork(nodes):
def main():
parser = argparse.ArgumentParser(description="Launch a network of dht nodes")
parser.add_argument("amount_of_nodes",
@ -53,17 +55,17 @@ def main():
print 'Network interface IP address omitted; using %s' % ipAddress
startPort = 4000
port = startPort+1
port = startPort + 1
nodes = []
print 'Creating Kademlia network'
try:
node = os.spawnlp(
os.P_NOWAIT, 'lbrynet-launch-node', 'lbrynet-launch-node', str(startPort))
nodes.append(node)
for i in range(amount-1):
for i in range(amount - 1):
time.sleep(0.15)
hashAmount = i*50/amount
hashbar = '#'*hashAmount
hashAmount = i * 50 / amount
hashbar = '#' * hashAmount
output = '\r[%-50s] %d/%d' % (hashbar, i, amount)
sys.stdout.write(output)
node = os.spawnlp(
@ -85,5 +87,6 @@ def main():
finally:
destroyNetwork(nodes)
if __name__ == '__main__':
main()

View file

@ -1,10 +1,10 @@
from lbrynet.dht.node import Node
import binascii
from twisted.internet import reactor, task
import logging
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__)
@ -34,7 +34,6 @@ def join_network(udp_port, known_nodes):
def get_hosts(node, h):
def print_hosts(hosts):
print "Hosts returned from the DHT: "
print hosts

View file

@ -21,8 +21,9 @@
# Thanks to Paul Cannon for IP-address resolution functions (taken from aspn.activestate.com)
import sys, hashlib, random
import binascii
import hashlib
import random
import twisted.internet.reactor
from lbrynet.dht.node import Node
@ -35,7 +36,7 @@ hash.update("key")
KEY = hash.digest()
# The value to store
VALUE = random.randint(10000, 20000)
import binascii
lbryid = KEY
@ -68,6 +69,7 @@ def genericErrorCallback(failure):
print 'An error has occurred:', failure.getErrorMessage()
twisted.internet.reactor.callLater(0, stop)
def getValue():
""" Retrieves the value of the specified key (KEY) from the DHT """
global node, KEY
@ -100,8 +102,10 @@ def stop():
print '\nStopping Kademlia node and terminating script'
twisted.internet.reactor.stop()
if __name__ == '__main__':
import sys
if len(sys.argv) < 2:
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]
@ -151,7 +155,7 @@ if __name__ == '__main__':
# Schedule the node to join the Kademlia/Entangled DHT
node.joinNetwork(knownNodes)
# 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)
# Start the Twisted reactor - this fires up all networking, and
# allows the scheduled join operation to take place

View file

@ -2,10 +2,10 @@
CLI for sending rpc commands to a DHT node
"""
import argparse
from twisted.internet import reactor
from txjsonrpc.web.jsonrpc import Proxy
import argparse
def print_value(value):

View file

@ -12,7 +12,6 @@
Launch a DHT node which can respond to RPC commands.
"""
import argparse
from lbrynet.dht.node import Node
from txjsonrpc.web import jsonrpc
@ -38,7 +37,6 @@ class RPCNode(jsonrpc.JSONRPC):
def main():
parser = argparse.ArgumentParser(description="Launch a dht node which responds to rpc commands")
parser.add_argument("node_port",