Skip to content

Commit

Permalink
Initial Implementation of BlockchainHandler and CrankkModule for Kade…
Browse files Browse the repository at this point in the history
…na Integration (#1)

This pull request introduces the initial implementation of the
**BlockchainHandler** and **CrankkModule** classes, designed to
facilitate interactions with Kadena smart contracts. These changes aim
to establish foundational connectivity and operational protocols for
blockchain interactions within our network modules.

- **BlockchainHandler Class**:

Manages blockchain operations such as syncing nodes and executing
blockchain commands.
Implements robust Wi-Fi connectivity checks to ensure operations are
performed only when network conditions are favorable.
Utilizes secure cryptographic methods for handling sensitive data
related to blockchain transactions.

- **CrankkModule Class**:

Manages and processes specific mesh network packets crucial for
blockchain interactions, utilizing the BlockchainHandler to effectively
integrate blockchain capabilities.

- **Wallet configuration**

Enable configuration of wallet private and public keys via the web
client interface, allowing for secure and user-friendly management of
blockchain credentials.

---------

Co-authored-by: Peter Varga <[email protected]>

Conditional Compilation and Redefined 'strptime'  (#3)

This PR introduces conditional compilation directives across the
Blockchain modules to exclude webserver-related code when
MESHTASTIC_EXCLUDE_WEBSERVER is defined. Additionally, it redefines the
strptime function within BlockchainHandler.cpp to address issues related
to IRAM overflow when calling HTTPClient functions. The changes ensure
that the system can be compiled with or without webserver components
based on configuration, enhancing modularity and flexibility in builds.

1. Added #if !MESHTASTIC_EXCLUDE_WEBSERVER guards in
BlockchainHandler.cpp, #if !MESHTASTIC_EXCLUDE_CRANKK in
CrankkModule.cpp, and Modules.cpp to conditionally compile blockchain
related code.
2. Redefined strptime in BlockchainHandler.cpp to use sscanf for parsing
date-time strings, which helps in avoiding potential IRAM overflow
issues in certain devices.

These modifications are aimed at improving the configurability of the
system, allowing for builds tailored to specific needs and hardware
capabilities.

Fix memory leaks in JSON object creation (#2)

This PR addresses several issues in the BlockchainHandler class,
including fixing memory leaks and improving the WiFi availability check.
The changes ensure better memory management and consistency in WiFi
status checks, enhancing the stability and reliability of the system.

1. Memory Management Improvements:
Added delete statements to properly free dynamically allocated JSONValue
objects.
Ensured that BlockchainHandler objects are properly deleted after use to
prevent memory leaks.
2. WiFi Availability Check:
Replaced the custom isWIFIavailable function with the existing
isWifiAvailable function for consistency and reliability.
3. Logging Enhancements:
Added logging to track heap memory usage before and after performing
node synchronization in performNodeSync.

These modifications are aimed at improving the memory management and
operational consistency of the BlockchainHandler class, ensuring that
resources are properly managed and the system remains stable during
operation.

Improve Beacon Check and Refactor BlockchainHandler to Use Enum for Status Handling (#4)

This pull request refactors the `BlockchainHandler` class to use an enum
(`BlockchainStatus`) for handling various states and errors, improving
code readability and maintainability. Additionally, it enhances the
logic for checking whether the node is ready to beacon by ensuring that
there are no errors.

- **Added `BlockchainStatus` Enum**: Introduced an enumeration to
represent different states and errors, including `OK`, `NO_WIFI`,
`HTTP_ERROR`, `EMPTY_RESPONSE`, `PARSING_ERROR`, `NODE_NOT_FOUND`,
`READY`, and `NOT_DUE`.
- **Implemented `blockchainStatusToString` Function**: Added a function
to convert `BlockchainStatus` enum values to strings for logging
purposes.
- **Refactored `performNodeSync` Method**: Updated the method to use the
new `BlockchainStatus` enum for handling different states and errors.
The method now checks if the node is ready to beacon by ensuring that
the status is `READY` and there are no errors.
- **Updated `executeBlockchainCommand` and `parseBlockchainResponse`
Methods**: Changed the return type to `BlockchainStatus` and updated the
logic to return appropriate enum values.

- **Better Error Handling**: The updated logic ensures that errors are
handled appropriately and that the node is only ready to beacon when
there are no errors.
- **Improved Readability**: Using an enum for status handling makes the
code more expressive and easier to understand.
- **Enhanced Maintainability**: The refactored code is more structured
and organized, making it easier to maintain and extend.

Enhance BlockchainHandler with payload encryption (#5)

This PR introduces significant enhancements to the BlockchainHandler
class by adding encryption capabilities and refactoring utility
functions into a new BlockchainUtils file. Additionally, it introduces a
new EncryptionHandler class to encapsulate encryption-related
functionalities.

- Encryption Integration:

Added encryption for payloads in BlockchainHandler using the director's
public key.
Introduced EncryptionHandler class to handle encryption tasks such as
generating hashes, signatures, and encrypting payloads.

- Refactoring:

Moved utility functions like strptime, getCurrentTimestamp, and
logLongString to a new utils.h file.
Refactored BlockchainHandler to use EncryptionHandler for
encryption-related tasks.

- Command Handling:

Modified parseBlockchainResponse to differentiate between commands and
handle responses accordingly.
Updated CrankkModule to fetch the director's public key before
encrypting and sending data.

- Code Cleanup:

Removed redundant functions from BlockchainHandler and moved them to
EncryptionHandler.
Replaced raw pointers with std::unique_ptr for better memory management.
Change LOG_INFO levels to LOG_DEBUG or LOG_TRACE

- Security: Encrypting payloads enhances the security of data
transmitted over the blockchain.

- Modularity: Separating encryption logic into its own class
(EncryptionHandler) improves code maintainability and readability.

- Scalability: Refactoring utility functions into a separate file
(utils.h) makes it easier to manage and extend utility functionalities.

Remove Raspbian Build and Package Jobs from Workflow (#6)

This PR removes the build-raspbian and package-raspbian jobs from the
.github/workflows/main_matrix.yml file.
The changes include:
- Deleting the build-raspbian job configuration.

- Deleting the package-raspbian job configuration.

- Updating the gather-artifacts job dependencies to exclude
build-raspbian and package-raspbian.

These changes streamline the CI workflow by removing unnecessary steps
related to Raspbian builds and packaging.

---------

Co-authored-by: Peter Varga <[email protected]>

Changes by create-pull-request action (#8)

Automated changes by
[create-pull-request](https://github.com/peter-evans/create-pull-request)
GitHub action

Co-authored-by: jorblancoa <[email protected]>

Update GitHub Actions to Use crankkio/web Repository (#9)

This PR updates the GitHub Actions workflows to pull the web UI from the
crankkio/web repository instead of the meshtastic/web repository. The
changes affect the following workflow files:

- build_esp32.yml

- build_esp32_c3.yml

- build_esp32_s3.yml

- package_amd64.yml

These updates ensure that the correct repository is used for fetching
the web UI assets during the build and packaging processes.

Changes by create-pull-request action (#11)

Automated changes by
[create-pull-request](https://github.com/peter-evans/create-pull-request)
GitHub action

Co-authored-by: jorblancoa <[email protected]>

Remove private key logging message (#12)

Merge tag 'v2.3.15.deb7c27' from upstream (#13)

Bump to 2.0.0

Bump to 2.3.15

Merge tag 'v2.4.2.5b45303' from upstream (#18)

Merge tag 'v2.5.14.f2ee0df' from upstream
  • Loading branch information
jorblancoa committed Dec 4, 2024
1 parent f2ee0df commit 2d2b84d
Show file tree
Hide file tree
Showing 43 changed files with 1,114 additions and 402 deletions.
4 changes: 2 additions & 2 deletions .github/actions/build-variant/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ runs:
if: inputs.include-web-ui == 'true'
uses: dsaltares/fetch-gh-release-asset@master
with:
repo: meshtastic/web
repo: crankkio/web
file: build.tar
target: build.tar
token: ${{ inputs.github_token }}
version: tags/v2.5.3
version: tags/latest

- name: Unpack web ui
if: inputs.include-web-ui == 'true'
Expand Down
52 changes: 0 additions & 52 deletions .github/workflows/build_raspbian.yml

This file was deleted.

52 changes: 0 additions & 52 deletions .github/workflows/build_raspbian_armv7l.yml

This file was deleted.

6 changes: 0 additions & 6 deletions .github/workflows/main_matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,6 @@ jobs:
with:
board: ${{ matrix.board }}

package-raspbian:
uses: ./.github/workflows/package_raspbian.yml

package-raspbian-armv7l:
uses: ./.github/workflows/package_raspbian_armv7l.yml

package-native:
uses: ./.github/workflows/package_amd64.yml

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/package_amd64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Pull web ui
uses: dsaltares/fetch-gh-release-asset@master
with:
repo: meshtastic/web
repo: crankkio/web
file: build.tar
target: build.tar
token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
85 changes: 0 additions & 85 deletions .github/workflows/package_raspbian.yml

This file was deleted.

85 changes: 0 additions & 85 deletions .github/workflows/package_raspbian_armv7l.yml

This file was deleted.

2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Contributor Covenant Code of Conduct

The Meshtastic Firmware project is subject to the code of conduct for the parent project, which can be found here:
The Meshtastic Firmware project is subject to the code of conduct for the parent project, which can be found here:
https://meshtastic.org/docs/legal/conduct/
2 changes: 1 addition & 1 deletion arch/esp32/esp32.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ platform = platformio/[email protected]
build_src_filter =
${arduino_base.build_src_filter} -<platform/nrf52/> -<platform/stm32wl> -<platform/rp2xx0> -<mesh/eth/> -<mesh/raspihttp>

upload_speed = 921600
upload_speed = 460800 #921600
debug_init_break = tbreak setup
monitor_filters = esp32_exception_decoder

Expand Down
4 changes: 2 additions & 2 deletions arch/nrf52/nrf52.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ build_flags =
-DMAX_NUM_NODES=80

build_src_filter =
${arduino_base.build_src_filter} -<platform/esp32/> -<platform/stm32wl> -<nimble/> -<mesh/wifi/> -<mesh/api/> -<mesh/http/> -<modules/esp32> -<platform/rp2xx0> -<mesh/eth/> -<mesh/raspihttp>
${arduino_base.build_src_filter} -<platform/esp32/> -<platform/stm32wl> -<nimble/> -<mesh/wifi/> -<mesh/api/> -<mesh/http/> -<mesh/blockchain/> -<modules/esp32> -<platform/rp2040> -<mesh/eth/> -<mesh/raspihttp>

lib_deps=
${arduino_base.lib_deps}
Expand All @@ -28,4 +28,4 @@ lib_deps=

lib_ignore =
BluetoothOTA
lvgl
lvgl
1 change: 1 addition & 0 deletions arch/portduino/portduino.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ build_src_filter =
-<platform/rp2xx0>
-<mesh/wifi/>
-<mesh/http/>
-<mesh/blockchain/>
+<mesh/raspihttp/>
-<mesh/eth/>
-<modules/esp32>
Expand Down
2 changes: 1 addition & 1 deletion arch/rp2xx0/rp2350.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ build_flags =
-D__PLAT_RP2040__
# -D _POSIX_THREADS
build_src_filter =
${arduino_base.build_src_filter} -<platform/esp32/> -<nimble/> -<modules/esp32> -<platform/nrf52/> -<platform/stm32wl> -<mesh/eth/> -<mesh/wifi/> -<mesh/http/> -<mesh/raspihttp>
${arduino_base.build_src_filter} -<platform/esp32/> -<nimble/> -<modules/esp32> -<platform/nrf52/> -<platform/stm32wl> -<mesh/eth/> -<mesh/wifi/> -<mesh/http/> -<mesh/blockchain/> -<mesh/raspihttp>

lib_ignore =
BluetoothOTA
Expand Down
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,4 @@ lib_deps =
https://github.com/KodinLanewave/[email protected]
mprograms/[email protected]
dfrobot/[email protected]
https://github.com/meshtastic/DFRobot_LarkWeatherStation#4de3a9cadef0f6a5220a8a906cf9775b02b0040d
https://github.com/meshtastic/DFRobot_LarkWeatherStation#4de3a9cadef0f6a5220a8a906cf9775b02b0040d
3 changes: 2 additions & 1 deletion src/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// Turn off all optional modules
#ifdef MESHTASTIC_EXCLUDE_MODULES
#define MESHTASTIC_EXCLUDE_AUDIO 1
#define MESHTASTIC_EXCLUDE_CRANKK 1
#define MESHTASTIC_EXCLUDE_DETECTIONSENSOR 1
#define MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR 1
#define MESHTASTIC_EXCLUDE_EXTERNALNOTIFICATION 1
Expand Down Expand Up @@ -361,4 +362,4 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#endif

#include "DebugConfiguration.h"
#include "RF95Configuration.h"
#include "RF95Configuration.h"
Loading

0 comments on commit 2d2b84d

Please sign in to comment.