mirror of
https://github.com/gnh1201/caterpillar.git
synced 2025-07-15 08:48:08 +00:00
Update server.py
This commit is contained in:
parent
4993806c22
commit
dd0913cb67
45
server.py
45
server.py
|
@ -157,21 +157,8 @@ def parse_first_data(data):
|
||||||
def conn_string(conn, data, addr):
|
def conn_string(conn, data, addr):
|
||||||
# check is it JSON-RPC 2.0 request
|
# check is it JSON-RPC 2.0 request
|
||||||
if data.find(b'{') == 0:
|
if data.find(b'{') == 0:
|
||||||
type, id, method, rpcdata = jsonrpc2_decode(data.decode(client_encoding))
|
jsonrpc2_server(conn, data)
|
||||||
if type == "call":
|
return
|
||||||
if method == "relay_accept":
|
|
||||||
accepted_relay[id] = conn
|
|
||||||
connection_speed = rpcdata['connection_speed']
|
|
||||||
print ("[*] connection speed: %s miliseconds" % (str(connection_speed)))
|
|
||||||
while conn.fileno() > -1:
|
|
||||||
time.sleep(1)
|
|
||||||
del accepted_relay[id]
|
|
||||||
print ("[*] relay destroyed: %s" % (id))
|
|
||||||
else:
|
|
||||||
rpchandler = Extension.get_rpcmethod(method)
|
|
||||||
if rpchandler:
|
|
||||||
rpchandler.dispatch(type, id, method, rpcdata)
|
|
||||||
return
|
|
||||||
|
|
||||||
# parse first data (header)
|
# parse first data (header)
|
||||||
webserver, port, scheme, method, url = parse_first_data(data)
|
webserver, port, scheme, method, url = parse_first_data(data)
|
||||||
|
@ -187,6 +174,34 @@ def conn_string(conn, data, addr):
|
||||||
|
|
||||||
proxy_server(webserver, port, scheme, method, url, conn, addr, data)
|
proxy_server(webserver, port, scheme, method, url, conn, addr, data)
|
||||||
|
|
||||||
|
def jsonrpc2_server(conn, data):
|
||||||
|
# get following chunks
|
||||||
|
conn.settimeout(1)
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
chunk = conn.recv(buffer_size)
|
||||||
|
if not chunk:
|
||||||
|
break
|
||||||
|
data += chunk
|
||||||
|
except:
|
||||||
|
break
|
||||||
|
|
||||||
|
# process JSON-RPC 2 request
|
||||||
|
type, id, method, rpcdata = jsonrpc2_decode(data.decode(client_encoding))
|
||||||
|
if type == "call":
|
||||||
|
if method == "relay_accept":
|
||||||
|
accepted_relay[id] = conn
|
||||||
|
connection_speed = rpcdata['connection_speed']
|
||||||
|
print ("[*] connection speed: %s miliseconds" % (str(connection_speed)))
|
||||||
|
while conn.fileno() > -1:
|
||||||
|
time.sleep(1)
|
||||||
|
del accepted_relay[id]
|
||||||
|
print ("[*] relay destroyed: %s" % (id))
|
||||||
|
else:
|
||||||
|
rpchandler = Extension.get_rpcmethod(method)
|
||||||
|
if rpchandler:
|
||||||
|
rpchandler.dispatch(type, id, method, rpcdata)
|
||||||
|
|
||||||
def proxy_connect(webserver, conn):
|
def proxy_connect(webserver, conn):
|
||||||
hostname = webserver.decode(client_encoding)
|
hostname = webserver.decode(client_encoding)
|
||||||
certpath = "%s/%s.crt" % (certdir.rstrip('/'), hostname)
|
certpath = "%s/%s.crt" % (certdir.rstrip('/'), hostname)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user