-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathqueryProtocols.py
More file actions
91 lines (67 loc) · 2.44 KB
/
queryProtocols.py
File metadata and controls
91 lines (67 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from config import myIpAddress
from config import noisy as verbose
import data.ships as ships
import plugins.proxyplugins
from twisted.internet import protocol
from twisted.internet import threads
class BlockScraper(protocol.Protocol):
def __init__(self):
pass
def connectionMade(self):
port = self.transport.getHost().port
print(
"[BlockQuery] {}:{} wants to load-balance on port {}!".format(
self.transport.getPeer().host,
self.transport.getPeer().port,
port
)
)
d = threads.deferToThread(ships.get_first_block, port, myIpAddress)
d.addCallback(self.send_block_scrape)
ships.get_first_block(port, myIpAddress)
def send_block_scrape(self, data):
self.transport.write(bytes(data))
self.transport.loseConnection()
class BlockScraperFactory(protocol.Factory):
noisy = False
def __init__(self):
self.noisy = verbose
pass
def buildProtocol(self, address):
return BlockScraper()
class ShipAdvertiserPC(protocol.Protocol):
def __init__(self):
pass
def connectionMade(self):
for f in plugins.plugins.onQueryConnection:
f(self)
print("[ShipStatus] PC Client connected " + str(self.transport.getPeer()) + "! Sending ship list packet...")
d = threads.deferToThread(ships.get_ship_query, myIpAddress, self.transport.getPeer().host)
d.addCallback(self.send_ship_list)
def send_ship_list(self, data):
self.transport.write(data)
self.transport.loseConnection()
class ShipAdvertiserVita(protocol.Protocol):
def __init__(self):
pass
def connectionMade(self):
print("[ShipStatus] Vita Client connected " + str(self.transport.getPeer()) + "! Rejecting client...")
d = threads.deferToThread(ships.reject_vita, myIpAddress)
d.addCallback(self.send_ship_list)
def send_ship_list(self, data):
self.transport.write(data)
self.transport.loseConnection()
class ShipAdvertiserFactoryPC(protocol.Factory):
noisy = False
def __init__(self):
self.noisy = verbose
pass
def buildProtocol(self, address):
return ShipAdvertiserPC()
class ShipAdvertiserFactoryVita(protocol.Factory):
noisy = False
def __init__(self):
self.noisy = verbose
pass
def buildProtocol(self, address):
return ShipAdvertiserVita()