Пример #1
0
def local_address():
    local_ip = socket.gethostbyname('localhost')
    local_port = 56789
    yield PeerAddress(
        network=Network.IPV4,
        host=local_ip,
        port=local_port,
    )
Пример #2
0
def gen_squeak_peer(peer_name):
    host = "random_host_{}".format(uuid.uuid1())
    port = random.randint(1, 10000)
    peer_address = PeerAddress(
        network=Network.IPV4,
        host=host,
        port=port,
    )
    return create_saved_peer(
        peer_name,
        peer_address,
    )
Пример #3
0
 def handle_get_offer(self, squeak_hash_str, client_host,
                      client_port) -> Offer:
     squeak_hash = bytes.fromhex(squeak_hash_str)
     client_addr = PeerAddress(
         network=Network.IPV4,
         host=client_host,
         port=client_port,
     )
     offer = self.squeak_controller.get_packaged_offer(
         squeak_hash,
         client_addr,
     )
     if not offer:
         raise NotFoundError()
     return offer
Пример #4
0
def create_saved_peer(
    peer_name: str,
    peer_address: PeerAddress,
    default_peer_port: int,
) -> SqueakPeer:
    validate_saved_peer_name(peer_name)
    if peer_address.port == 0:
        peer_address = peer_address._replace(port=default_peer_port, )
    return SqueakPeer(
        peer_id=None,
        peer_name=peer_name,
        address=peer_address,
        autoconnect=True,
        share_for_free=False,
    )
Пример #5
0
 def accept_connections(self):
     try:
         self.listen_socket.bind(('', self.port))
         self.listen_socket.listen()
         while True:
             peer_socket, address = self.listen_socket.accept()
             host, port = address
             peer_address = PeerAddress(
                 network=Network.IPV4,
                 host=host,
                 port=port,
             )
             peer_socket.setblocking(True)
             self.handle_connection(
                 peer_socket,
                 peer_address,
             )
     except Exception:
         logger.exception("Accept peer connections failed.")
Пример #6
0
def peer_address_with_zero():
    return PeerAddress(
        network=Network.IPV4,
        host="fake_host",
        port=0,
    )
Пример #7
0
def peer_address():
    return PeerAddress(
        network=Network.IPV4,
        host="fake_host",
        port=5678,
    )
Пример #8
0
def peer_address_with_no_port():
    yield PeerAddress(
        network=Network.IPV4,
        host="fake_host",
        port=0,
    )
Пример #9
0
def peer_address_with_tor():
    yield PeerAddress(
        network=Network.TORV3,
        host="fake_host",
        port=1234,
    )
Пример #10
0
def peer_address():
    yield PeerAddress(
        network=Network.IPV4,
        host="fake_host",
        port=8765,
    )
Пример #11
0
def message_to_peer_address(msg: squeak_admin_pb2.PeerAddress) -> PeerAddress:
    return PeerAddress(
        network=Network[msg.network],
        host=msg.host,
        port=msg.port,
    )
Пример #12
0
 def get_external_address(self) -> PeerAddress:
     return PeerAddress(
         network=Network.IPV4,
         host=self.config.server.external_address or '',
         port=self.config.server.external_port or 0,
     )
Пример #13
0
def outbound_local_address():
    yield PeerAddress(
        network=Network.IPV4,
        host='outbound.com',
        port=4321,
    )
Пример #14
0
def inbound_local_address():
    yield PeerAddress(
        network=Network.IPV4,
        host='inbound.com',
        port=56789,
    )
Пример #15
0
 def external_address(self) -> PeerAddress:
     return PeerAddress(
         network=Network.IPV4,
         host=self.external_host or self.local_ip,
         port=self.local_port,
     )