From c907558dd147d3a17ffa6aec3efbf04efd87a39b Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Mon, 27 Aug 2018 23:45:31 -0500 Subject: [PATCH] more work on user info --- onionr/onionr.py | 5 +- onionr/onionrusers.py | 12 ++++- onionr/onionrutils.py | 2 +- .../default-plugins/cliui/info.json | 5 ++ .../static-data/default-plugins/cliui/main.py | 51 +++++++++++++++++++ 5 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 onionr/static-data/default-plugins/cliui/info.json create mode 100644 onionr/static-data/default-plugins/cliui/main.py diff --git a/onionr/onionr.py b/onionr/onionr.py index 5408b2c4..333340ad 100755 --- a/onionr/onionr.py +++ b/onionr/onionr.py @@ -275,7 +275,10 @@ class Onionr: action = action.lower() if action == 'list': for friend in self.onionrCore.listPeers(randomOrder=False, trust=1): - logger.info(friend) + if friend == self.onionrCore._crypto.pubKey: + continue + friendProfile = onionrusers.OnionrUser(self.onionrCore, friend) + logger.info(friend + ' - ' + friendProfile.getName()) elif action in ('add', 'remove'): try: friend = sys.argv[3] diff --git a/onionr/onionrusers.py b/onionr/onionrusers.py index 9138e1ce..d258a8da 100644 --- a/onionr/onionrusers.py +++ b/onionr/onionrusers.py @@ -31,9 +31,19 @@ class OnionrUser: self._core.setPeerInfo(self.publicKey, 'trust', newTrust) def isFriend(self): - if self._core.getPeerInfo(self.publicKey, 6) == 1: + if self._core.getPeerInfo(self.publicKey, 'trust') == 1: return True return False + + def getName(self): + retData = 'anonymous' + name = self._core.getPeerInfo(self.publicKey, 'name') + try: + if len(name) > 0: + retData = name + except ValueError: + pass + return retData def encrypt(self, data): encrypted = coreInst._crypto.pubKeyEncrypt(data, self.publicKey, encodedData=True) diff --git a/onionr/onionrutils.py b/onionr/onionrutils.py index 8e8f5ab8..81ebf44a 100644 --- a/onionr/onionrutils.py +++ b/onionr/onionrutils.py @@ -264,7 +264,7 @@ class OnionrUtils: if myBlock.isEncrypted: myBlock.decrypt() blockType = myBlock.getMetadata('type') # we would use myBlock.getType() here, but it is bugged with encrypted blocks - signer = myBlock.getSigner() + signer = myBlock.signer try: if len(blockType) <= 10: diff --git a/onionr/static-data/default-plugins/cliui/info.json b/onionr/static-data/default-plugins/cliui/info.json new file mode 100644 index 00000000..e06855f6 --- /dev/null +++ b/onionr/static-data/default-plugins/cliui/info.json @@ -0,0 +1,5 @@ +{ + "name" : "cliui", + "version" : "1.0", + "author" : "onionr" +} diff --git a/onionr/static-data/default-plugins/cliui/main.py b/onionr/static-data/default-plugins/cliui/main.py new file mode 100644 index 00000000..40bcfd6f --- /dev/null +++ b/onionr/static-data/default-plugins/cliui/main.py @@ -0,0 +1,51 @@ +''' + Onionr - P2P Anonymous Storage Network + + This is an interactive menu-driven CLI interface for Onionr +''' +''' + 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 . +''' + +# Imports some useful libraries +import logger, config, threading, time +from onionrblockapi import Block + +plugin_name = 'cliui' +PLUGIN_VERSION = '0.0.1' + +class OnionrCLIUI: + def __init__(self, apiInst): + self.api = apiInst + self.myCore = apiInst.get_core() + return + def start(self): + name = input("Enter your name") + self.myCore.insertBlock("userInfo", sign=True, header='userInfo', meta={'name': name}) + return + +def on_init(api, data = None): + ''' + This event is called after Onionr is initialized, but before the command + inputted is executed. Could be called when daemon is starting or when + just the client is running. + ''' + + # Doing this makes it so that the other functions can access the api object + # by simply referencing the variable `pluginapi`. + pluginapi = api + ui = OnionrCLIUI(api) + api.commands.register('interactive', ui.start) + api.commands.register_help('interactive', 'Open the CLI interface') + return