mirror of
https://github.com/cwinfo/yggdrasil-map
synced 2024-12-28 12:55:39 +00:00
readall for crawler
This commit is contained in:
parent
ca64c31ca9
commit
da1bbfc8e3
@ -15,6 +15,17 @@ else:
|
|||||||
socktype = socket.AF_UNIX
|
socktype = socket.AF_UNIX
|
||||||
sockaddr = "/var/run/yggdrasil/yggdrasil.sock"
|
sockaddr = "/var/run/yggdrasil/yggdrasil.sock"
|
||||||
|
|
||||||
|
def readall(sock):
|
||||||
|
data = []
|
||||||
|
sock.settimeout(1)
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
frag = sock.recv(4096)
|
||||||
|
data.append(frag)
|
||||||
|
except:
|
||||||
|
break
|
||||||
|
return "".join(data)
|
||||||
|
|
||||||
def getPeersRequest(key):
|
def getPeersRequest(key):
|
||||||
return '{{"keepalive":true, "request":"debug_remoteGetPeers", "arguments": {{"key":"{}"}}}}'.format(key)
|
return '{{"keepalive":true, "request":"debug_remoteGetPeers", "arguments": {{"key":"{}"}}}}'.format(key)
|
||||||
|
|
||||||
@ -23,7 +34,7 @@ def doRequest(req):
|
|||||||
ygg = socket.socket(socktype, socket.SOCK_STREAM)
|
ygg = socket.socket(socktype, socket.SOCK_STREAM)
|
||||||
ygg.connect(sockaddr)
|
ygg.connect(sockaddr)
|
||||||
ygg.send(req)
|
ygg.send(req)
|
||||||
data = json.loads(ygg.recv(1048576))
|
data = json.loads(readall(ygg))
|
||||||
return data
|
return data
|
||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
|
Loading…
Reference in New Issue
Block a user