def _joinNetwork_findNodeWorker(host): try: newHost = httpGet('http://' + host + '/node').strip() with Session() as s: if Node.getThisNode(s, newHost).first(): return Node.add(s, newHost) s.commit() except URLError: pass
def _doPing_worker(host): try: response = httpGet('http://' + host + '/ping').splitlines() with Session() as s: node = Node.getThisNode(s, host).first() if response[0].strip() != 'PONG': node.linked = False else: node.updateTimestamp() if len(response) > 1: newNodeHost = response[1].strip() newNode = Node.getThisNode(s, newNodeHost).first() if not newNode: Node.add(s, newNodeHost) s.commit() except URLError: pass
def _joinNetwork_joinWorker(host): try: response = httpGet('http://' + host + '/join/' + settings.NODE_NAME).splitlines() if response[0] != 'WELCOME': return with Session() as s: node = Node.getThisNode(s, host).first() if node: node.linked = True else: Node.add(s, host) s.commit() if len(response) == 2: newHost = response[1] with Session() as s: if Node.getThisNode(s, newHost).first(): return Node.add(s, newHost) s.commit() except URLError: pass