From 671642b5862a8309c342848843c1ab41d2e515a7 Mon Sep 17 00:00:00 2001 From: Cameron Dale Date: Tue, 4 Mar 2008 16:03:28 -0800 Subject: [PATCH] Document the DHT's knode module. --- apt_dht_Khashmir/knode.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/apt_dht_Khashmir/knode.py b/apt_dht_Khashmir/knode.py index ea714e6..e7fb6b3 100644 --- a/apt_dht_Khashmir/knode.py +++ b/apt_dht_Khashmir/knode.py @@ -1,12 +1,17 @@ ## Copyright 2002-2004 Andrew Loewenstern, All Rights Reserved # see LICENSE.txt for license information +"""Represents a khashmir node in the DHT.""" + from twisted.python import log from node import Node, NULL_ID class KNodeBase(Node): + """A basic node that can only be pinged and help find other nodes.""" + def checkSender(self, dict): + """Check the sender's info to make sure it meets expectations.""" try: senderid = dict['rsp']['id'] except KeyError: @@ -20,42 +25,53 @@ 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 findNode(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 class KNodeRead(KNodeBase): + """More advanced node that can also find and send values.""" + def findValue(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 getValue(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 class KNodeWrite(KNodeRead): + """Most advanced node that can also store values.""" + def storeValue(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) -- 2.30.2