squeaknode/squeaknode/network/peer_handler.py
Jonathan Zernik 1101dd7480
Simplify getting address from peer class (#1060)
* Simplify getting address from peer class

* Improved getting caddress field in version messages

* Simplified getting caddress even more

* Include local address and remote address as params for peer constructor

* Remove old comments from peer class
2021-08-24 20:56:51 -07:00

28 lines
716 B
Python

import logging
import socket
import threading
from squeaknode.core.peer_address import PeerAddress
logger = logging.getLogger(__name__)
class PeerHandler():
"""Handles new peer connection.
"""
def __init__(
self,
squeak_controller,
handle_connection_fn,
):
super().__init__()
self.squeak_controller = squeak_controller
self.handle_connection_fn = handle_connection_fn
def handle_connection(self, peer_socket: socket.socket, address: PeerAddress, outgoing: bool):
threading.Thread(
target=self.handle_connection_fn,
args=(self.squeak_controller, peer_socket, address, outgoing,),
).start()