added peerprofiles and filepaths tests

This commit is contained in:
Kevin Froman 2019-09-14 01:29:31 -05:00
parent 4f6f83f383
commit 376b2cc2d6
9 changed files with 103 additions and 10 deletions

View file

@ -24,7 +24,7 @@ from onionrutils import localcommand, epoch
from .. import dbfiles
import dbcreator
def daemon_queue():
def daemon_queue()->str:
'''
Gives commands to the communication proccess/daemon by reading an sqlite3 database
@ -51,7 +51,7 @@ def daemon_queue():
return retData
def daemon_queue_add(command, data='', responseID=''):
def daemon_queue_add(command: str, data='', responseID: str =''):
'''
Add a command to the daemon queue, used by the communication daemon (communicator.py)
'''

View file

@ -94,7 +94,7 @@ class PrivateEndpoints:
# returns node stats
while True:
try:
return Response(client_api._too_many.get(SerializedData).getStats())
return Response(client_api._too_many.get(SerializedData).get_stats())
except AttributeError as e:
pass

View file

@ -17,6 +17,7 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
from typing import Callable
from .. import onionrstatistics, version, daemonlaunch, keyadders, openwebinterface
from .. import banblocks # Command to blacklist a block by its hash
from .. import filecommands # commands to share files with onionr
@ -28,7 +29,7 @@ from .. import softreset # command to delete onionr blocks
import onionrexceptions
from onionrutils import importnewblocks # func to import new blocks
import onionrevents as events
def get_arguments():
def get_arguments()->dict:
"""This is a function because we need to be able to dynamically modify them with plugins"""
args = {
('blacklist', 'blacklist-block', 'remove-block', 'removeblock', 'banblock', 'ban-block'): banblocks.ban_block,
@ -64,7 +65,7 @@ def get_help(arg: str) -> str:
if arg in argument: return arguments[argument].onionr_help
raise KeyError
def get_func(argument):
def get_func(argument: str) -> Callable:
"""Returns the function for a given command argument"""
argument = argument.lower()
args = get_arguments()

View file

@ -19,6 +19,9 @@
'''
from coredb import keydb
from onionrutils import epoch
from onionrutils import stringvalidators
import onionrblacklist
import onionrexceptions
UPDATE_DELAY = 300
@ -27,6 +30,7 @@ class PeerProfiles:
PeerProfiles
'''
def __init__(self, address):
if not stringvalidators.validate_transport(address): raise onionrexceptions.InvalidAddress
self.address = address # node address
self.score = None
self.friendSigCount = 0
@ -38,7 +42,9 @@ class PeerProfiles:
self.getConnectTime()
self.last_updated = {'connect_time': UPDATE_DELAY, 'score': UPDATE_DELAY} # Last time a given value was updated
return
if not address in keydb.listkeys.list_adders() and not onionrblacklist.OnionrBlackList().inBlacklist(address):
keydb.addkeys.add_address(address)
def loadScore(self):
'''Load the node's score from the database'''
@ -49,10 +55,13 @@ class PeerProfiles:
self.score = self.success
def getConnectTime(self):
"""set the connectTime variable for when we last connected to them, using the db value"""
try:
self.connectTime = int(keydb.transportinfo.get_address_info(self.address, 'lastConnect'))
except (KeyError, ValueError, TypeError) as e:
pass
else:
return self.connectTime
def update_connect_time(self):
if epoch.get_epoch() - self.last_updated['connect_time'] >= UPDATE_DELAY:
@ -69,4 +78,4 @@ class PeerProfiles:
def addScore(self, toAdd):
'''Add to the peer's score (can add negative)'''
self.score += toAdd
self.saveScore()
self.saveScore()

View file

@ -32,7 +32,7 @@ class SerializedData:
}
'''
def getStats(self):
def get_stats(self):
'''Return statistics about our node'''
stats = {}
try:

View file

@ -23,7 +23,8 @@ import dbcreator, filepaths
home = identifyhome.identify_home()
def create_dirs():
"""Creates onionr data-related directories in order of the hardcoded list below"""
"""Creates onionr data-related directories in order of the hardcoded list below,
then trigger creation of DBs"""
gen_dirs = [home, filepaths.block_data_location, filepaths.contacts_location, filepaths.export_location]
for path in gen_dirs:
if not os.path.exists(path):