MCPcopy
hub / github.com/HelloZeroNet/ZeroNet / ConnectionServer

Class ConnectionServer

src/Connection/ConnectionServer.py:23–361  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21
22
23class ConnectionServer(object):
24 def __init__(self, ip=None, port=None, request_handler=None):
25 if not ip:
26 if config.fileserver_ip_type == "ipv6":
27 ip = "::1"
28 else:
29 ip = "127.0.0.1"
30 port = 15441
31 self.ip = ip
32 self.port = port
33 self.last_connection_id = 1 # Connection id incrementer
34 self.log = logging.getLogger("ConnServer")
35 self.port_opened = {}
36 self.peer_blacklist = SiteManager.peer_blacklist
37
38 self.tor_manager = TorManager(self.ip, self.port)
39 self.connections = [] # Connections
40 self.whitelist = config.ip_local # No flood protection on this ips
41 self.ip_incoming = {} # Incoming connections from ip in the last minute to avoid connection flood
42 self.broken_ssl_ips = {} # Peerids of broken ssl connections
43 self.ips = {} # Connection by ip
44 self.has_internet = True # Internet outage detection
45
46 self.stream_server = None
47 self.stream_server_proxy = None
48 self.running = False
49
50 self.stat_recv = defaultdict(lambda: defaultdict(int))
51 self.stat_sent = defaultdict(lambda: defaultdict(int))
52 self.bytes_recv = 0
53 self.bytes_sent = 0
54 self.num_recv = 0
55 self.num_sent = 0
56
57 self.num_incoming = 0
58 self.num_outgoing = 0
59 self.had_external_incoming = False
60
61 self.timecorrection = 0.0
62 self.pool = Pool(500) # do not accept more than 500 connections
63
64 # Bittorrent style peerid
65 self.peer_id = "-UT3530-%s" % CryptHash.random(12, "base64")
66
67 # Check msgpack version
68 if msgpack.version[0] == 0 and msgpack.version[1] < 4:
69 self.log.error(
70 "Error: Unsupported msgpack version: %s (<0.4.0), please run `sudo apt-get install python-pip; sudo pip install msgpack --upgrade`" %
71 str(msgpack.version)
72 )
73 sys.exit(0)
74
75 if request_handler:
76 self.handleRequest = request_handler
77
78 def start(self, check_connections=True):
79 self.running = True
80 if check_connections:

Callers 15

peerPingMethod · 0.90
peerGetFileMethod · 0.90
peerCmdMethod · 0.90
testGetFileMethod · 0.90
testStreamFileMethod · 0.90
testOptionalDownloadMethod · 0.90
testFindOptionalMethod · 0.90
testIpv6Method · 0.90
testSslConnectionMethod · 0.90
testRawConnectionMethod · 0.90
testPingMethod · 0.90
testGetConnectionMethod · 0.90

Calls

no outgoing calls

Tested by 15

testGetFileMethod · 0.72
testStreamFileMethod · 0.72
testOptionalDownloadMethod · 0.72
testFindOptionalMethod · 0.72
testIpv6Method · 0.72
testSslConnectionMethod · 0.72
testRawConnectionMethod · 0.72
testPingMethod · 0.72
testGetConnectionMethod · 0.72
testFloodProtectionMethod · 0.72
testOpenBigfileMethod · 0.72