1. Matt Joiner
  2. erutor

Commits

Matt Joiner  committed 4cd660c

Pass the addr around explicitly to avoid race condition

  • Participants
  • Parent commits 59ef472
  • Branches default

Comments (0)

Files changed (2)

File lib/pwp.py

View file
     ProtocolError = ProtocolError
     Closed = Closed
 
-    def __init__(self, sock):
+    def __init__(self, sock, addr):
         import queue, collections
         self.socket = sock
         self.peer_bitfield = set()
         self.peer_peer_id = None
         self.closed = False
         self.piece_count = None
+        self.peer_addr = addr
 
     @property
     def extended_protocol_enabled(self):

File lib/torrent.py

View file
                     self.logger.info('%s: Connected to %r', self, addr)
                     sock.setblocking(True)
 
-        with Connection(self, sock) as conn:
+        with Connection(self, sock, addr) as conn:
             threading.current_thread().name = conn
             self.spawn(self.peer_conn_send_routine, conn)
             conn.send_protocol()
                 'm': {'ut_pex': 1},
                 'reqq': 5,
                 'v': 'erutor-0.1', # todo get this from a global
-                'yourip': socket.inet_aton(conn.socket.getpeername()[0]),
+                'yourip': socket.inet_aton(conn.peer_addr[0]),
                 'p': self.port})
 
     def activate_peer(self, sock, addr):