Exemplo n.º 1
0
#!/usr/bin/env python

import time
import os
from utils import delayed_thread
from WatClient import WDHTClient
try:
    delayed_thread(lambda: os.system("./server aaron localhost 15243"))
    delayed_thread(lambda: os.system("./server guru localhost 15244 localhost 15243"))
    time.sleep(0.5)

    WDHTClient("localhost", 15243).put("XX", "1", -1)
    WDHTClient("localhost", 15243).put("YY", "2", -1)
    WDHTClient("localhost", 15243).put("ZZ", "3", -1)
    WDHTClient("localhost", 15243).put("a", "4", -1)
    WDHTClient("localhost", 15243).put("b", "5", -1)
    delayed_thread(lambda: os.system("./server aarom localhost 15245 localhost 15243"))
    time.sleep(0.5)

    WDHTClient("localhost", 15243).put("c", "6", -1)

    print WDHTClient("localhost", 15244).get("a")
    print WDHTClient("localhost", 15245).get("b")

except KeyboardInterrupt:
    os.system("./kill-server")
finally:
    os.system("./kill-server")
Exemplo n.º 2
0
#!/usr/bin/env python

import time
import os
from utils import delayed_thread
from WatClient import WDHTClient

try:
    delayed_thread(lambda: os.system("./server aaron localhost 15247"))
    delayed_thread(lambda: os.system("./server guru localhost 15246 localhost 15247"), 0.1)
    time.sleep(1)

    print "Putting"
    WDHTClient("localhost", 15246).put("XX", "1", -1)
    WDHTClient("localhost", 15246).put("YY", "2", -1)
    WDHTClient("localhost", 15246).put("ZZ", "3", -1)

    print "Killing one"
    os.system("./kill-one-server aaron")
    time.sleep(0.1)

    print "Finishing"
    WDHTClient("localhost", 15246).put("a", "4", -1)
    WDHTClient("localhost", 15246).put("b", "5", -1)
    print WDHTClient("localhost", 15246).get("a")
    print WDHTClient("localhost", 15246).get("b")

except KeyboardInterrupt:
    os.system("./kill-server")
finally:
    os.system("./kill-server")
Exemplo n.º 3
0
from ttypes import WatDHTException

num_hosts = 20
num_pairs = 1000
first_port = 11333

def rand_string():
    return ''.join(chr(random.randrange(ord('A'), ord('z')+1)) for i in range(random.randrange(5, 31)))

table = []
for i in range(num_pairs):
    table.append((rand_string(), rand_string()))

try:
    print "[[Starting 0]]"
    delayed_thread(lambda: os.system("./server 0 localhost %d" % first_port))
    for i in range(1, num_hosts / 2):
        # time.sleep(1)
        print "[[Starting %d]]" % i
        delayed_thread((lambda i: lambda: os.system("./server %d localhost %d localhost %d" % (i, first_port + i, first_port)))(i))
    time.sleep(1)

    for i in range(num_pairs):
        key, value = table[i]
        print "[[Inserting (%s, %s)]]" % (key, value)
        WDHTClient("localhost", random.randrange(num_hosts / 2) + first_port).put(key, value, -1)

    for i in range(num_hosts / 2, num_hosts):
        # time.sleep(1)
        print "[[Starting %d]]" % i
        delayed_thread((lambda i: lambda: os.system("./server %d localhost %d localhost %d" % (i, first_port + i, first_port)))(i))
Exemplo n.º 4
0
        print "Usage: ./server node_id ip port [existing_ip existing_port]"
        sys.exit(-1)

    logging.info("Initializing ...")
    node_id = Router.hash(sys.argv[1])
    host = sys.argv[2]
    port = int(sys.argv[3])    
    node = NodeID(node_id, host, port)

    logging.info("Node: %x (%s:%d)", node.int_id, host, port)
    handler = WDHTHandler(node)

    if len(sys.argv) == 6:
        existing_host = sys.argv[4]
        existing_port = int(sys.argv[5])

        logging.info("Joining (%s:%d)", existing_host, existing_port)
        delayed_thread(lambda:handler.prv_init(existing_host, existing_port))

    else:
        handler.prv_init_origin()

    # Starting maintenance threads
    periodic_thread(handler.prv_maintain_neighbors, 10)
    periodic_thread(handler.prv_maintain_routing, 30)

    # Start server
    logging.info("Starting Server")
    start(handler, port)
    logging.info("Done")