def seekPoint(self, service, remote, point): path = remote.addr + service + "/peer/" + "seekPoint/%s" % point val = None try: r = requests.get(path) results = r.json() val = util.PeerInfo(results["id"], results["addr"], results["loc"]) except Exception: raise DialFailed() return val
def getPredecessor(self, service, remote): result = [] try: r = requests.get(remote.addr + service + "/peer/getPredecessor/") if len(r.json()) == 0: return [] for p in r.json(): newPeer = util.PeerInfo(p["id"], p["addr"], p["loc"]) result.append(newPeer) except Exception: raise DialFailed() return result
def seek(self, service, remote, id): """ This function remotely calls seek on the remote node, asking it to run LogicComponent.seek() on id """ path = remote.addr + service + "/peer/" + "seek/%s" % id val = None try: r = requests.get(path) results = r.json() val = util.PeerInfo(results["id"], results["addr"], results["loc"]) except Exception: raise DialFailed() return val
ip = config["bindAddr"] port = config["bindPort"] loc = None if type(config["loc"]) is type([]) and len(config["loc"]) == 2: print("updating loc") loc = tuple(config["loc"]) net = NetworkClass.Networking(ip, port) data = DataBaseClass.DataBase() bootstraps = jsonLoad(config["bootstraps"]) peerPool = [ util.PeerInfo(x["id"], x["addr"], x["loc"]) for x in bootstraps ] print(peerPool) peerPool = list(filter(lambda x: net.ping("UrDHT", x), peerPool)) #filter only living bootstrap peers path = config["publicAddr"] if len(path) == 0 and len(peerPool) > 0: random_peer = random.choice(peerPool) pubip = net.getIP("UrDHT", random_peer) path = "http://%s:%d/" % (pubip, port) else: if path[-1] != "/": path += "/" if path[0:4] != "http":