def writeToNet(self, value): # we need a client to talk to the peer head client = Simple_Client(self.host, self.port) # put a header so the app_support server knows what to do with the data string d_item = DataItem(value) msg = "WRITE_DATA|" + d_item.key + "|" + d_item.value # send the data and return client.connect_send__receive_close(self.host, self.port, msg) return d_item.key
def deleteFromNet(self, key): # we need a client to talk to the peer head client = Simple_Client(self.host, self.port) # put a header so the app_support server knows what to do with the data string msg = "DELETE|" + key # send the data and return return client.connect_send__receive_close(self.host, self.port, msg)
def joinNetwork(self): # we need a client to talk to the peer head client = Simple_Client(self.host, self.port) msg = "JOIN_NETWORK|" # send the data and return response = client.connect_send__receive_close(self.host, self.port, msg) return response
def findPeer(self): # we need a client to talk to the peer head client = Simple_Client(self.host, self.port) msg = "FIND_PEER|" + self.host # send the data and return response = client.connect_send__receive_close(self.host, self.port, msg) return response
def locateHash(self, hash): # we need a client to talk to the peer head client = Simple_Client(self.host, self.port) msg = "LOOKUP|" + hash # send the data and return response = client.connect_send__receive_close(self.host, self.port, msg) return response
def DumpPeerData(self): # we need a client to talk to the peer head client = Simple_Client(self.host, self.port) msg = "DUMP_PEER_DATA|" # send the data and return response = client.connect_send__receive_close(self.host, self.port, msg) return response
def readFromNet(self, key): # we need a client to talk to the peer head client = Simple_Client(self.host, self.port) # put a header so the app_support server knows what to do with the data # string msg = "READ_DATA|{0}".format(key) # send the data and return return client.connect_send__receive_close(self.host, self.port, msg)
def hasListener(self): response = "" client = Simple_Client(self.host, self.port) try: response = client.connect_send__receive_close(self.host, self.port, "PING|") except: return False if response == "OK": return True return False
def getNeighbors(self, mode): # we need a client to talk to the peer head client = Simple_Client(self.host, self.port) if mode == "FULL": msg = "GET_NET_STAT|FULL" else: msg = "GET_NET_STAT|CSV" # send the data and return return client.connect_send__receive_close(self.host, self.port, msg)
def getNeighbors(self, mode): # we need a client to talk to the peer head client = Simple_Client(self.host, self.port) if mode == "FULL": msg = "GET_NET_STAT|FULL" else: msg = "GET_NET_STAT|CSV" # send the data and return response = client.connect_send__receive_close(self.host, self.port, msg) return response
def leaveNetwork(self): # we need a client to talk to the peer head client = Simple_Client(self.host, self.port) msg = "LEAVE_NETWORK|" # send the data and return return client.connect_send__receive_close(self.host, self.port, msg)
def networkSize(self): # we need a client to talk to the peer head client = Simple_Client(self.host, self.port) msg = "NETWORK_SIZE|" # send the data and return return client.connect_send__receive_close(self.host, self.port, msg)