Пример #1
0
def IterativeStore(key, value, callback):
    logging.info("Storing: dict({}:{})".format(key, value))
    
    routing_table = kBucket(cache["addr"], cache["port"], cache["uuid"])
    hashed_key = get_hash(key)
    
    def store_callback(resp, err):
        if not err: 
            logging.debug("store_callback({},{})".format(resp, err))
            callback(resp)
        
    nodes = routing_table.get_nearest_nodes(hashed_key)
    logging.debug("Storing to nodes: {}".format(nodes))
    for node in nodes:
        store_data = AsyncRPC(store_callback())
        socket_observable.register(store_data)
        store_data.send(
            store_data.new_packet(
                node, "store", (key, value, hashed_key, cache["uuid"])
            )
        )
    
    cache["values"].update(
        {   hashed_key: (key, value),
            "author": cache["uuid"]
        })
    logging.debug("Values stored, yielding...")
    yield
Пример #2
0
        db.add("external_ip", external_ip)
        db.add("external_port", port) ## audit for stun/turn port map
        
    except Exception, e:
        logging.error("STUN probing failed: {0}".format(e))

    ## start tftp receiver
    p = Process(target=tftp_server, args=(port + 1, "./tasks"))
    p.start()
    

    logging.info("Shell manager started on {0}:{1}".format(
        external_ip, port))
    
    db.add("shell_manager", (external_ip, port))
    db.add("uuid", get_hash(str(get_mac())))
    
    yield db.save()
    logging.info("DB saved to hdd: {0}".format(db.get_all()))
    
    ## event rpc listener loop
    while True:
        resp, addr, rpc_no, uuid = yield receiver.recv()
        sender = Sender(addr, receiver.get_addr(), uuid)
        yield sender.send_resp(resp, rpc_no)
    


def shell_client(sendto=db.get("shell_manager"), command_list=None):
    receiver = Receiver()
    cdb = yield db.load()