MCPcopy Index your code
hub / github.com/Bitmessage/PyBitmessage / __init__

Method __init__

src/network/tcp.py:38–76  ·  view source on GitHub ↗
(self, address=None, sock=None)

Source from the content-addressed store, hash-verified

36
37class TCPConnection(BMProto, TLSDispatcher):
38 def __init__(self, address=None, sock=None):
39 BMProto.__init__(self, address=address, sock=sock)
40 self.verackReceived = False
41 self.verackSent = False
42 self.streams = [0]
43 self.fullyEstablished = False
44 self.connectedAt = 0
45 self.skipUntil = 0
46 if address is None and sock is not None:
47 self.destination = state.Peer(sock.getpeername()[0], sock.getpeername()[1])
48 self.isOutbound = False
49 TLSDispatcher.__init__(self, sock, server_side=True)
50 self.connectedAt = time.time()
51 logger.debug("Received connection from %s:%i", self.destination.host, self.destination.port)
52 self.nodeid = randomBytes(8)
53 elif address is not None and sock is not None:
54 TLSDispatcher.__init__(self, sock, server_side=False)
55 self.isOutbound = True
56 logger.debug("Outbound proxy connection to %s:%i", self.destination.host, self.destination.port)
57 else:
58 self.destination = address
59 self.isOutbound = True
60 if ":" in address.host:
61 self.create_socket(socket.AF_INET6, socket.SOCK_STREAM)
62 else:
63 self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
64 self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
65 TLSDispatcher.__init__(self, sock, server_side=False)
66 self.connect(self.destination)
67 logger.debug("Connecting to %s:%i", self.destination.host, self.destination.port)
68 encodedAddr = protocol.encodeHost(self.destination.host)
69 if protocol.checkIPAddress(encodedAddr, True) and not protocol.checkSocksIP(self.destination.host):
70 self.local = True
71 else:
72 self.local = False
73 #shared.connectedHostsList[self.destination] = 0
74 ObjectTracker.__init__(self)
75 self.bm_proto_reset()
76 self.set_state("bm_header", expectBytes=protocol.Header.size)
77
78 def antiIntersectionDelay(self, initial = False):
79 # estimated time for a small object to propagate across the whole network

Callers

nothing calls this directly

Calls 7

randomBytesFunction · 0.90
getpeernameMethod · 0.80
create_socketMethod · 0.80
bm_proto_resetMethod · 0.80
set_stateMethod · 0.80
__init__Method · 0.45
connectMethod · 0.45

Tested by

no test coverage detected