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) # 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
@ -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",
@ -85,5 +87,6 @@ def main():
finally: finally:
destroyNetwork(nodes) destroyNetwork(nodes)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -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

View file

@ -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]

View file

@ -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):

View file

@ -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",