(datetime.now() - old.lastSeen) >
timedelta(seconds=self.config['MIN_PING_INTERVAL'])):
- def _staleNodeHandler(failure, oldnode = old, newnode = node):
+ def _staleNodeHandler(err, oldnode = old, newnode = node, self = self):
"""The pinged node never responded, so replace it."""
+ log.msg("ping failed (%s) %s/%s" % (self.config['PORT'], oldnode.host, oldnode.port))
+ log.err(err)
self.table.replaceStaleNode(oldnode, newnode)
- def _notStaleNodeHandler(dict, old=old):
+ def _notStaleNodeHandler(dict, old=old, self=self):
"""Got a pong from the old node, so update it."""
dict = dict['rsp']
if dict['id'] == old.id:
if callback:
callback((dict['rsp']['ip_addr'], dict['rsp']['port']))
- def _defaultPong(err, node=node, table=self.table, callback=callback, errback=errback):
+ def _defaultPong(err, node=node, self=self, callback=callback, errback=errback):
"""Error occurred, fail node and errback or callback with error."""
- table.nodeFailed(node)
+ log.msg("join failed (%s) %s/%s" % (self.config['PORT'], node.host, node.port))
+ log.err(err)
+ self.table.nodeFailed(node)
if errback:
errback()
elif callback:
return dict
- def errBack(self, err):
- """Log an error that has occurred."""
- log.err(err)
- return err
-
def ping(self, id):
"""Ping the node."""
df = self.conn.sendRequest('ping', {"id":id})
- df.addErrback(self.errBack)
df.addCallback(self.checkSender)
return df
def join(self, id):
"""Use the node to bootstrap into the system."""
df = self.conn.sendRequest('join', {"id":id})
- df.addErrback(self.errBack)
df.addCallback(self.checkSender)
return df
def find_node(self, id, target):
"""Request the nearest nodes to the target that the node knows about."""
df = self.conn.sendRequest('find_node', {"target" : target, "id": id})
- df.addErrback(self.errBack)
df.addCallback(self.checkSender)
return df
def find_value(self, id, key):
"""Request the nearest nodes to the key that the node knows about."""
df = self.conn.sendRequest('find_value', {"key" : key, "id" : id})
- df.addErrback(self.errBack)
df.addCallback(self.checkSender)
return df
def get_value(self, id, key, num):
"""Request the values that the node has for the key."""
df = self.conn.sendRequest('get_value', {"key" : key, "num": num, "id" : id})
- df.addErrback(self.errBack)
df.addCallback(self.checkSender)
return df
def store_value(self, id, key, value, token):
"""Store a value in the node."""
df = self.conn.sendRequest('store_value', {"key" : key, "value" : value, "token" : token, "id": id})
- df.addErrback(self.errBack)
df.addCallback(self.checkSender)
return df