Skip to content

Conversation

@gRoussac
Copy link
Contributor

@gRoussac gRoussac commented Oct 21, 2024

As MVP Enable wasm32 compilation and runtime of the nested binary-port-access library.

Basically expose the binary-port-access lib as intended for Rust (non wasm32) / NodeJs (wasm32) / Browser WebSockets (wasm32)

  • Rust remains the same a previous aka a TCP connection
  • In Node.js, it uses raw TCP connections via the net module.
  • In non-Node.js environments (typically browsers), it uses WebSockets.

Note that browsers have CORS (Cross-Origin Resource Sharing) restrictions, so the WebSocket requests should/may be addressed to a WebSocket proxy.

The added communication module provides both shared and platform-specific functionalities for managing communication processes.
- common.rs
- wasm32.rs Contains WebAssembly-specific (wasm32 target) communication utilities, available only when compiled for WebAssembly.

A TODO remains to replace usage of js_sys::eval on Node.js (script is local, not remote so no security issue but nice to change to global function execution with js_sys::Reflect::apply which should be more appropriate)

Could not make it work without eval because net library is required for NodeJs through require

NodeJs

Desktop-screenshot-10-27-2024_06_07_PM

Chromium Browser

Desktop-screenshot-10-27-2024_10_30_PM
Desktop-screenshot-10-27-2024_10_32_PM

@gRoussac gRoussac changed the title Rust sdk feat 2.0 Enable wasm32 compilation and runtime of the binary-port-access lib Oct 28, 2024
@gRoussac gRoussac requested a review from rafal-ch November 5, 2024 22:56
Copy link

@wojcik91 wojcik91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, great documentation. I'd prefer if someone with more subject matter experience also looked through this

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we don't use a --release profile I think the make build step is currently just duplicating stuff that is later done by other steps.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a

build-for-release:
	cargo build --release

there was not real release process here but I don't believe other steps include a build, like test / lint / fmt / audit, test does not build

Correct me please if I miss the point.

Copy link
Contributor

@igor-casper igor-casper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine by me, but see the suggestions.

node_address: &str,
request: BinaryRequest,
) -> Result<BinaryResponseAndRequest, Error> {
let request_id = rand::thread_rng().gen::<u16>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of using a random number generator here... u16 is small enough to where you will run into collisions quickly -- from my testing, around 317 iterations. Given the size of this type, it's plausible to experience collisions way sooner than that too. Not a big deal, but there should be a simpler way of tackling this. Would a counter not be enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, That's a good point. usually it's a u64 in sidecar/node, not here as per request def in node. (It does not really matter to have repetition as soon as they are not to much successive, I think previous code was sending 0.)

I added the counter as suggested.

    let request_id = COUNTER.fetch_add(1, Ordering::SeqCst); // Atomically increment the counter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@igor-casper Actually counter is not that great because in CLI it will be always 0, so collision very fast. The counter starts at 0 at every request. A collision every 317 iterations was actually probably better than always 0.

Copy link
Contributor

@igor-casper igor-casper Feb 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gRoussac You're probably right for the purposes of the client, but that's a CLI issue; As a standalone library, I think it should do its best to work in any context and shouldn't cater to just the client. How about you expose a method in the lib for manually assigning a value to the counter, so that downstream has the ability to decide for themselves? (CLI could use this to initialize it to a random value etc.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gRoussac please consider #11 , I think it's a decent solution

@devendran-m
Copy link

Hi @gRoussac ,
PR is approved and ready for merge.

@gRoussac
Copy link
Contributor Author

@wojcik91 @igor-casper Thanks for your good review I appreciate. I think I treated it please give a last check at commit 94c871e
while I am testing it live before merging. cc @devendran-m

…rt-client into rustSDK-feat-2.0

# Conflicts:
#	binary_port_access/src/communication.rs
@gRoussac
Copy link
Contributor Author

@zajko @devendran-m I think I ported your last changes but I didn't implement send_raw for wasm32 as I don't see the purpose yet for wasm32

@gRoussac gRoussac merged commit 6f9ace6 into master Feb 4, 2025
1 check passed
@gRoussac gRoussac linked an issue Feb 4, 2025 that may be closed by this pull request
@gRoussac gRoussac deleted the rustSDK-feat-2.0 branch March 25, 2025 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable wasm32 compilation and runtime of the binary-port-access lib

5 participants