remove hashwatcher

This commit is contained in:
Jack Robison 2018-05-23 16:44:09 -04:00
parent e4219b9cfc
commit e6ffd7caf8
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
2 changed files with 0 additions and 40 deletions

View file

@ -1,33 +0,0 @@
from collections import Counter
import datetime
from twisted.internet import task
class HashWatcher(object):
def __init__(self, clock=None):
if not clock:
from twisted.internet import reactor as clock
self.ttl = 600
self.hashes = []
self.lc = task.LoopingCall(self._remove_old_hashes)
self.lc.clock = clock
def start(self):
return self.lc.start(10)
def stop(self):
return self.lc.stop()
def add_requested_hash(self, hashsum, contact):
from_ip = contact.compact_ip
matching_hashes = [h for h in self.hashes if h[0] == hashsum and h[2] == from_ip]
if len(matching_hashes) == 0:
self.hashes.append((hashsum, datetime.datetime.now(), from_ip))
def most_popular_hashes(self, num_to_return=10):
hash_counter = Counter([h[0] for h in self.hashes])
return hash_counter.most_common(num_to_return)
def _remove_old_hashes(self):
remove_time = datetime.datetime.now() - datetime.timedelta(minutes=10)
self.hashes = [h for h in self.hashes if h[1] < remove_time]

View file

@ -25,7 +25,6 @@ import protocol
from error import TimeoutError from error import TimeoutError
from peerfinder import DHTPeerFinder from peerfinder import DHTPeerFinder
from contact import Contact from contact import Contact
from hashwatcher import HashWatcher
from distance import Distance from distance import Distance
@ -137,8 +136,6 @@ class Node(object):
self._routingTable.addContact(contact) self._routingTable.addContact(contact)
self.externalIP = externalIP self.externalIP = externalIP
self.peerPort = peerPort self.peerPort = peerPort
self.hash_watcher = HashWatcher(self.clock)
self.peer_manager = peer_manager or PeerManager() self.peer_manager = peer_manager or PeerManager()
self.peer_finder = peer_finder or DHTPeerFinder(self, self.peer_manager) self.peer_finder = peer_finder or DHTPeerFinder(self, self.peer_manager)
@ -156,8 +153,6 @@ class Node(object):
yield self.change_token_lc.stop() yield self.change_token_lc.stop()
if self._listeningPort is not None: if self._listeningPort is not None:
yield self._listeningPort.stopListening() yield self._listeningPort.stopListening()
if self.hash_watcher.lc.running:
yield self.hash_watcher.stop()
def start_listening(self): def start_listening(self):
if not self._listeningPort: if not self._listeningPort:
@ -223,7 +218,6 @@ class Node(object):
# Start refreshing k-buckets periodically, if necessary # Start refreshing k-buckets periodically, if necessary
self.bootstrap_join(known_node_addresses or [], self._joinDeferred) self.bootstrap_join(known_node_addresses or [], self._joinDeferred)
yield self._joinDeferred yield self._joinDeferred
self.hash_watcher.start()
self.change_token_lc.start(constants.tokenSecretChangeInterval) self.change_token_lc.start(constants.tokenSecretChangeInterval)
self.refresh_node_lc.start(constants.checkRefreshInterval) self.refresh_node_lc.start(constants.checkRefreshInterval)
@ -570,7 +564,6 @@ class Node(object):
contact = kwargs['_rpcNodeContact'] contact = kwargs['_rpcNodeContact']
compact_ip = contact.compact_ip() compact_ip = contact.compact_ip()
rval['token'] = self.make_token(compact_ip) rval['token'] = self.make_token(compact_ip)
self.hash_watcher.add_requested_hash(key, contact)
return rval return rval
def _generateID(self): def _generateID(self):