From e80887d7796609464e57ceb33b68bc7fd4f2f319 Mon Sep 17 00:00:00 2001 From: shortcutme Date: Mon, 27 Feb 2017 00:06:13 +0100 Subject: [PATCH] Add reputation for old peers --- plugins/PeerDb/PeerDbPlugin.py | 1 + src/Peer/Peer.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/PeerDb/PeerDbPlugin.py b/plugins/PeerDb/PeerDbPlugin.py index 05de8fe0..c7a1e073 100644 --- a/plugins/PeerDb/PeerDbPlugin.py +++ b/plugins/PeerDb/PeerDbPlugin.py @@ -46,6 +46,7 @@ class ContentDbPlugin(object): peer.hashfield.replaceFromString(row["hashfield"]) num_hashfield += 1 peer.time_added = row["time_added"] + peer.reputation = int((time.time() - peer.time_added) / (60 * 60 * 24)) # Older peers has more reputation num += 1 site.log.debug("%s peers (%s with hashfield) loaded in %.3fs" % (num, num_hashfield, time.time() - s)) diff --git a/src/Peer/Peer.py b/src/Peer/Peer.py index e05bc346..032990f6 100644 --- a/src/Peer/Peer.py +++ b/src/Peer/Peer.py @@ -18,7 +18,7 @@ if config.use_tempfiles: class Peer(object): __slots__ = ( "ip", "port", "site", "key", "connection", "connection_server", "time_found", "time_response", "time_hashfield", "time_added", "has_hashfield", - "time_my_hashfield_sent", "last_ping", "last_content_json_update", "hashfield", "connection_error", "hash_failed", "download_bytes", "download_time" + "time_my_hashfield_sent", "last_ping", "reputation", "last_content_json_update", "hashfield", "connection_error", "hash_failed", "download_bytes", "download_time" ) def __init__(self, ip, port, site=None, connection_server=None): @@ -36,6 +36,7 @@ class Peer(object): self.time_response = None # Time of last successful response from peer self.time_added = time.time() self.last_ping = None # Last response time for ping + self.reputation = 0 # More likely to connect if larger self.last_content_json_update = 0.0 # Modify date of last received content.json self.connection_error = 0 # Series of connection error