fixed default storage culling bug, linted, bumped version to 0.4

This commit is contained in:
Brian Muller 2015-01-04 14:40:52 -05:00
parent c6f1062082
commit ae7a90926b
6 changed files with 8 additions and 9 deletions

View File

@ -3,5 +3,5 @@ Kademlia is a Python implementation of the Kademlia protocol for U{Twisted <http
@author: Brian Muller U{bamuller@gmail.com} @author: Brian Muller U{bamuller@gmail.com}
""" """
version_info = (0, 3) version_info = (0, 4)
version = '.'.join(map(str, version_info)) version = '.'.join(map(str, version_info))

View File

@ -187,7 +187,7 @@ class Server(object):
""" """
Load the state of this node (the alpha/ksize/id/immediate neighbors) Load the state of this node (the alpha/ksize/id/immediate neighbors)
from a cache file with the given fname. from a cache file with the given fname.
""" """
with open(fname, 'r') as f: with open(fname, 'r') as f:
data = pickle.load(f) data = pickle.load(f)
s = Server(data['ksize'], data['alpha'], data['id']) s = Server(data['ksize'], data['alpha'], data['id'])
@ -199,7 +199,7 @@ class Server(object):
""" """
Save the state of node with a given regularity to the given Save the state of node with a given regularity to the given
filename. filename.
@param fname: File to save retularly to @param fname: File to save retularly to
@param frequencey: Frequency in seconds that the state @param frequencey: Frequency in seconds that the state
should be saved. By default, 10 minutes. should be saved. By default, 10 minutes.

View File

@ -60,7 +60,7 @@ class NodeHeap(object):
return return
nheap = [] nheap = []
for distance, node in self.heap: for distance, node in self.heap:
if not node.id in peerIDs: if node.id not in peerIDs:
heapq.heappush(nheap, (distance, node)) heapq.heappush(nheap, (distance, node))
self.heap = nheap self.heap = nheap
@ -105,4 +105,4 @@ class NodeHeap(object):
return iter(map(itemgetter(1), nodes)) return iter(map(itemgetter(1), nodes))
def getUncontacted(self): def getUncontacted(self):
return [n for n in self if not n.id in self.contacted] return [n for n in self if n.id not in self.contacted]

View File

@ -30,7 +30,7 @@ class KBucket(object):
return (one, two) return (one, two)
def removeNode(self, node): def removeNode(self, node):
if not node.id in self.nodes: if node.id not in self.nodes:
return return
# delete node, and see if we can add a replacement # delete node, and see if we can add a replacement

View File

@ -58,7 +58,7 @@ class ForgetfulStorage(object):
def cull(self): def cull(self):
for k, v in self.iteritemsOlderThan(self.ttl): for k, v in self.iteritemsOlderThan(self.ttl):
self.data.popitem(first=True) self.data.popitem(last=False)
def get(self, key, default=None): def get(self, key, default=None):
self.cull() self.cull()

View File

@ -1,7 +1,6 @@
from twisted.trial import unittest from twisted.trial import unittest
from kademlia.routing import KBucket, RoutingTable from kademlia.routing import KBucket
from kademlia.protocol import KademliaProtocol
from kademlia.tests.utils import mknode, FakeProtocol from kademlia.tests.utils import mknode, FakeProtocol