Exemple #1
0
def requestBounties(address):
    """Request the bountylist of another node"""
    con = socket.socket()
    con.settimeout(5)
    safeprint(address)
    try:
        safeprint(address.split(":")[0] + ":" + address.split(":")[1])
        con.connect((address.split(":")[0],int(address.split(":")[1])))
        con.send(bounty_request)
        connected = True
        received = "".encode('utf-8')
        while connected:
            packet = con.recv(64)
            safeprint(packet)
            if packet == close_signal:
                con.close()
                connected = False
            else:
                received += packet
        safeprint(pickle.loads(received))
        try:
            bounties = pickle.loads(received)
            for bounty in bounties:
                addBounty(pickle.dumps(bounty,0))
                safeprint("Bounty added")
        except Exception as error:
            safeprint("Could not add bounties. This is likely because you do not have the optional dependency PyCrypto")
            safeprint(type(error))
            #later add function to request without charity bounties
    except Exception as error:
        safeprint("Failed:" + str(type(error)))
        safeprint(error)
        remove.extend([address])
Exemple #2
0
def handleIncomingBounty(conn):
    """Given a socket, store an incoming bounty, and report it valid or invalid"""
    connected = True
    received = "".encode('utf-8')
    while connected:
        packet = conn.recv(len(close_signal))
        safeprint(packet)
        if not packet == close_signal:
            received += packet
        else:
            connected = False
    safeprint("Adding bounty: " + received.decode())
    try:
        if addBounty(received):
            conn.send(valid_signal)
        else:
            conn.send(invalid_signal)
    except:
        safeprint("They closed too early")
Exemple #3
0
def handleIncomingBounty(conn, key=None):
    """Given a socket, store an incoming bounty, and report it valid or invalid"""
    received = recv(conn)
    safeprint("Adding bounty: " + received.decode())
    try:
        valid = addBounty(received)
        if valid >= -1:  #If it's valid, even if it's a duplicate, send valid signal
            send(valid_signal, conn, key)
            if valid >= 0:  #If it's valid and not already received, propagate
                mouth = socket.socket()
                from common import settings
                mouth.connect(("localhost", settings.config['port'] + 1))
                mouth.send(incoming_bounty)
                mouth.send(pad(received))
                mouth.send(close_signal)
                mouth.close()
        else:
            send(invalid_signal, conn, key)
    except Exception as error:
        safeprint("Incoming failed: " + str(type(error)))
        safeprint(error)
        traceback.print_exc()
    return key
Exemple #4
0
def handleIncomingBounty(conn, key=None):
    """Given a socket, store an incoming bounty, and report it valid or invalid"""
    received = recv(conn)
    safeprint("Adding bounty: " + received.decode())
    try:
        valid = addBounty(received)
        if valid >= -1: #If it's valid, even if it's a duplicate, send valid signal
            send(valid_signal,conn,key)
            if valid >= 0:  #If it's valid and not already received, propagate
                mouth = socket.socket()
                from common import settings
                mouth.connect(("localhost",settings.config['port'] + 1))
                mouth.send(incoming_bounty)
                mouth.send(pad(received))
                mouth.send(close_signal)
                mouth.close()
        else:
            send(invalid_signal,conn,key)
    except Exception as error:
        safeprint("Incoming failed: " + str(type(error)))
        safeprint(error)
        traceback.print_exc()
    return key