diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index f2ab3397..00000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "onionr/bitpeer"] - path = onionr/bitpeer - url = https://github.com/beardog108/bitpeer.py diff --git a/onionr/onionr.py b/onionr/onionr.py index 333340ad..dcf76318 100755 --- a/onionr/onionr.py +++ b/onionr/onionr.py @@ -265,17 +265,21 @@ class Onionr: return self.cmds def friendCmd(self): - '''List, add, or remove friend(s)''' + '''List, add, or remove friend(s) + Changes their peer DB entry. + ''' friend = '' try: + # Get the friend command action = sys.argv[2] except IndexError: logger.info('Syntax: friend add/remove/list [address]') else: action = action.lower() if action == 'list': + # List out peers marked as our friend for friend in self.onionrCore.listPeers(randomOrder=False, trust=1): - if friend == self.onionrCore._crypto.pubKey: + if friend == self.onionrCore._crypto.pubKey: # do not list our key continue friendProfile = onionrusers.OnionrUser(self.onionrCore, friend) logger.info(friend + ' - ' + friendProfile.getName()) diff --git a/onionr/onionrusers.py b/onionr/onionrusers.py index d258a8da..03807ea9 100644 --- a/onionr/onionrusers.py +++ b/onionr/onionrusers.py @@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . ''' +import onionrblockapi, logger class OnionrUser: def __init__(self, coreInst, publicKey): self.trust = 0 @@ -58,4 +59,15 @@ class OnionrUser: def forwardDecrypt(self, encrypted): return - \ No newline at end of file + + def findAndSetID(self): + '''Find any info about the user from existing blocks and cache it to their DB entry''' + infoBlocks = [] + for bHash in self._core.getBlocksByType('userInfo'): + block = onionrblockapi.Block(bHash, core=self._core) + if block.signer == self.publicKey: + if block.verifySig(): + newName = block.getMetadata('name') + if newName.isalnum(): + logger.info('%s is now using the name %s.' % (self.publicKey, newName)) + self._core.setPeerInfo(self.publicKey, 'name', newName) \ No newline at end of file diff --git a/onionr/onionrutils.py b/onionr/onionrutils.py index 81ebf44a..075077e5 100644 --- a/onionr/onionrutils.py +++ b/onionr/onionrutils.py @@ -23,7 +23,7 @@ import nacl.signing, nacl.encoding from onionrblockapi import Block import onionrexceptions from defusedxml import minidom -import pgpwords +import pgpwords, onionrusers if sys.version_info < (3, 6): try: import sha3 @@ -95,7 +95,6 @@ class OnionrUtils: except IndexError: logger.warn('No pow token') continue - #powHash = self._core._crypto.blake2bHash(base64.b64decode(key[1]) + self._core._crypto.blake2bHash(key[0].encode())) value = base64.b64decode(key[1]) hashedKey = self._core._crypto.blake2bHash(key[0]) powHash = self._core._crypto.blake2bHash(value + hashedKey) @@ -106,6 +105,7 @@ class OnionrUtils: if powHash.startswith(b'0000'): if not key[0] in self._core.listPeers(randomOrder=False) and type(key) != None and key[0] != self._core._crypto.pubKey: if self._core.addPeer(key[0], key[1]): + onionrusers.OnionrUser(self._core, key[0]).findAndSetID() retVal = True else: logger.warn("Failed to add key") @@ -282,6 +282,7 @@ class OnionrUtils: pass else: self._core.setPeerInfo(signer, 'name', peerName) + logger.info('%s is now using the name %s.' % (signer, peerName)) except TypeError: pass diff --git a/onionr/static-data/default-plugins/cliui/main.py b/onionr/static-data/default-plugins/cliui/main.py index 40bcfd6f..1d0db8b0 100644 --- a/onionr/static-data/default-plugins/cliui/main.py +++ b/onionr/static-data/default-plugins/cliui/main.py @@ -19,7 +19,7 @@ ''' # Imports some useful libraries -import logger, config, threading, time +import logger, config, threading, time, uuid from onionrblockapi import Block plugin_name = 'cliui' @@ -32,7 +32,7 @@ class OnionrCLIUI: return def start(self): name = input("Enter your name") - self.myCore.insertBlock("userInfo", sign=True, header='userInfo', meta={'name': name}) + self.myCore.insertBlock("userInfo-" + str(uuid.uuid1()), sign=True, header='userInfo', meta={'name': name}) return def on_init(api, data = None): diff --git a/onionr/static-data/default-plugins/pms/main.py b/onionr/static-data/default-plugins/pms/main.py index 27f56438..dc57a82c 100644 --- a/onionr/static-data/default-plugins/pms/main.py +++ b/onionr/static-data/default-plugins/pms/main.py @@ -21,7 +21,7 @@ # Imports some useful libraries import logger, config, threading, time, readline, datetime from onionrblockapi import Block -import onionrexceptions +import onionrexceptions, onionrusers import locale locale.setlocale(locale.LC_ALL, '') @@ -81,8 +81,15 @@ class OnionrMail: continue blockCount += 1 pmBlockMap[blockCount] = blockHash + + block = Block(blockHash, core=self.myCore) + senderKey = block.getMetadata('signer') + senderDisplay = onionrusers.OnionrUser(self.myCore, senderKey) + if senderDisplay == 'anonymous': + senderDisplay = senderKey + blockDate = pmBlocks[blockHash].getDate().strftime("%m/%d %H:%M") - print('%s. %s: %s' % (blockCount, blockDate, blockHash)) + print('%s. %s - %s: %s' % (blockCount, blockDate, senderDisplay, blockHash)) try: choice = logger.readline('Enter a block number, -r to refresh, or -q to stop: ').strip().lower()