From 2b3034a42fc0e8eaa06af444e8c3709fe4d33832 Mon Sep 17 00:00:00 2001 From: Lee Miller Date: Mon, 27 May 2024 19:10:21 +0300 Subject: [PATCH 01/11] Add lines for local testing into the buildbot docker files --- .buildbot/appimage/Dockerfile | 2 ++ .buildbot/tox-bionic/Dockerfile | 4 ++++ .buildbot/tox-focal/Dockerfile | 2 ++ .buildbot/tox-jammy/Dockerfile | 4 ++++ 4 files changed, 12 insertions(+) diff --git a/.buildbot/appimage/Dockerfile b/.buildbot/appimage/Dockerfile index 6c2b87d5..c4dde327 100644 --- a/.buildbot/appimage/Dockerfile +++ b/.buildbot/appimage/Dockerfile @@ -24,3 +24,5 @@ RUN wget -qO appimage-builder-x86_64.AppImage \ https://github.com/AppImageCrafters/appimage-builder/releases/download/v1.1.0/appimage-builder-1.1.0-x86_64.AppImage ADD . . + +CMD .buildbot/tox-bionic/build.sh diff --git a/.buildbot/tox-bionic/Dockerfile b/.buildbot/tox-bionic/Dockerfile index 5cc36b7f..1acf58dc 100644 --- a/.buildbot/tox-bionic/Dockerfile +++ b/.buildbot/tox-bionic/Dockerfile @@ -20,3 +20,7 @@ RUN python3.8 -m pip install --upgrade pip tox virtualenv ENV LANG en_US.UTF-8 ENV LANGUAGE en_US:en ENV LC_ALL en_US.UTF-8 + +ADD . . + +CMD .buildbot/tox-bionic/test.sh diff --git a/.buildbot/tox-focal/Dockerfile b/.buildbot/tox-focal/Dockerfile index c2ba0ffc..fecc0819 100644 --- a/.buildbot/tox-focal/Dockerfile +++ b/.buildbot/tox-focal/Dockerfile @@ -13,3 +13,5 @@ RUN apt-get install -yq --no-install-suggests --no-install-recommends \ RUN python3.9 -m pip install --upgrade pip tox virtualenv ADD . . + +CMD .buildbot/tox-focal/test.sh diff --git a/.buildbot/tox-jammy/Dockerfile b/.buildbot/tox-jammy/Dockerfile index 8ca63aa0..b15c3b8f 100644 --- a/.buildbot/tox-jammy/Dockerfile +++ b/.buildbot/tox-jammy/Dockerfile @@ -10,3 +10,7 @@ RUN apt-get install -yq --no-install-suggests --no-install-recommends \ python3-dev python3-pip language-pack-en qt5dxcb-plugin tor xvfb RUN pip install tox + +ADD . . + +CMD .buildbot/tox-jammy/test.sh From b68beaab206b23a441996367e6b908a963bde47b Mon Sep 17 00:00:00 2001 From: Lee Miller Date: Sun, 2 Jun 2024 04:16:22 +0300 Subject: [PATCH 02/11] Update and rename the script for testing with docker --- docker-test.sh | 11 +++++++++++ run-tests-in-docker.sh | 13 ------------- 2 files changed, 11 insertions(+), 13 deletions(-) create mode 100755 docker-test.sh delete mode 100755 run-tests-in-docker.sh diff --git a/docker-test.sh b/docker-test.sh new file mode 100755 index 00000000..18b6569a --- /dev/null +++ b/docker-test.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +DOCKERFILE=.buildbot/tox-bionic/Dockerfile + +docker build -t pybm/tox -f $DOCKERFILE . + +if [ $? -gt 0 ]; then + docker build --no-cache -t pybm/tox -f $DOCKERFILE . +fi + +docker run --rm -it pybm/tox diff --git a/run-tests-in-docker.sh b/run-tests-in-docker.sh deleted file mode 100755 index 174cb754..00000000 --- a/run-tests-in-docker.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -DOCKERFILE=packages/docker/Dockerfile.bionic - -# explicitly mark appimage stage because it builds in any case -docker build --target appimage -t pybm/appimage -f $DOCKERFILE . - -if [ $? -gt 0 ]; then - docker build --no-cache --target appimage -t pybm/appimage -f $DOCKERFILE . -fi - -docker build --target tox -t pybm/tox -f $DOCKERFILE . -docker run --rm -t pybm/tox From 65d2a37cb22cfc37fa9561d90a3de845f54c41f9 Mon Sep 17 00:00:00 2001 From: Lee Miller Date: Sun, 2 Jun 2024 04:57:10 +0300 Subject: [PATCH 03/11] Extend environment markers for PyQt5 - doesn't install on arm --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 6f4a22fb..c787d2dd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ coverage psutil pycryptodome -PyQt5;python_version>="3.7" +PyQt5;python_version>="3.7" and platform_machine=="x86_64" mock;python_version<="2.7" python_prctl;platform_system=="Linux" six From 27e566140d1c119856d84235ea20142af3769e42 Mon Sep 17 00:00:00 2001 From: Lee Miller Date: Wed, 3 Jul 2024 01:25:47 +0300 Subject: [PATCH 04/11] Add a check for default in TestProtocol.test_check_local() --- src/tests/test_protocol.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tests/test_protocol.py b/src/tests/test_protocol.py index e3137b25..69e1e82f 100644 --- a/src/tests/test_protocol.py +++ b/src/tests/test_protocol.py @@ -63,6 +63,8 @@ class TestProtocol(TestSocketInet): def test_check_local(self): """Check the logic of TCPConnection.local""" + self.assertFalse( + protocol.checkIPAddress(protocol.encodeHost('127.0.0.1'))) self.assertTrue( protocol.checkIPAddress(protocol.encodeHost('127.0.0.1'), True)) self.assertTrue( From 6578b5b9250224872612aa338c20622056dcba68 Mon Sep 17 00:00:00 2001 From: anand k Date: Sun, 23 Jun 2024 08:43:51 +0530 Subject: [PATCH 05/11] Moved multiqueue to network module --- src/{ => network}/multiqueue.py | 9 ++------- src/queues.py | 7 +++---- src/tests/test_multiqueue.py | 2 +- 3 files changed, 6 insertions(+), 12 deletions(-) rename src/{ => network}/multiqueue.py (89%) diff --git a/src/multiqueue.py b/src/network/multiqueue.py similarity index 89% rename from src/multiqueue.py rename to src/network/multiqueue.py index 88b6a4dd..3fad4e34 100644 --- a/src/multiqueue.py +++ b/src/network/multiqueue.py @@ -2,16 +2,11 @@ A queue with multiple internal subqueues. Elements are added into a random subqueue, and retrieval rotates """ - +import random from collections import deque from six.moves import queue -try: - import helper_random -except ImportError: - from . import helper_random - class MultiQueue(queue.Queue): """A base queue class""" @@ -38,7 +33,7 @@ class MultiQueue(queue.Queue): # Put a new item in the queue def _put(self, item): # self.queue.append(item) - self.queues[helper_random.randomrandrange(self.queueCount)].append( + self.queues[random.randrange(self.queueCount)].append( # nosec B311 (item)) # Get an item from the queue diff --git a/src/queues.py b/src/queues.py index 4a9b98d2..a95e8e46 100644 --- a/src/queues.py +++ b/src/queues.py @@ -5,10 +5,9 @@ import time from six.moves import queue -try: - from multiqueue import MultiQueue -except ImportError: - from .multiqueue import MultiQueue + +from network.multiqueue import MultiQueue + class ObjectProcessorQueue(queue.Queue): diff --git a/src/tests/test_multiqueue.py b/src/tests/test_multiqueue.py index 87149d56..4b041f1c 100644 --- a/src/tests/test_multiqueue.py +++ b/src/tests/test_multiqueue.py @@ -1,7 +1,7 @@ """Test cases for multiqueue""" import unittest -from pybitmessage.multiqueue import MultiQueue +from pybitmessage.network.multiqueue import MultiQueue class TestMultiQueue(unittest.TestCase): From 5cd4ecb4371741a94c0f7831dbed39834cfd920b Mon Sep 17 00:00:00 2001 From: anand k Date: Sun, 23 Jun 2024 10:53:48 +0530 Subject: [PATCH 06/11] Moved invQueue to network module --- src/api.py | 6 +++--- src/class_objectProcessor.py | 4 ++-- src/class_singleWorker.py | 16 ++++++++-------- src/network/__init__.py | 5 ++++- src/network/bmproto.py | 4 ++-- src/network/invthread.py | 3 +-- src/network/tcp.py | 4 ++-- src/queues.py | 1 - 8 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/api.py b/src/api.py index a4445569..f9bf55de 100644 --- a/src/api.py +++ b/src/api.py @@ -100,7 +100,7 @@ try: except ImportError: connectionpool = None -from network import stats, StoppableThread +from network import stats, StoppableThread, invQueue from version import softwareVersion try: # TODO: write tests for XML vulnerabilities @@ -1346,7 +1346,7 @@ class BMRPCDispatcher(object): logger.info( 'Broadcasting inv for msg(API disseminatePreEncryptedMsg' ' command): %s', hexlify(inventoryHash)) - queues.invQueue.put((toStreamNumber, inventoryHash)) + invQueue.put((toStreamNumber, inventoryHash)) return hexlify(inventoryHash).decode() @command('trashSentMessageByAckData') @@ -1401,7 +1401,7 @@ class BMRPCDispatcher(object): logger.info( 'broadcasting inv within API command disseminatePubkey with' ' hash: %s', hexlify(inventoryHash)) - queues.invQueue.put((pubkeyStreamNumber, inventoryHash)) + invQueue.put((pubkeyStreamNumber, inventoryHash)) @command( 'getMessageDataByDestinationHash', 'getMessageDataByDestinationTag') diff --git a/src/class_objectProcessor.py b/src/class_objectProcessor.py index 469ccbfa..974631cb 100644 --- a/src/class_objectProcessor.py +++ b/src/class_objectProcessor.py @@ -30,7 +30,7 @@ from addresses import ( from bmconfigparser import config from helper_sql import ( sql_ready, sql_timeout, SqlBulkExecute, sqlExecute, sqlQuery) -from network import knownnodes +from network import knownnodes, invQueue from network.node import Peer from tr import _translate @@ -729,7 +729,7 @@ class objectProcessor(threading.Thread): inventoryHash = highlevelcrypto.calculateInventoryHash(ackPayload) state.Inventory[inventoryHash] = ( objectType, toStreamNumber, ackPayload, expiresTime, b'') - queues.invQueue.put((toStreamNumber, inventoryHash)) + invQueue.put((toStreamNumber, inventoryHash)) # Display timing data timeRequiredToAttemptToDecryptMessage = time.time( diff --git a/src/class_singleWorker.py b/src/class_singleWorker.py index f2821f65..f79d9240 100644 --- a/src/class_singleWorker.py +++ b/src/class_singleWorker.py @@ -28,7 +28,7 @@ import tr from addresses import decodeAddress, decodeVarint, encodeVarint from bmconfigparser import config from helper_sql import sqlExecute, sqlQuery -from network import knownnodes, StoppableThread +from network import knownnodes, StoppableThread, invQueue from six.moves import configparser, queue @@ -293,7 +293,7 @@ class singleWorker(StoppableThread): self.logger.info( 'broadcasting inv with hash: %s', hexlify(inventoryHash)) - queues.invQueue.put((streamNumber, inventoryHash)) + invQueue.put((streamNumber, inventoryHash)) queues.UISignalQueue.put(('updateStatusBar', '')) try: config.set( @@ -381,7 +381,7 @@ class singleWorker(StoppableThread): self.logger.info( 'broadcasting inv with hash: %s', hexlify(inventoryHash)) - queues.invQueue.put((streamNumber, inventoryHash)) + invQueue.put((streamNumber, inventoryHash)) queues.UISignalQueue.put(('updateStatusBar', '')) try: config.set( @@ -474,7 +474,7 @@ class singleWorker(StoppableThread): self.logger.info( 'broadcasting inv with hash: %s', hexlify(inventoryHash)) - queues.invQueue.put((streamNumber, inventoryHash)) + invQueue.put((streamNumber, inventoryHash)) queues.UISignalQueue.put(('updateStatusBar', '')) try: config.set( @@ -522,7 +522,7 @@ class singleWorker(StoppableThread): self.logger.info( 'sending inv (within sendOnionPeerObj function) for object: %s', hexlify(inventoryHash)) - queues.invQueue.put((streamNumber, inventoryHash)) + invQueue.put((streamNumber, inventoryHash)) def sendBroadcast(self): """Send a broadcast-type object (assemble the object, perform PoW and put it to the inv announcement queue)""" @@ -690,7 +690,7 @@ class singleWorker(StoppableThread): ' for object: %s', hexlify(inventoryHash) ) - queues.invQueue.put((streamNumber, inventoryHash)) + invQueue.put((streamNumber, inventoryHash)) queues.UISignalQueue.put(( 'updateSentItemStatusByAckdata', ( @@ -1326,7 +1326,7 @@ class singleWorker(StoppableThread): 'Broadcasting inv for my msg(within sendmsg function): %s', hexlify(inventoryHash) ) - queues.invQueue.put((toStreamNumber, inventoryHash)) + invQueue.put((toStreamNumber, inventoryHash)) # Update the sent message in the sent table with the # necessary information. @@ -1459,7 +1459,7 @@ class singleWorker(StoppableThread): state.Inventory[inventoryHash] = ( objectType, streamNumber, payload, embeddedTime, '') self.logger.info('sending inv (for the getpubkey message)') - queues.invQueue.put((streamNumber, inventoryHash)) + invQueue.put((streamNumber, inventoryHash)) # wait 10% past expiration sleeptill = int(time.time() + TTL * 1.1) diff --git a/src/network/__init__.py b/src/network/__init__.py index 42e9d035..642842df 100644 --- a/src/network/__init__.py +++ b/src/network/__init__.py @@ -3,15 +3,18 @@ Network subsystem package """ from .dandelion import Dandelion from .threads import StoppableThread +from .multiqueue import MultiQueue dandelion_ins = Dandelion() +# network queues +invQueue = MultiQueue() + __all__ = ["StoppableThread"] def start(config, state): """Start network threads""" - import state from .announcethread import AnnounceThread import connectionpool # pylint: disable=relative-import from .addrthread import AddrThread diff --git a/src/network/bmproto.py b/src/network/bmproto.py index 797dab5e..2b8dff79 100644 --- a/src/network/bmproto.py +++ b/src/network/bmproto.py @@ -17,7 +17,7 @@ import protocol import state import connectionpool from bmconfigparser import config -from queues import invQueue, objectProcessorQueue, portCheckerQueue +from queues import objectProcessorQueue, portCheckerQueue from randomtrackingdict import RandomTrackingDict from network.advanceddispatcher import AdvancedDispatcher from network.bmobject import ( @@ -26,7 +26,7 @@ from network.bmobject import ( BMObjectUnwantedStreamError ) from network.proxy import ProxyError -from network import dandelion_ins +from network import dandelion_ins, invQueue from node import Node, Peer from objectracker import ObjectTracker, missingObjects diff --git a/src/network/invthread.py b/src/network/invthread.py index 0b79710a..503eefa1 100644 --- a/src/network/invthread.py +++ b/src/network/invthread.py @@ -9,8 +9,7 @@ import addresses import protocol import state import connectionpool -from network import dandelion_ins -from queues import invQueue +from network import dandelion_ins, invQueue from threads import StoppableThread diff --git a/src/network/tcp.py b/src/network/tcp.py index f2dce07d..ec29c9ae 100644 --- a/src/network/tcp.py +++ b/src/network/tcp.py @@ -17,8 +17,8 @@ import state import connectionpool from bmconfigparser import config from highlevelcrypto import randomBytes -from network import dandelion_ins -from queues import invQueue, receiveDataQueue, UISignalQueue +from network import dandelion_ins, invQueue +from queues import receiveDataQueue, UISignalQueue from tr import _translate import asyncore_pollchoose as asyncore diff --git a/src/queues.py b/src/queues.py index a95e8e46..8e46ccf0 100644 --- a/src/queues.py +++ b/src/queues.py @@ -43,7 +43,6 @@ addressGeneratorQueue = queue.Queue() #: `.network.ReceiveQueueThread` instances dump objects they hear #: on the network into this queue to be processed. objectProcessorQueue = ObjectProcessorQueue() -invQueue = MultiQueue() addrQueue = MultiQueue() portCheckerQueue = queue.Queue() receiveDataQueue = queue.Queue() From 49e89ecdf20586c15349644d271e9fa6fdab4deb Mon Sep 17 00:00:00 2001 From: anand k Date: Sun, 23 Jun 2024 10:57:57 +0530 Subject: [PATCH 07/11] Moved addrQueue to network module --- src/network/__init__.py | 1 + src/network/addrthread.py | 2 +- src/queues.py | 5 ----- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/network/__init__.py b/src/network/__init__.py index 642842df..073c8435 100644 --- a/src/network/__init__.py +++ b/src/network/__init__.py @@ -9,6 +9,7 @@ dandelion_ins = Dandelion() # network queues invQueue = MultiQueue() +addrQueue = MultiQueue() __all__ = ["StoppableThread"] diff --git a/src/network/addrthread.py b/src/network/addrthread.py index a77e609c..81e44506 100644 --- a/src/network/addrthread.py +++ b/src/network/addrthread.py @@ -7,7 +7,7 @@ from six.moves import queue # magic imports! import connectionpool from protocol import assembleAddrMessage -from queues import addrQueue # FIXME: init with queue +from network import addrQueue # FIXME: init with queue from threads import StoppableThread diff --git a/src/queues.py b/src/queues.py index 8e46ccf0..18eb6dfa 100644 --- a/src/queues.py +++ b/src/queues.py @@ -6,10 +6,6 @@ import time from six.moves import queue -from network.multiqueue import MultiQueue - - - class ObjectProcessorQueue(queue.Queue): """Special queue class using lock for `.threads.objectProcessor`""" @@ -43,7 +39,6 @@ addressGeneratorQueue = queue.Queue() #: `.network.ReceiveQueueThread` instances dump objects they hear #: on the network into this queue to be processed. objectProcessorQueue = ObjectProcessorQueue() -addrQueue = MultiQueue() portCheckerQueue = queue.Queue() receiveDataQueue = queue.Queue() #: The address generator thread uses this queue to get information back From 5b537eabe1a05a89ca49831306704264184d853d Mon Sep 17 00:00:00 2001 From: anand k Date: Mon, 24 Jun 2024 12:10:44 +0530 Subject: [PATCH 08/11] Moved portCheckerQueue and receiveDataQueue to network module --- src/network/__init__.py | 3 +++ src/network/bmproto.py | 4 ++-- src/network/connectionchooser.py | 5 ++++- src/network/receivequeuethread.py | 2 +- src/network/tcp.py | 4 ++-- src/network/tls.py | 2 +- src/network/udp.py | 2 +- src/queues.py | 2 -- 8 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/network/__init__.py b/src/network/__init__.py index 073c8435..c87ad64d 100644 --- a/src/network/__init__.py +++ b/src/network/__init__.py @@ -1,6 +1,7 @@ """ Network subsystem package """ +from six.moves import queue from .dandelion import Dandelion from .threads import StoppableThread from .multiqueue import MultiQueue @@ -10,6 +11,8 @@ dandelion_ins = Dandelion() # network queues invQueue = MultiQueue() addrQueue = MultiQueue() +portCheckerQueue = queue.Queue() +receiveDataQueue = queue.Queue() __all__ = ["StoppableThread"] diff --git a/src/network/bmproto.py b/src/network/bmproto.py index 2b8dff79..e5f38bf5 100644 --- a/src/network/bmproto.py +++ b/src/network/bmproto.py @@ -17,7 +17,7 @@ import protocol import state import connectionpool from bmconfigparser import config -from queues import objectProcessorQueue, portCheckerQueue +from queues import objectProcessorQueue from randomtrackingdict import RandomTrackingDict from network.advanceddispatcher import AdvancedDispatcher from network.bmobject import ( @@ -26,7 +26,7 @@ from network.bmobject import ( BMObjectUnwantedStreamError ) from network.proxy import ProxyError -from network import dandelion_ins, invQueue +from network import dandelion_ins, invQueue, portCheckerQueue from node import Node, Peer from objectracker import ObjectTracker, missingObjects diff --git a/src/network/connectionchooser.py b/src/network/connectionchooser.py index d7062d24..e2981d51 100644 --- a/src/network/connectionchooser.py +++ b/src/network/connectionchooser.py @@ -5,11 +5,14 @@ Select which node to connect to import logging import random +from six.moves import queue + import knownnodes import protocol import state + from bmconfigparser import config -from queues import queue, portCheckerQueue +from network import portCheckerQueue logger = logging.getLogger('default') diff --git a/src/network/receivequeuethread.py b/src/network/receivequeuethread.py index 10f2acea..88d3b740 100644 --- a/src/network/receivequeuethread.py +++ b/src/network/receivequeuethread.py @@ -7,7 +7,7 @@ import socket import connectionpool from network.advanceddispatcher import UnknownStateError -from queues import receiveDataQueue +from network import receiveDataQueue from threads import StoppableThread diff --git a/src/network/tcp.py b/src/network/tcp.py index ec29c9ae..db7d6595 100644 --- a/src/network/tcp.py +++ b/src/network/tcp.py @@ -17,8 +17,8 @@ import state import connectionpool from bmconfigparser import config from highlevelcrypto import randomBytes -from network import dandelion_ins, invQueue -from queues import receiveDataQueue, UISignalQueue +from network import dandelion_ins, invQueue, receiveDataQueue +from queues import UISignalQueue from tr import _translate import asyncore_pollchoose as asyncore diff --git a/src/network/tls.py b/src/network/tls.py index a3774b44..2d5d5e1b 100644 --- a/src/network/tls.py +++ b/src/network/tls.py @@ -10,7 +10,7 @@ import sys import network.asyncore_pollchoose as asyncore import paths from network.advanceddispatcher import AdvancedDispatcher -from queues import receiveDataQueue +from network import receiveDataQueue logger = logging.getLogger('default') diff --git a/src/network/udp.py b/src/network/udp.py index b16146f9..30643d40 100644 --- a/src/network/udp.py +++ b/src/network/udp.py @@ -9,8 +9,8 @@ import time import protocol import state import connectionpool -from queues import receiveDataQueue +from network import receiveDataQueue from bmproto import BMProto from node import Peer from objectracker import ObjectTracker diff --git a/src/queues.py b/src/queues.py index 18eb6dfa..cee5ce8b 100644 --- a/src/queues.py +++ b/src/queues.py @@ -39,8 +39,6 @@ addressGeneratorQueue = queue.Queue() #: `.network.ReceiveQueueThread` instances dump objects they hear #: on the network into this queue to be processed. objectProcessorQueue = ObjectProcessorQueue() -portCheckerQueue = queue.Queue() -receiveDataQueue = queue.Queue() #: The address generator thread uses this queue to get information back #: to the API thread. apiAddressGeneratorReturnQueue = queue.Queue() From d6823a6fb1fcb72622b98e01a6203360f0e8e377 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Sun, 7 Jul 2024 20:07:26 +0800 Subject: [PATCH 09/11] Fix python3 / kivy test --- src/bitmessagekivy/tests/telenium_process.py | 7 ++++++- src/highlevelcrypto.py | 14 ++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/bitmessagekivy/tests/telenium_process.py b/src/bitmessagekivy/tests/telenium_process.py index 0a81044d..209287e2 100644 --- a/src/bitmessagekivy/tests/telenium_process.py +++ b/src/bitmessagekivy/tests/telenium_process.py @@ -7,6 +7,8 @@ import shutil import tempfile from time import time, sleep +from requests.exceptions import ChunkedEncodingError + from telenium.tests import TeleniumTestCase from telenium.client import TeleniumHttpException @@ -54,7 +56,10 @@ class TeleniumTestProcess(TeleniumTestCase): def tearDownClass(cls): """Ensures that pybitmessage stopped and removes files""" # pylint: disable=no-member - super(TeleniumTestProcess, cls).tearDownClass() + try: + super(TeleniumTestProcess, cls).tearDownClass() + except ChunkedEncodingError: + pass cleanup() def assert_wait_no_except(self, selector, timeout=-1, value='inbox'): diff --git a/src/highlevelcrypto.py b/src/highlevelcrypto.py index d59a721d..b83da2f3 100644 --- a/src/highlevelcrypto.py +++ b/src/highlevelcrypto.py @@ -11,11 +11,17 @@ import hashlib import os from binascii import hexlify -import pyelliptic -from pyelliptic import OpenSSL -from pyelliptic import arithmetic as a +try: + import pyelliptic + from fallback import RIPEMD160Hash + from pyelliptic import OpenSSL + from pyelliptic import arithmetic as a +except ImportError: + from pybitmessage import pyelliptic + from pybitmessage.fallback import RIPEMD160Hash + from pybitmessage.pyelliptic import OpenSSL + from pybitmessage.pyelliptic import arithmetic as a -from fallback import RIPEMD160Hash __all__ = [ 'decodeWalletImportFormat', 'deterministic_keys', From 759c6228c34317f9c52df725b0d327113ec999c0 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Fri, 29 Mar 2024 19:11:40 +0800 Subject: [PATCH 10/11] Android build fixes - updates requirements as per Play Store - can build aab on release --- .buildbot/android/build.sh | 15 +++++++++++++-- .buildbot/android/test.sh | 6 ++++++ packages/android/buildozer.spec | 12 +++++++----- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/.buildbot/android/build.sh b/.buildbot/android/build.sh index 10176ef3..52f563f7 100755 --- a/.buildbot/android/build.sh +++ b/.buildbot/android/build.sh @@ -2,8 +2,19 @@ export LC_ALL=en_US.UTF-8 export LANG=en_US.UTF-8 pushd packages/android -buildozer android debug || exit $? + +BUILDMODE=debug + +if [ "$BUILDBOT_JOBNAME" = "android" -a \ + "$BUILDBOT_REPOSITORY" = "https://github.com/Bitmessage/PyBitmessage" -a \ + "$BUILDBOT_BRANCH" = "v0.6" ]; then + sed -e 's/android.release_artifact *=.*/release_artifact = aab/' -i "" buildozer.spec + BUILDMODE=release +fi + +buildozer android $BUILDMODE || exit $? popd mkdir -p ../out -cp packages/android/bin/*.apk ../out +RELEASE_ARTIFACT=$(grep release_artifact packages/android/buildozer.spec |cut -d= -f2|tr -Cd 'a-z') +cp packages/android/bin/*.${RELEASE_ARTIFACT} ../out diff --git a/.buildbot/android/test.sh b/.buildbot/android/test.sh index b61fac85..65a0fe7d 100755 --- a/.buildbot/android/test.sh +++ b/.buildbot/android/test.sh @@ -1,5 +1,11 @@ #!/bin/bash +RELEASE_ARTIFACT=$(grep release_artifact packages/android/buildozer.spec |cut -d= -f2|tr -Cd 'a-z') + +if [ $RELEASE_ARTIFACT = "aab" ]; then + exit +fi + unzip -p packages/android/bin/*.apk assets/private.tar \ | tar --list -z > package.list cat package.list diff --git a/packages/android/buildozer.spec b/packages/android/buildozer.spec index c98717b4..14afa47d 100644 --- a/packages/android/buildozer.spec +++ b/packages/android/buildozer.spec @@ -1,13 +1,13 @@ [app] # (str) Title of your application -title = mockone +title = PyBitmessage Mock # (str) Package name -package.name = mock +package.name = pybitmessagemock # (str) Package domain (needed for android/ios packaging) -package.domain = org.mock +package.domain = at.bitmessage # (str) Source code where the main.py live source.dir = ../../src @@ -28,7 +28,7 @@ source.include_exts = py,png,jpg,kv,atlas,tflite,sql #source.exclude_patterns = license,images/*/*.jpg # (str) Application versioning (method 1) -version = 0.1 +version = 0.1.1 # (str) Application versioning (method 2) # version.regex = __version__ = ['"](.*)['"] @@ -92,7 +92,7 @@ fullscreen = 0 # (int) Android API to use (targetSdkVersion AND compileSdkVersion) # note: when changing, Dockerfile also needs to be changed to install corresponding build tools -android.api = 28 +android.api = 33 # (int) Minimum API required. You will need to set the android.ndk_api to be as low as this value. android.minapi = 21 @@ -243,6 +243,8 @@ android.allow_backup = True # Usage example : android.manifest_placeholders = [myCustomUrl:\"org.kivy.customurl\"] # android.manifest_placeholders = [:] +android.release_artifact = apk + # # Python for android (p4a) specific # From cf3716950f6ae5280534536dd280a1c754e53cc1 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Fri, 29 Mar 2024 19:53:08 +0800 Subject: [PATCH 11/11] Use mock for android build --- .buildbot/android/Dockerfile | 2 +- .buildbot/android/build.sh | 12 +++++++++++ packages/android/buildozer.spec | 4 ++-- src/main-android-live.py | 13 ++++++++++++ src/main.py | 36 ++++++++++++++++++++++++--------- src/pyelliptic/openssl.py | 4 ++++ 6 files changed, 59 insertions(+), 12 deletions(-) create mode 100644 src/main-android-live.py diff --git a/.buildbot/android/Dockerfile b/.buildbot/android/Dockerfile index 2d722834..faf29233 100755 --- a/.buildbot/android/Dockerfile +++ b/.buildbot/android/Dockerfile @@ -22,7 +22,7 @@ RUN apt-get -y update -qq \ RUN apt-get -y install -qq --no-install-recommends openjdk-17-jdk \ && apt-get -y autoremove -RUN pip install pip install buildozer cython virtualenv +RUN pip install buildozer cython virtualenv ENV ANDROID_NDK_HOME="${ANDROID_HOME}/android-ndk" diff --git a/.buildbot/android/build.sh b/.buildbot/android/build.sh index 52f563f7..e008218a 100755 --- a/.buildbot/android/build.sh +++ b/.buildbot/android/build.sh @@ -1,6 +1,18 @@ #!/bin/bash export LC_ALL=en_US.UTF-8 export LANG=en_US.UTF-8 + +# buildozer OOM workaround +mkdir -p ~/.gradle +echo "org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8" \ + > ~/.gradle/gradle.properties + +# workaround for symlink +rm -rf src/pybitmessage +mkdir -p src/pybitmessage +cp src/*.py src/pybitmessage +cp -r src/bitmessagekivy src/backend src/mockbm src/pybitmessage + pushd packages/android BUILDMODE=debug diff --git a/packages/android/buildozer.spec b/packages/android/buildozer.spec index 14afa47d..99393e86 100644 --- a/packages/android/buildozer.spec +++ b/packages/android/buildozer.spec @@ -13,7 +13,7 @@ package.domain = at.bitmessage source.dir = ../../src # (list) Source files to include (let empty to include all the files) -source.include_exts = py,png,jpg,kv,atlas,tflite,sql +source.include_exts = py,png,jpg,kv,atlas,tflite,sql,json # (list) List of inclusions using pattern matching #source.include_patterns = assets/*,images/*.png @@ -36,7 +36,7 @@ version = 0.1.1 # (list) Application requirements # comma separated e.g. requirements = sqlite3,kivy -requirements = python3,kivy +requirements = python3,kivy,sqlite3,kivymd==1.0.2,Pillow,opencv,kivy-garden.qrcode,qrcode,typing_extensions,libpng # (str) Custom source folders for requirements # Sets custom source for any requirements with recipes diff --git a/src/main-android-live.py b/src/main-android-live.py new file mode 100644 index 00000000..e1644436 --- /dev/null +++ b/src/main-android-live.py @@ -0,0 +1,13 @@ +"""This module is for thread start.""" +import state +import sys +from bitmessagemain import main +from termcolor import colored +print(colored('kivy is not supported at the moment for this version..', 'red')) +sys.exit() + + +if __name__ == '__main__': + state.kivy = True + print("Kivy Loading......") + main() diff --git a/src/main.py b/src/main.py index e1644436..ce042b84 100644 --- a/src/main.py +++ b/src/main.py @@ -1,13 +1,31 @@ -"""This module is for thread start.""" +# pylint: disable=unused-import, wrong-import-position, ungrouped-imports +# flake8: noqa:E401, E402 + +"""Mock kivy app with mock threads.""" + +import os +from kivy.config import Config +from mockbm import multiqueue import state -import sys -from bitmessagemain import main -from termcolor import colored -print(colored('kivy is not supported at the moment for this version..', 'red')) -sys.exit() + +from mockbm.class_addressGenerator import FakeAddressGenerator # noqa:E402 +from bitmessagekivy.mpybit import NavigateApp # noqa:E402 +from mockbm import network # noqa:E402 + +stats = network.stats +objectracker = network.objectracker -if __name__ == '__main__': - state.kivy = True - print("Kivy Loading......") +def main(): + """main method for starting threads""" + addressGeneratorThread = FakeAddressGenerator() + addressGeneratorThread.daemon = True + addressGeneratorThread.start() + state.kivyapp = NavigateApp() + state.kivyapp.run() + addressGeneratorThread.stopThread() + + +if __name__ == "__main__": + os.environ['INSTALL_TESTS'] = "True" main() diff --git a/src/pyelliptic/openssl.py b/src/pyelliptic/openssl.py index deb81644..851dfa15 100644 --- a/src/pyelliptic/openssl.py +++ b/src/pyelliptic/openssl.py @@ -805,6 +805,10 @@ def loadOpenSSL(): 'libcrypto.dylib', '/usr/local/opt/openssl/lib/libcrypto.dylib']) elif 'win32' in sys.platform or 'win64' in sys.platform: libdir.append('libeay32.dll') + # kivy + elif 'ANDROID_ARGUMENT' in environ: + libdir.append('libcrypto1.1.so') + libdir.append('libssl1.1.so') else: libdir.append('libcrypto.so') libdir.append('libssl.so')