1. Matt Joiner
  2. erutor


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
     def extended_protocol_enabled(self):

File lib/torrent.py

View file
                     self.logger.info('%s: Connected to %r', self, addr)
-        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)
                 '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):