Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathproxy.py
More file actions
Latest commit
85 lines (61 loc) · 2.09 KB
/
Copy pathproxy.py
File metadata and controls
85 lines (61 loc) · 2.09 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
# coding: utf-8
importsys
try:
from . importsharedasG, utils, reactor
from .handlersimportbase
from .protocolsimportfloo_proto
except (ImportError, ValueError):
importmsg
importsharedasG
importreactor
fromhandlersimportbase
fromprotocolsimportfloo_proto
# KANS: this should use base, but I want the connection logic from FlooProto (ie, move that shit to base)
classProxiedProtocol(floo_proto.FlooProtocol):
''' Speaks floo proto, but is given the conn and we don't want to reconnect '''
def_handle(self, data):
self.proxy(data)
classFlooConn(base.BaseHandler):
PROTOCOL=ProxiedProtocol
def__init__(self, server):
super(ProxyServer, self).__init__()
self.proxy=server.send# agent handler (to the backend connection)
deftick(self):
pass
defon_connect(self):
msg.log('Connection established.')
self.proto.proxy=self.proxy
classProxyProtocol(floo_proto.FlooProtocol):
''' Speaks floo proto, but is given the conn and we don't want to reconnect '''
MAX_RETRIES=-1
INITIAL_RECONNECT_DELAY=0
defconnect(self, sock=None):
self.emit('connected')
self._sock=sock
self.connected=True
defreconnect(self):
msg.error('Client connection died!')
sys.exit(1)
defstop(self):
self.cleanup()
classProxyServer(base.BaseHandler):
PROTOCOL=ProxyProtocol
defon_connect(self):
msg.log('Connection established.')
reactor.reactor.connect(FlooConn(self), G.DEFAULT_HOST, G.DEFAULT_PORT, True)
defmain():
G.__VERSION__='0.11'
G.__PLUGIN_VERSION__='1.0'
utils.reload_settings()
floo_log_level='msg'
ifG.DEBUG:
floo_log_level='debug'
msg.LOG_LEVEL=msg.LOG_LEVELS.get(floo_log_level.upper(), msg.LOG_LEVELS['MSG'])
proxy=ProxyServer()
_, port=reactor.reactor.listen(proxy)
defon_ready():
print('Now listening on %s'%port)
utils.set_timeout(on_ready, 100)
reactor.reactor.block()
if__name__=='__main__':
main()