Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] Use structures for flux messages #1225

Open
MorningLightMountain713 opened this issue Feb 18, 2024 · 0 comments
Open

[FEAT] Use structures for flux messages #1225

MorningLightMountain713 opened this issue Feb 18, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@MorningLightMountain713
Copy link
Contributor

MorningLightMountain713 commented Feb 18, 2024

Flux messages are quite large. For example an apprunningmessage:

const fluxAppRunningMsg = {
    type: 'fluxapprunning',
    version: 1,
    name: 'Ipshow',
    hash: '4da0ce332a5e8634b7a22132f4962ff4defdd2a7c3e047494728bbe1208fb3a8', // hash of application specifics that are running
    ip: "12.12.12.12",
    broadcastedAt: 1708252932172,
    runningSince: 1708252932172,
};

This gets converted to json, then used as the payload for another signed flux message. For eg:

const dataObj = {
    version: 1,
    timestamp: 1708252932172,
    pubKey: '04f568e8dbba96b55592cbc4ca378e30fd449eb46e050743eac07aad3e04cf630a0ea5bb20c8ff38e74a0cf0c1657c155c0293d9ba08a0ed69e22e65ff4365bc53',
    signature: 'IB/IEZDZr+C5aT2jNL6X26sEAmOgahTcJjIjeDZkOKFGaWzaWiWZp50t8XO5PCkoz0VQHYr1uFQ0MrKvFaAdQ08=',
    data: fluxAppRunningMsg,
};

Then the above message gets converted to JSON before being sent on the wire. The size of the above message is 497 bytes.

If we were to use structures, the same message would only be 187 bytes that is only 38% of the original messages size.

Something like the following:

fluxapprunning message

type         uint8       1 bytes
version      uint8       1 bytes
name         uint8Array  32 bytes max
hash         uint8Array  32 bytes
ip           uint32      4 bytes
broadcast    uint32      4 bytes
running      uint32      4 bytes

total 78 bytes max.
generic fluxnode signed message

version      uint8       1 bytes
timestamp    uint32      4 bytes
pubkey       uint8Array  65 bytes
signature    uint8Array  65 bytes (as buffer, 88 bytes otherwise)
data         uint8Array  74 bytes (fluxapprunning max message size)

total 213 bytes or (187 for app name ipshow) vs 497 when serializing JSON

It wouldn't be too much work to create the serializer / deserializer - then just swap out the JSON serializer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants
@MorningLightMountain713 @TheTrunk and others