From bfb81d14f4fc4eeda56f8e8c6c7be787716ee024 Mon Sep 17 00:00:00 2001 From: Cameron Dale Date: Thu, 20 Mar 2008 15:26:41 -0700 Subject: [PATCH] Remove the duplicate error logging from the knode module. --- apt_p2p_Khashmir/khashmir.py | 12 ++++++++---- apt_p2p_Khashmir/knode.py | 11 ----------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/apt_p2p_Khashmir/khashmir.py b/apt_p2p_Khashmir/khashmir.py index 230de1f..b3b007d 100644 --- a/apt_p2p_Khashmir/khashmir.py +++ b/apt_p2p_Khashmir/khashmir.py @@ -208,11 +208,13 @@ class KhashmirBase(protocol.Factory): (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: @@ -244,9 +246,11 @@ class KhashmirBase(protocol.Factory): 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: diff --git a/apt_p2p_Khashmir/knode.py b/apt_p2p_Khashmir/knode.py index 36d77bd..1fbdbc3 100644 --- a/apt_p2p_Khashmir/knode.py +++ b/apt_p2p_Khashmir/knode.py @@ -25,29 +25,21 @@ class KNodeBase(Node): 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 @@ -57,14 +49,12 @@ class KNodeRead(KNodeBase): 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 @@ -74,6 +64,5 @@ class KNodeWrite(KNodeRead): 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 -- 2.39.5