-Change all print statements to log.msg() calls.
-
-
-Add ability to search and hash and DHT-store other directories.
-
-The user should be able to specify a list of directories that will be
-searched for files to hash and add to the DHT.
-
-
Missing Kademlia implementation details are needed.
The current implementation is missing some important features, mostly
# see LICENSE.txt for license information
from twisted.internet import reactor
+from twisted.python import log
from khash import intify
def makeMsgFailed(self, node):
def defaultGotNodes(err, self=self, node=node):
- print ">>> find failed (%s) %s/%s" % (self.config['PORT'], node.host, node.port), err
+ log.msg("find failed (%s) %s/%s" % (self.config['PORT'], node.host, node.port))
+ log.err(err)
self.caller.table.nodeFailed(node)
self.outstanding = self.outstanding - 1
self.schedule()
try:
f = getattr(node, self.findValue)
except AttributeError:
- print ">>> findValue %s doesn't have a %s method!" % (node, self.findValue)
+ log.msg("findValue %s doesn't have a %s method!" % (node, self.findValue))
else:
df = f(self.target, self.caller.node.id)
df.addCallback(self.handleGotNodes)
return t
def storeFailed(self, t, node):
- print ">>> store failed %s/%s" % (node.host, node.port)
+ log.msg("store failed %s/%s" % (node.host, node.port))
self.caller.nodeFailed(node)
self.outstanding -= 1
if self.finished:
try:
f = getattr(node, self.store)
except AttributeError:
- print ">>> %s doesn't have a %s method!" % (node, self.store)
+ log.msg("%s doesn't have a %s method!" % (node, self.store))
else:
df = f(self.target, self.value, self.originated, self.caller.node.id)
df.addCallback(self.storedValue, node=node)
## Copyright 2002-2004 Andrew Loewenstern, All Rights Reserved
# see LICENSE.txt for license information
+from twisted.python import log
+
from node import Node, NULL_ID
class KNodeBase(Node):
try:
senderid = dict['rsp']['id']
except KeyError:
- print ">>>> No peer id in response"
+ log.msg("No peer id in response")
raise Exception, "No peer id in response."
else:
if self.id != NULL_ID and senderid != self.id:
- print "Got response from different node than expected."
+ log.msg("Got response from different node than expected.")
self.table.invalidateNode(self)
return dict
def errBack(self, err):
- print ">>> ", err
+ log.err(err)
return err
def ping(self, id):
from twisted.internet.defer import Deferred
from twisted.internet import protocol, reactor
+from twisted.python import log
from twisted.trial import unittest
from khash import newID
def datagramReceived(self, str, addr):
if self.stopped:
if self.noisy:
- print "stopped, dropping message from", addr, str
+ log.msg("stopped, dropping message from %r: %s" % (addr, str))
# bdecode
try:
msg = bdecode(str)
except Exception, e:
if self.noisy:
- print "response decode error: " + `e`
+ log.msg("response decode error: ")
+ log.err(e)
else:
if self.noisy:
- print self.factory.port, "received from", addr, self.addr, ":", msg
+ log.msg("%d received from %r: %s" % (self.factory.port, addr, msg))
# look at msg type
if msg[TYP] == REQ:
ilen = len(str)
olen = self._sendResponse(addr, msg[TID], RSP, ret)
else:
if self.noisy:
- print "don't know about method %s" % msg[REQ]
+ log.msg("don't know about method %s" % msg[REQ])
# unknown method
olen = self._sendResponse(addr, msg[TID], ERR, KRPC_ERROR_METHOD_UNKNOWN)
if self.noisy:
- print "%s %s >>> %s - %s %s %s" % (asctime(), addr, self.factory.node.port,
- ilen, msg[REQ], olen)
+ log.msg("%s >>> %s - %s %s %s" % (addr, self.factory.node.port,
+ ilen, msg[REQ], olen))
elif msg[TYP] == RSP:
# if response
# lookup tid
del(self.tids[msg[TID]])
df.callback({'rsp' : msg[RSP], '_krpc_sender': addr})
else:
- print 'timeout ' + `msg[RSP]['id']`
# no tid, this transaction timed out already...
+ if self.noisy:
+ log.msg('timeout: %r' % msg[RSP]['id'])
elif msg[TYP] == ERR:
# if error
# lookup tid
# day late and dollar short
pass
else:
- print "unknown message type " + `msg`
+ if self.noisy:
+ log.msg("unknown message type: %r" % msg)
# unknown message type
df = self.tids[msg[TID]]
# callback
msg = {TID : tid, TYP : msgType, msgType : response}
if self.noisy:
- print self.factory.port, "responding to", addr, ":", msg
+ log.msg("%d responding to %r: %s" % (self.factory.port, addr, msg))
out = bencode(msg)
self.transport.write(out, addr)
# send it
msg = {TID : newID(), TYP : REQ, REQ : method, ARG : args}
if self.noisy:
- print self.factory.port, "sending to", self.addr, ":", msg
+ log.msg("%d sending to %r: %s" % (self.factory.port, self.addr, msg))
str = bencode(msg)
d = Deferred()
self.tids[msg[TID]] = d
if tids.has_key(id):
df = tids[id]
del(tids[id])
- print ">>>>>> KRPC_ERROR_TIMEOUT"
+ log.msg(">>>>>> KRPC_ERROR_TIMEOUT")
df.errback(ProtocolError('timeout waiting for %r' % msg))
later = reactor.callLater(KRPC_TIMEOUT, timeOut)
def dropTimeOut(dict, later_call = later):
from datetime import datetime
from bisect import bisect_left
+from twisted.python import log
from twisted.trial import unittest
import khash
# this bucket is full and contains our node, split the bucket
if len(self.buckets) >= self.config['HASH_LENGTH']:
# our table is FULL, this is really unlikely
- print "Hash Table is FULL! Increase K!"
+ log.err("Hash Table is FULL! Increase K!")
return
self._splitBucket(self.buckets[i])
"""
- print '************************** apt-get (' + str(num_down) + ') ' + ' '.join(cmd) + ' **************************'
+ print '*************** apt-get (' + str(num_down) + ') ' + ' '.join(cmd) + ' ****************'
apt_conf = join([down_dir(num_down), 'etc', 'apt', 'apt.conf'])
dpkg_status = join([down_dir(num_down), 'var', 'lib', 'dpkg', 'status'])
args = ['-d', '-c', apt_conf, '-o', 'Dir::state::status='+dpkg_status] + cmd
apt_get_results.append((elapsed, r_value))
if r_value == 0:
- print '********************** apt-get completed successfully in ' + str(elapsed) + ' sec. **************************'
+ print '********** apt-get completed successfully in ' + str(elapsed) + ' sec. *****************'
else:
- print '********************** apt-get finished with status ' + str(r_value) + ' in ' + str(elapsed) + ' sec. **************************'
+ print '********** apt-get finished with status ' + str(r_value) + ' in ' + str(elapsed) + ' sec. ************'
sleep(5)