From 1ba26541b2709301d5c1b83bbef3be61878c5460 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Fri, 12 Jul 2019 12:51:35 -0500 Subject: [PATCH] put peerprofiles in its own file --- onionr/onionrpeers/__init__.py | 64 +---------------------- onionr/onionrpeers/peerprofiles.py | 60 +++++++++++++++++++++ onionr/onionrpeers/scoresortedpeerlist.py | 3 +- 3 files changed, 64 insertions(+), 63 deletions(-) create mode 100644 onionr/onionrpeers/peerprofiles.py diff --git a/onionr/onionrpeers/__init__.py b/onionr/onionrpeers/__init__.py index 17b571c8..cd4aa8b2 100755 --- a/onionr/onionrpeers/__init__.py +++ b/onionr/onionrpeers/__init__.py @@ -1,64 +1,4 @@ -''' - Onionr - Private P2P Communication - - This file contains both the PeerProfiles class for network profiling of Onionr nodes -''' -''' - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -''' -from . import scoresortedpeerlist, peercleanup +from . import scoresortedpeerlist, peercleanup, peerprofiles get_score_sorted_peer_list = scoresortedpeerlist.get_score_sorted_peer_list peer_cleanup = peercleanup.peer_cleanup - -class PeerProfiles: - ''' - PeerProfiles - ''' - def __init__(self, address, coreInst): - self.address = address # node address - self.score = None - self.friendSigCount = 0 - self.success = 0 - self.failure = 0 - self.connectTime = None - - self.coreInst = coreInst - - self.loadScore() - self.getConnectTime() - return - - def loadScore(self): - '''Load the node's score from the database''' - try: - self.success = int(self.coreInst.getAddressInfo(self.address, 'success')) - except (TypeError, ValueError) as e: - self.success = 0 - self.score = self.success - - def getConnectTime(self): - try: - self.connectTime = int(self.coreInst.getAddressInfo(self.address, 'lastConnect')) - except (KeyError, ValueError, TypeError) as e: - pass - - def saveScore(self): - '''Save the node's score to the database''' - self.coreInst.setAddressInfo(self.address, 'success', self.score) - return - - def addScore(self, toAdd): - '''Add to the peer's score (can add negative)''' - self.score += toAdd - self.saveScore() +PeerProfiles = peerprofiles.PeerProfiles \ No newline at end of file diff --git a/onionr/onionrpeers/peerprofiles.py b/onionr/onionrpeers/peerprofiles.py new file mode 100644 index 00000000..791e8c45 --- /dev/null +++ b/onionr/onionrpeers/peerprofiles.py @@ -0,0 +1,60 @@ +''' + Onionr - Private P2P Communication + + This file contains both the PeerProfiles class for network profiling of Onionr nodes +''' +''' + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +''' +class PeerProfiles: + ''' + PeerProfiles + ''' + def __init__(self, address, coreInst): + self.address = address # node address + self.score = None + self.friendSigCount = 0 + self.success = 0 + self.failure = 0 + self.connectTime = None + + self.coreInst = coreInst + + self.loadScore() + self.getConnectTime() + return + + def loadScore(self): + '''Load the node's score from the database''' + try: + self.success = int(self.coreInst.getAddressInfo(self.address, 'success')) + except (TypeError, ValueError) as e: + self.success = 0 + self.score = self.success + + def getConnectTime(self): + try: + self.connectTime = int(self.coreInst.getAddressInfo(self.address, 'lastConnect')) + except (KeyError, ValueError, TypeError) as e: + pass + + def saveScore(self): + '''Save the node's score to the database''' + self.coreInst.setAddressInfo(self.address, 'success', self.score) + return + + def addScore(self, toAdd): + '''Add to the peer's score (can add negative)''' + self.score += toAdd + self.saveScore() \ No newline at end of file diff --git a/onionr/onionrpeers/scoresortedpeerlist.py b/onionr/onionrpeers/scoresortedpeerlist.py index 22696766..9c30e586 100644 --- a/onionr/onionrpeers/scoresortedpeerlist.py +++ b/onionr/onionrpeers/scoresortedpeerlist.py @@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . ''' +from . import peerprofiles def get_score_sorted_peer_list(coreInst): peer_list = coreInst.listAdders() peer_scores = {} @@ -24,7 +25,7 @@ def get_score_sorted_peer_list(coreInst): for address in peer_list: # Load peer's profiles into a list - profile = PeerProfiles(address, coreInst) + profile = peerprofiles.PeerProfiles(address, coreInst) peer_scores[address] = profile.score if not isinstance(profile.connectTime, type(None)): peer_times[address] = profile.connectTime