1 # Written George Milescu
2 # see LICENSE.txt for license information
4 # This class contains all util methods related to the ProxyService
9 def generate_proxy_challenge():
10 """ Generates a challenge (8 byte long random number) that a doe sends to a proxy during the handshake
12 @return: an 8 byte log string
14 # Generate a random challenge - random number on 8 bytes (62**8 possible combinations)
15 chars = string.letters + string.digits #len(chars)=62
18 challenge = challenge + random.choice(chars)
23 def decode_challenge_from_peerid(peerid):
24 """ Method used to retrieve (decode) a challenge from a peerid
26 @param peerid: the peerid of the peer whose challenge is to be retrieved
28 @return: a number, the challenge previously send to that peer, and encoded by the peer in its peerid
34 def encode_challenge_in_peerid(peerid, challenge):
35 """ Method used to insert (encode) a challenge into a peerid
37 @param peerid: the regular peerid, into which the challenge will be encoded
38 @param challenge: an 8 byte long number, to be encoded in the peerid
40 @return: a new peerid, with the challenge encoded in it
43 # proxy_peer_id = | regular_peer_id[1:12] | challenge[1:8] |
44 proxy_peer_id = peerid[:12] + challenge # len(self.challenge) = 8