def removeThisNode(self, service, remote, badNode): path = remote.addr + service + "/peer/" + "removeThisNode/%s" % badNode try: r = requests.post(path) return r.status_code == requests.codes.ok except Exception: return False
def dial(subnet, target, cmd, **kwargs): buildURL = [target["addr"]] buildURL.append(subnet + "/client/") buildURL.append(cmd) buildURL.append("/") postData = None if cmd == "seek" or cmd == "get": buildURL.append(kwargs["id"]) elif cmd == "poll": buildURL.append(kwargs["id"]) buildURL.append("/") buildURL.append(str(kwargs["time"])) elif cmd == "post": buildURL.append(kwargs["id"]) postData = kwargs["data"] elif cmd == "store": buildURL.append(kwargs["id"]) postData = kwargs["data"] trgAddr = ''.join(buildURL) print(trgAddr) if postData is not None: r = requests.post(trgAddr, data=postData) if r.text: return r.json() else: r = requests.get(trgAddr) #print(r.text) if len(r.text) > 0: if cmd == "get": return r.text else: return r.json()
def store(self,remote,id,data): #print("SENDING NOTIFY",remote,origin) try: r = requests.post(remote.addr+"api/v0/client/store/"+id, data=data) return r.status_code == requests.codes.ok except: return False
def notify(self,remote,origin): #print("SENDING NOTIFY",remote,origin) try: r = requests.post(remote.addr+"api/v0/peer/notify", data=str(origin)) return r.status_code == requests.codes.ok except: return False
def dial(subnet,target, cmd, **kwargs): buildURL = [target["addr"]] buildURL.append(subnet+"/client/") buildURL.append(cmd) buildURL.append("/") postData = None if cmd == "seek" or cmd == "get": buildURL.append(kwargs["id"]) elif cmd == "poll": buildURL.append(kwargs["id"]) buildURL.append("/") buildURL.append(str(kwargs["time"])) elif cmd == "post": buildURL.append(kwargs["id"]) postData = kwargs["data"] elif cmd == "store": buildURL.append(kwargs["id"]) postData = kwargs["data"] trgAddr = ''.join(buildURL) if postData is not None: r = requests.post(trgAddr, data=postData) if r.text: return r.json() else: r = requests.get(trgAddr) #print(r.text) if len(r.text)>0: if cmd == "get": return r.text else: return r.json()
def store(self, service, remote, id, data): # print("SENDING NOTIFY",remote,origin) try: r = requests.post(remote.addr + service + "/client/store/" + id, data=data) return r.status_code == requests.codes.ok except: return False
def notify(self, service, remote, origin): # print("SENDING NOTIFY",remote,origin) try: r = requests.post(remote.addr + service + "/peer/notify", data=str(origin)) return r.status_code == requests.codes.ok except: return False
def proxy(websocket, path): cmd_text = yield from websocket.recv() print(cmd_text) cmd = json.loads(cmd_text) output = "" if cmd["method"] == "seek": seekarg = cmd["id"] newpath = ''.join((hostPath,"seek/",seekarg)) r = requests.get(newpath) peer = r.json() peerAddr = peer["addr"] wsaddr = wsResolve(peerAddr) peer["wsAddr"] = wsaddr print(json.dumps(peer)) output = json.dumps(peer) if cmd["method"] == "get": seekarg = cmd["id"] newpath = ''.join((hostPath,"get/",seekarg)) r = requests.get(newpath) output = r.text if cmd["method"] == "poll": seekarg = cmd["id"] t = cmd["time"] newpath = ''.join((hostPath,"poll/",seekarg,"/",str(t))) r = requests.get(newpath) output = r.text if cmd["method"] == "store": seekarg = cmd["id"] newpath = ''.join((hostPath,"store/",seekarg)) data = json.dumps(cmd["data"]) r = requests.post(newpath, data=data) output = r.text if cmd["method"] == "post": seekarg = cmd["id"] newpath = ''.join((hostPath,"post/",seekarg)) data = json.dumps(cmd["data"]) r = requests.post(newpath, data=data) output = r.text yield from websocket.send(output)