def buildExtendPayload(on):
    match = re.search(r'(\d{1,3}\.){3}\d{1,3}(:\d{1,5})?', on)
    # if on =="Goblin500":
    #     print "Goblin500"
    #     ip = [82,26,108,68]
    #     port = 9001
    #     extend = struct.pack("B" * len(ip), *ip)
    #     extend += struct.pack("H", port)

    #     x, pl_To_Next = remoteKeyX(on) 
    #     extend += pl_To_Next
    #     r = consensus.getRouter(on)

    #     print r['identity'].encode('hex')
    #     extend += r['identity']

    if match:
        ip, port,identity = on.split(":")
        print ip
        # print type(ip)
        d = consensus.get_data_by_ip(ip)

        ip = map(int,ip.split("."))
        port = int(port)

        extend = struct.pack("B" * len(ip), *ip)
        extend += struct.pack("H", port)
        d = consensus.get_data_by_ip(ip)

        x, pl_To_Next = remoteKeyX(d['identityhash'])

        extend += pl_To_Next
        extend += d['identity']

    else :
        r = consensus.getRouter(on)
        ip = map(int,r['ip'].split("."))
        port = int(r['orport'])
        extend = struct.pack("B" * len(ip), *ip)
        extend += struct.pack("H", port)

        x, pl_To_Next = remoteKeyX(on) #made into function much better than repeating code
           #creates the payload to the next hop
            #pl_To_Next = hybridEncrypt(remoteKey, X)
        extend += pl_To_Next
        extend += r['identity']

    return (x, extend)
Exemple #2
0
# print "message_decrypted\n\n", message_decrypted #Testing, not going to be used in the original developement as it will confuse the user

#saves  decrypted data to a text file
file_decrypted_to_save = descriptor_id_list[0]+"_decrypted.txt" #Sets the name, this is the same as the encrypted versio, just with decrypted added onto the end, make it easy to see which files are releated if this was required.
message_decrypted_file = open(file_decrypted_to_save, "w") #Opens the file and assigns the write permisson to it to allow the application to write the file.
message_decrypted_file.write(message_decrypted) #Writes the decrypted message to the file
message_decrypted_file.close() #Closes the file to be used again later

#Retrieves data from the decrypted version of the document recieved
introduction_point_decrypted, ip_addresses, onion_port, onion_key_decrypted, service_key_decrypted, service_key_encrypted = extract_data_from_file(file_decrypted_to_save)

print introduction_point_decrypted[0] #One of the chosen Introduction points

# Put a loop in here, if un named try another
introduction_point_nick = consensus.get_data_by_ip(ip_addresses[0])['nick'] #Retrieves the nickname based on ip address

#### TEST ####
## This makes sure the seelcted node does not have the nickname "unkown", as it was descovered during testing, if it has this nickname, then it will not be able to be connected to.
print "introduction_point_nick", introduction_point_nick
i = 1
while i>4: #Only 3 Induction points, if used while true would loop forever
    if introduction_point_nick == "Unnamed":
        introduction_point_nick = consensus.get_data_by_ip(ip_addresses[i])['nick'] #Retrieves the nickname based on ip address
    # assert introduction_point_nick != "Unnamed" #Testing

    if introduction_point_nick == "Unnamed":
        unnamed_error()
        i = i + 1
    else:
        break