better user info syncing and show names in mail

This commit is contained in:
Kevin Froman 2018-08-28 20:09:27 -05:00
parent c907558dd1
commit c0c0f838b6
6 changed files with 33 additions and 12 deletions

3
.gitmodules vendored
View File

@ -1,3 +0,0 @@
[submodule "onionr/bitpeer"]
path = onionr/bitpeer
url = https://github.com/beardog108/bitpeer.py

View File

@ -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())

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/>.
'''
import onionrblockapi, logger
class OnionrUser:
def __init__(self, coreInst, publicKey):
self.trust = 0
@ -58,4 +59,15 @@ class OnionrUser:
def forwardDecrypt(self, encrypted):
return
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)

View File

@ -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

View File

@ -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):

View File

@ -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()