MCPcopy Index your code
hub / github.com/HelloZeroNet/ZeroNet / Connection

Class Connection

src/Connection/Connection.py:17–635  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15
16
17class Connection(object):
18 __slots__ = (
19 "sock", "sock_wrapped", "ip", "port", "cert_pin", "target_onion", "id", "protocol", "type", "server", "unpacker", "unpacker_bytes", "req_id", "ip_type",
20 "handshake", "crypt", "connected", "event_connected", "closed", "start_time", "handshake_time", "last_recv_time", "is_private_ip", "is_tracker_connection",
21 "last_message_time", "last_send_time", "last_sent_time", "incomplete_buff_recv", "bytes_recv", "bytes_sent", "cpu_time", "send_lock",
22 "last_ping_delay", "last_req_time", "last_cmd_sent", "last_cmd_recv", "bad_actions", "sites", "name", "waiting_requests", "waiting_streams"
23 )
24
25 def __init__(self, server, ip, port, sock=None, target_onion=None, is_tracker_connection=False):
26 self.sock = sock
27 self.cert_pin = None
28 if "#" in ip:
29 ip, self.cert_pin = ip.split("#")
30 self.target_onion = target_onion # Requested onion adress
31 self.id = server.last_connection_id
32 server.last_connection_id += 1
33 self.protocol = "?"
34 self.type = "?"
35 self.ip_type = "?"
36 self.port = int(port)
37 self.setIp(ip)
38
39 if helper.isPrivateIp(self.ip) and self.ip not in config.ip_local:
40 self.is_private_ip = True
41 else:
42 self.is_private_ip = False
43 self.is_tracker_connection = is_tracker_connection
44
45 self.server = server
46 self.unpacker = None # Stream incoming socket messages here
47 self.unpacker_bytes = 0 # How many bytes the unpacker received
48 self.req_id = 0 # Last request id
49 self.handshake = {} # Handshake info got from peer
50 self.crypt = None # Connection encryption method
51 self.sock_wrapped = False # Socket wrapped to encryption
52
53 self.connected = False
54 self.event_connected = gevent.event.AsyncResult() # Solves on handshake received
55 self.closed = False
56
57 # Stats
58 self.start_time = time.time()
59 self.handshake_time = 0
60 self.last_recv_time = 0
61 self.last_message_time = 0
62 self.last_send_time = 0
63 self.last_sent_time = 0
64 self.incomplete_buff_recv = 0
65 self.bytes_recv = 0
66 self.bytes_sent = 0
67 self.last_ping_delay = None
68 self.last_req_time = 0
69 self.last_cmd_sent = None
70 self.last_cmd_recv = None
71 self.bad_actions = 0
72 self.sites = 0
73 self.cpu_time = 0.0
74 self.send_lock = RLock()

Callers 3

getConnectionMethod · 0.90
testPexMethod · 0.90

Calls

no outgoing calls

Tested by 1

testPexMethod · 0.72