2019-07-12 17:51:35 +00:00
|
|
|
'''
|
|
|
|
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 <https://www.gnu.org/licenses/>.
|
|
|
|
'''
|
2019-07-20 06:02:30 +00:00
|
|
|
from coredb import keydb
|
2019-07-12 17:51:35 +00:00
|
|
|
class PeerProfiles:
|
|
|
|
'''
|
|
|
|
PeerProfiles
|
|
|
|
'''
|
2019-07-19 19:49:56 +00:00
|
|
|
def __init__(self, address):
|
2019-07-12 17:51:35 +00:00
|
|
|
self.address = address # node address
|
|
|
|
self.score = None
|
|
|
|
self.friendSigCount = 0
|
|
|
|
self.success = 0
|
|
|
|
self.failure = 0
|
|
|
|
self.connectTime = None
|
|
|
|
|
|
|
|
self.loadScore()
|
|
|
|
self.getConnectTime()
|
|
|
|
return
|
|
|
|
|
|
|
|
def loadScore(self):
|
|
|
|
'''Load the node's score from the database'''
|
|
|
|
try:
|
2019-07-20 06:02:30 +00:00
|
|
|
self.success = int(keydb.transportinfo.get_address_info(self.address, 'success'))
|
2019-07-12 17:51:35 +00:00
|
|
|
except (TypeError, ValueError) as e:
|
|
|
|
self.success = 0
|
|
|
|
self.score = self.success
|
|
|
|
|
|
|
|
def getConnectTime(self):
|
|
|
|
try:
|
2019-07-20 06:02:30 +00:00
|
|
|
self.connectTime = int(keydb.transportinfo.get_address_info(self.address, 'lastConnect'))
|
2019-07-12 17:51:35 +00:00
|
|
|
except (KeyError, ValueError, TypeError) as e:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def saveScore(self):
|
|
|
|
'''Save the node's score to the database'''
|
2019-07-20 06:02:30 +00:00
|
|
|
keydb.transportinfo.set_address_info(self.address, 'success', self.score)
|
2019-07-12 17:51:35 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
def addScore(self, toAdd):
|
|
|
|
'''Add to the peer's score (can add negative)'''
|
|
|
|
self.score += toAdd
|
|
|
|
self.saveScore()
|