Solved new address creations issues

This commit is contained in:
jai.s 2019-10-09 18:21:29 +05:30
parent c813f679ae
commit 95990d8def
No known key found for this signature in database
GPG Key ID: 360CFA25EFC67D12
11 changed files with 28 additions and 50 deletions

View File

@ -158,7 +158,7 @@ def encodeAddress(version, stream, ripe):
raise Exception( raise Exception(
'Programming error in encodeAddress: The length of' 'Programming error in encodeAddress: The length of'
' a given ripe hash was not 20.') ' a given ripe hash was not 20.')
ripe = ripe.lstrip('\x00') ripe = ripe.lstrip('\x00'.encode('utf-8'))
storedBinaryData = encodeVarint(version) + encodeVarint(stream) + ripe storedBinaryData = encodeVarint(version) + encodeVarint(stream) + ripe
@ -264,7 +264,8 @@ def decodeAddress(address):
return 'ripetoolong', 0, 0, '' return 'ripetoolong', 0, 0, ''
elif len(embeddedRipeData) < 4: elif len(embeddedRipeData) < 4:
return 'ripetooshort', 0, 0, '' return 'ripetooshort', 0, 0, ''
x00string = '\x00' * (20 - len(embeddedRipeData)) x00string = '\x00'.encode('utf-8') * (20 - len(embeddedRipeData))
return status, addressVersionNumber, streamNumber, \ return status, addressVersionNumber, streamNumber, \
x00string + embeddedRipeData x00string + embeddedRipeData

View File

@ -334,7 +334,6 @@ NavigationLayout:
BoxLayout: BoxLayout:
AnchorLayout: AnchorLayout:
MDRaisedButton: MDRaisedButton:
size_hint: .6, .35
height: dp(40) height: dp(40)
MDLabel: MDLabel:
font_style: 'H4' font_style: 'H4'
@ -383,7 +382,6 @@ NavigationLayout:
txt_input: txt_input txt_input: txt_input
rv: rv rv: rv
size : (890, 60) size : (890, 60)
size_hint: 1,1
MyTextInput: MyTextInput:
id: txt_input id: txt_input
size_hint_y: None size_hint_y: None
@ -414,7 +412,6 @@ NavigationLayout:
spacing:50 spacing:50
AnchorLayout: AnchorLayout:
MDRaisedButton: MDRaisedButton:
size_hint: 1, None
height: dp(40) height: dp(40)
on_press: root.reset_composer() on_press: root.reset_composer()
MDLabel: MDLabel:
@ -512,7 +509,6 @@ NavigationLayout:
BoxLayout: BoxLayout:
AnchorLayout: AnchorLayout:
MDRaisedButton: MDRaisedButton:
size_hint: .5, .35
height: dp(40) height: dp(40)
on_press: app.root.ids.scr_mngr.current = 'random' on_press: app.root.ids.scr_mngr.current = 'random'
MDLabel: MDLabel:
@ -556,7 +552,6 @@ NavigationLayout:
BoxLayout: BoxLayout:
AnchorLayout: AnchorLayout:
MDRaisedButton: MDRaisedButton:
size_hint: .5, None
height: dp(40) height: dp(40)
on_release: root.generateaddress(app) on_release: root.generateaddress(app)
opposite_colors: True opposite_colors: True
@ -586,7 +581,6 @@ NavigationLayout:
BoxLayout: BoxLayout:
AnchorLayout: AnchorLayout:
MDRaisedButton: MDRaisedButton:
size_hint: .6, .55
height: dp(40) height: dp(40)
MDLabel: MDLabel:
font_style: 'H4' font_style: 'H4'
@ -599,7 +593,6 @@ NavigationLayout:
BoxLayout: BoxLayout:
AnchorLayout: AnchorLayout:
MDRaisedButton: MDRaisedButton:
size_hint: .6, .55
height: dp(40) height: dp(40)
MDLabel: MDLabel:
font_style: 'H4' font_style: 'H4'
@ -612,7 +605,6 @@ NavigationLayout:
BoxLayout: BoxLayout:
AnchorLayout: AnchorLayout:
MDRaisedButton: MDRaisedButton:
size_hint: .6, .55
height: dp(40) height: dp(40)
MDLabel: MDLabel:
font_style: 'H4' font_style: 'H4'
@ -633,7 +625,6 @@ NavigationLayout:
BoxLayout: BoxLayout:
MDCheckbox: MDCheckbox:
id: chkbox id: chkbox
size_hint: None, None
size: dp(48), dp(64) size: dp(48), dp(64)
active: True active: True
MDLabel: MDLabel:
@ -718,7 +709,6 @@ NavigationLayout:
Rectangle: Rectangle:
pos: self.pos pos: self.pos
size: self.size size: self.size
size_hint: 1, None
height: dp(40) height: dp(40)
on_press: root.get_available_credits(self) on_press: root.get_available_credits(self)
MDLabel: MDLabel:
@ -763,7 +753,6 @@ NavigationLayout:
Rectangle: Rectangle:
pos: self.pos pos: self.pos
size: self.size size: self.size
size_hint: 1, None
height: dp(40) height: dp(40)
MDLabel: MDLabel:
font_style: 'H4' font_style: 'H4'
@ -807,7 +796,6 @@ NavigationLayout:
Rectangle: Rectangle:
pos: self.pos pos: self.pos
size: self.size size: self.size
size_hint: 1, None
height: dp(40) height: dp(40)
MDLabel: MDLabel:
font_style: 'H4' font_style: 'H4'
@ -819,7 +807,6 @@ NavigationLayout:
<GrashofPopup>: <GrashofPopup>:
id: popup id: popup
size_hint : (None,None)
height: 2*(label.height + address.height) + 10 height: 2*(label.height + address.height) + 10
width :app.window_size[0] - app.window_size[0]/10 width :app.window_size[0] - app.window_size[0]/10
title: 'add contact\'s' title: 'add contact\'s'
@ -852,7 +839,6 @@ NavigationLayout:
orientation: 'horizontal' orientation: 'horizontal'
MDRaisedButton: MDRaisedButton:
id: save_addr id: save_addr
size_hint: 1.5, None
height: dp(40) height: dp(40)
on_release: on_release:
root.savecontact() root.savecontact()
@ -863,7 +849,6 @@ NavigationLayout:
color: (1,1,1,1) color: (1,1,1,1)
halign: 'center' halign: 'center'
MDRaisedButton: MDRaisedButton:
size_hint: 1.5, None
height: dp(40) height: dp(40)
on_press: root.dismiss() on_press: root.dismiss()
on_press: root.close_pop() on_press: root.close_pop()
@ -874,7 +859,6 @@ NavigationLayout:
color: (1,1,1,1) color: (1,1,1,1)
halign: 'center' halign: 'center'
MDRaisedButton: MDRaisedButton:
size_hint: 2, None
height: dp(40) height: dp(40)
MDLabel: MDLabel:
font_style: 'H4' font_style: 'H4'
@ -965,7 +949,6 @@ NavigationLayout:
<MyaddDetailPopup>: <MyaddDetailPopup>:
id: myadd_popup id: myadd_popup
size_hint : (None,None)
height: 4.5*(myaddr_label.height+ my_add_btn.children[0].height) height: 4.5*(myaddr_label.height+ my_add_btn.children[0].height)
width :app.window_size[0] - app.window_size[0]/10 width :app.window_size[0] - app.window_size[0]/10
background: './images/popup.jpeg' background: './images/popup.jpeg'
@ -1010,7 +993,6 @@ NavigationLayout:
spacing:5 spacing:5
orientation: 'horizontal' orientation: 'horizontal'
MDRaisedButton: MDRaisedButton:
size_hint: 2, None
height: dp(40) height: dp(40)
on_press: root.send_message_from() on_press: root.send_message_from()
MDLabel: MDLabel:
@ -1020,7 +1002,6 @@ NavigationLayout:
color: (1,1,1,1) color: (1,1,1,1)
halign: 'center' halign: 'center'
MDRaisedButton: MDRaisedButton:
size_hint: 1.5, None
height: dp(40) height: dp(40)
on_press: root.dismiss() on_press: root.dismiss()
on_press: app.root.ids.scr_mngr.current = 'showqrcode' on_press: app.root.ids.scr_mngr.current = 'showqrcode'
@ -1032,7 +1013,6 @@ NavigationLayout:
color: (1,1,1,1) color: (1,1,1,1)
halign: 'center' halign: 'center'
MDRaisedButton: MDRaisedButton:
size_hint: 1.5, None
height: dp(40) height: dp(40)
on_press: root.dismiss() on_press: root.dismiss()
on_press: root.close_pop() on_press: root.close_pop()
@ -1045,7 +1025,6 @@ NavigationLayout:
<AddbookDetailPopup>: <AddbookDetailPopup>:
id: addbook_popup id: addbook_popup
size_hint : (None,None)
height: 4*(add_label.height) height: 4*(add_label.height)
width :app.window_size[0] - app.window_size[0]/10 width :app.window_size[0] - app.window_size[0]/10
background: './images/popup.jpeg' background: './images/popup.jpeg'
@ -1092,7 +1071,6 @@ NavigationLayout:
spacing:5 spacing:5
orientation: 'horizontal' orientation: 'horizontal'
MDRaisedButton: MDRaisedButton:
size_hint: 2, None
height: dp(40) height: dp(40)
on_press: root.send_message_to() on_press: root.send_message_to()
MDLabel: MDLabel:
@ -1102,7 +1080,6 @@ NavigationLayout:
color: (1,1,1,1) color: (1,1,1,1)
halign: 'center' halign: 'center'
MDRaisedButton: MDRaisedButton:
size_hint: 1.5, None
height: dp(40) height: dp(40)
font_size: '10sp' font_size: '10sp'
on_press: root.update_addbook_label(root.address) on_press: root.update_addbook_label(root.address)
@ -1113,7 +1090,6 @@ NavigationLayout:
color: (1,1,1,1) color: (1,1,1,1)
halign: 'center' halign: 'center'
MDRaisedButton: MDRaisedButton:
size_hint: 1.5, None
height: dp(40) height: dp(40)
on_press: root.dismiss() on_press: root.dismiss()
on_press: root.close_pop() on_press: root.close_pop()

View File

@ -29,7 +29,6 @@ class addressGenerator(StoppableThread):
super(addressGenerator, self).stopThread() super(addressGenerator, self).stopThread()
def run(self): def run(self):
while state.shutdown == 0: while state.shutdown == 0:
queueValue = queues.addressGeneratorQueue.get() queueValue = queues.addressGeneratorQueue.get()
nonceTrialsPerByte = 0 nonceTrialsPerByte = 0
@ -134,7 +133,7 @@ class addressGenerator(StoppableThread):
ripe = RIPEMD160Hash(sha.digest()).digest() ripe = RIPEMD160Hash(sha.digest()).digest()
if ( if (
ripe[:numberOfNullBytesDemandedOnFrontOfRipeHash] == ripe[:numberOfNullBytesDemandedOnFrontOfRipeHash] ==
'\x00' * numberOfNullBytesDemandedOnFrontOfRipeHash '\x00'.encode('utf-8') * numberOfNullBytesDemandedOnFrontOfRipeHash
): ):
break break
logger.info( logger.info(
@ -151,19 +150,20 @@ class addressGenerator(StoppableThread):
# The user must have a pretty fast computer. # The user must have a pretty fast computer.
# time.time() - startTime equaled zero. # time.time() - startTime equaled zero.
pass pass
address = encodeAddress( address = encodeAddress(
addressVersionNumber, streamNumber, ripe) addressVersionNumber, streamNumber, ripe)
# An excellent way for us to store our keys # An excellent way for us to store our keys
# is in Wallet Import Format. Let us convert now. # is in Wallet Import Format. Let us convert now.
# https://en.bitcoin.it/wiki/Wallet_import_format # https://en.bitcoin.it/wiki/Wallet_import_format
privSigningKey = '\x80' + potentialPrivSigningKey privSigningKey = '\x80'.encode('utf-8') + potentialPrivSigningKey
checksum = hashlib.sha256(hashlib.sha256( checksum = hashlib.sha256(hashlib.sha256(
privSigningKey).digest()).digest()[0:4] privSigningKey).digest()).digest()[0:4]
privSigningKeyWIF = arithmetic.changebase( privSigningKeyWIF = arithmetic.changebase(
privSigningKey + checksum, 256, 58) privSigningKey + checksum, 256, 58)
privEncryptionKey = '\x80' + potentialPrivEncryptionKey privEncryptionKey = '\x80'.encode('utf-8') + potentialPrivEncryptionKey
checksum = hashlib.sha256(hashlib.sha256( checksum = hashlib.sha256(hashlib.sha256(
privEncryptionKey).digest()).digest()[0:4] privEncryptionKey).digest()).digest()[0:4]
privEncryptionKeyWIF = arithmetic.changebase( privEncryptionKeyWIF = arithmetic.changebase(

View File

@ -143,8 +143,8 @@ class singleCleaner(StoppableThread):
# inv/object tracking # inv/object tracking
for connection in \ for connection in \
BMConnectionPool().inboundConnections.values() + \ list(BMConnectionPool().inboundConnections.values()) + \
BMConnectionPool().outboundConnections.values(): list(BMConnectionPool().outboundConnections.values()):
connection.clean() connection.clean()
# discovery tracking # discovery tracking

View File

@ -86,7 +86,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
"""Process incoming header""" """Process incoming header"""
self.magic, self.command, self.payloadLength, self.checksum = \ self.magic, self.command, self.payloadLength, self.checksum = \
protocol.Header.unpack(self.read_buf[:protocol.Header.size]) protocol.Header.unpack(self.read_buf[:protocol.Header.size])
self.command = self.command.rstrip('\x00') self.command = self.command.rstrip('\x00'.encode('utf-8'))
if self.magic != 0xE9BEB4D9: if self.magic != 0xE9BEB4D9:
# skip 1 byte in order to sync # skip 1 byte in order to sync
self.set_state("bm_header", length=1) self.set_state("bm_header", length=1)

View File

@ -328,8 +328,8 @@ class BMConnectionPool(object):
reaper = [] reaper = []
for i in ( for i in (
self.inboundConnections.values() + list(self.inboundConnections.values()) +
self.outboundConnections.values() list(self.outboundConnections.values())
): ):
minTx = time.time() - 20 minTx = time.time() - 20
if i.fullyEstablished: if i.fullyEstablished:
@ -342,10 +342,10 @@ class BMConnectionPool(object):
time.time() - i.lastTx) time.time() - i.lastTx)
i.set_state("close") i.set_state("close")
for i in ( for i in (
self.inboundConnections.values() + list(self.inboundConnections.values()) +
self.outboundConnections.values() + list(self.outboundConnections.values()) +
self.listeningSockets.values() + list(self.listeningSockets.values()) +
self.udpSockets.values() list(self.udpSockets.values())
): ):
if not (i.accepting or i.connecting or i.connected): if not (i.accepting or i.connecting or i.connected):
reaper.append(i) reaper.append(i)

View File

@ -7,7 +7,7 @@ from random import choice, sample, expovariate
from threading import RLock from threading import RLock
from time import time from time import time
import network.connectionpool from network import connectionpool
import state import state
from debug import logging from debug import logging
from queues import invQueue from queues import invQueue
@ -182,8 +182,8 @@ class Dandelion(): # pylint: disable=old-style-class
try: try:
# random two connections # random two connections
self.stem = sample( self.stem = sample(
connectionpool.BMConnectionPool( list(connectionpool.BMConnectionPool(
).outboundConnections.values(), MAX_STEMS) ).outboundConnections.values()), MAX_STEMS)
# not enough stems available # not enough stems available
except ValueError: except ValueError:
self.stem = connectionpool.BMConnectionPool( self.stem = connectionpool.BMConnectionPool(

View File

@ -362,7 +362,7 @@ class TCPServer(AdvancedDispatcher):
"""TCP connection server for Bitmessage protocol""" """TCP connection server for Bitmessage protocol"""
def __init__(self, host='127.0.0.1', port=8444): def __init__(self, host='127.0.0.1', port=8444):
if not hasattr(self, '_map'): if not '_map' in dir(self):
AdvancedDispatcher.__init__(self) AdvancedDispatcher.__init__(self)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.set_reuse_addr() self.set_reuse_addr()

View File

@ -94,9 +94,9 @@ def isBitSetWithinBitfield(fourByteString, n):
def encodeHost(host): def encodeHost(host):
"""Encode a given host to be used in low-level socket operations""" """Encode a given host to be used in low-level socket operations"""
if host.find('.onion') > -1: if host.find('.onion') > -1:
return '\xfd\x87\xd8\x7e\xeb\x43' + base64.b32decode(host.split(".")[0], True) return '\xfd\x87\xd8\x7e\xeb\x43'.encode('utf-8') + base64.b32decode(host.split(".")[0], True)
elif host.find(':') == -1: elif host.find(':') == -1:
return '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF' + \ return '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF'.encode('utf-8') + \
socket.inet_aton(host) socket.inet_aton(host)
return socket.inet_pton(socket.AF_INET6, host) return socket.inet_pton(socket.AF_INET6, host)

View File

@ -39,11 +39,13 @@ def get_code_string(base):
def encode(val, base, minlen=0): def encode(val, base, minlen=0):
code_string = get_code_string(base) code_string = get_code_string(base)
result = "" result = ''
result = str.encode(result) # result = str.encode(result)
count = 0 count = 0
while val > 0: while val > 0:
count += 1 count += 1
print(f'code_string[int(val) % base:int(val) % base + 1] -{code_string[int(val) % base:int(val) % base + 1]}')
print(f'result-{result}')
result = code_string[int(val) % base:int(val) % base + 1] + result result = code_string[int(val) % base:int(val) % base + 1] + result
val = int(val / base) val = int(val / base)
if len(result) < minlen: if len(result) < minlen:
@ -53,13 +55,12 @@ def encode(val, base, minlen=0):
def decode(string, base): def decode(string, base):
code_string = get_code_string(base) code_string = get_code_string(base)
string.decode()
result = 0 result = 0
if base == 16: if base == 16:
string = string.lower() string = string.lower()
while string: while string:
result *= base result *= base
result += code_string.find(string.decode()[0]) result += code_string.find(string[0])
string = string[1:] string = string[1:]
return result return result

View File

@ -125,7 +125,7 @@ def reloadMyAddressHashes():
keyfileSecure = checkSensitiveFilePermissions(state.appdata + 'keys.dat') keyfileSecure = checkSensitiveFilePermissions(state.appdata + 'keys.dat')
hasEnabledKeys = False hasEnabledKeys = False
for addressInKeysFile in BMConfigParser().addresses(): for addressInKeysFile in BMConfigParser().addresses():
isEnabled = BMConfigParser().getboolean(addressInKeysFile, 'enabled') isEnabled = BMConfigParser().safeGet(addressInKeysFile, 'enabled')
if isEnabled: if isEnabled:
hasEnabledKeys = True hasEnabledKeys = True
# status # status