Threading best practices #1044
Replies: 5 comments 2 replies
-
|
Sorry to bump this up, but if someone has input on the topic it will be much appreciated. |
Beta Was this translation helpful? Give feedback.
-
|
I don't have definitive answers for you, but I can tell you the approach
I'm taking in writing applications for Reticulum:
+ Assume Reticulum isn't re-entrant and avoid calling the same function
from multiple threads simultaneously. Same for message submission - try
and submit one at a time.
+ Give LXMF time to process and send messages - don't exit the
application immediately after submission.
+ Exit callbacks as quickly as possible - these definitely do delay
packet processing.
Skyguy
…
|
Beta Was this translation helpful? Give feedback.
-
|
So far I've just queued the calls to handle_outbound() but my messaging
app isn't very far advanced yet!
|
Beta Was this translation helpful? Give feedback.
-
|
@markqvist can you help me understand why the log below occurs which causes the msg not to be sent? More of the logs are above in the first post. "Found generated ticket for <7f254eee1e9b47b8f9e291d7fe3317f4> with 20d, 23h, 52m and 22.32s of validity left, re-using this one" |
Beta Was this translation helpful? Give feedback.
-
No, RNS is designed to be fully multi-threaded. You can call any RNS, LXMF and LXST API function from any thread you wish. Not directly RNS related, but: Take note though, that some frontend frameworks require UI-updating API calls to happen on the main thread. RNS-triggered callbacks can also occur from any thread launched by RNS internally, and if your frontend framework requires a specific thread to call updates, you will need to handle this internally in your application, with a message queue or similar.
In general, no. A while back I refactored most of the callback code to ensure that triggering callbacks that could potentially block RNS-internal logic flow would themself happen in a newly spawned thread. It is possible I missed something, though, so if you found something where a callback blocks packet processing, please let me know.
No, not at all. If you use the provided message dispatch functions of the LXMF Router instance you've created, it will handle all queuing and scheduling automatically, and you will get callbacks on success or failure.
This is the root cause of the problems. It looks like you are using the stamp system. This is what happens:
Hope that clears it up! Otherwise, let me know. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello!
I’m using RNS, LXST, and LXMF and I want to understand best practices for threading and back-to-back function calls. I've been in the source code heavily for the last several weeks as I'm progressing thru RNS integration, but definitely still have gaps in my understanding.
I'm developing a Kotlin Android application and using Chaquopy for interfacing with RNS's python. There were some challenges going that direction but overall working very well.
Please advise on:
- Threading:
- Back-to-back function calls:
One of the reasons for asking above is I’m having random issues of what appears to be msgs not getting sent out from the LXMF router and want to make sure I’m playing nicely.
Dev setup:
Here is the log of Device A sending to Device C and B, respectively:
// This msg doesn't appear to have been sent to C:
sending msg type: lxmf.delivery to: <lxmf.delivery.f574cf1cdae1ca32f1355296636a4220:7f254eee1e9b47b8f9e291d7fe3317f4>
[2025-12-11 15:20:40] [Debug] No stamp cost set on LXM to <7f254eee1e9b47b8f9e291d7fe3317f4>, autoconfigured to 8, as required by latest announce
[2025-12-11 15:20:40] [Debug] Found generated ticket for <7f254eee1e9b47b8f9e291d7fe3317f4> with 20d, 23h, 52m and 22.32s of validity left, re-using this one
// This msg delivered to B:
sending msg type: lxmf.delivery to: <lxmf.delivery.1db754732739381f471dcc797bad5d94:9bb86a3e38b07e11c8d0da311400f7eb>
[2025-12-11 15:20:44] [Debug] No stamp cost set on LXM to <9bb86a3e38b07e11c8d0da311400f7eb>, autoconfigured to 8, as required by latest announce
[2025-12-11 15:20:44] [Debug] Deferred stamp generation was requested for , but outbound ticket was applied, processing immediately
[2025-12-11 15:20:44] [Debug] A ticket for <9bb86a3e38b07e11c8d0da311400f7eb> was already delivered 7m and 33.96s ago, not including another ticket yet
[2025-12-11 15:20:44] [Debug] Generated stamp with outbound ticket d1:c8:6c:4e:58:68:38:a1:95:e2:78:9e:85:82:62:a5 for <LXMessage 0ad7517751a5cf4d40dea1f06a11830ac0b1d49dd9c18a46eb8aec0039a28483>
[2025-12-11 15:20:44] [Debug] Outbound processing for <LXMessage 0ad7517751a5cf4d40dea1f06a11830ac0b1d49dd9c18a46eb8aec0039a28483> to <9bb86a3e38b07e11c8d0da311400f7eb>
[2025-12-11 15:20:44] [Debug] Using available direct link <96bb105651c2ab54d3c5bc285eb9f697> to <9bb86a3e38b07e11c8d0da311400f7eb>
[2025-12-11 15:20:44] [Debug] Starting transfer of <LXMessage 0ad7517751a5cf4d40dea1f06a11830ac0b1d49dd9c18a46eb8aec0039a28483> to <9bb86a3e38b07e11c8d0da311400f7eb> on link <96bb105651c2ab54d3c5bc285eb9f697>
[2025-12-11 15:20:44] [Extra] Compressing resource data...
[2025-12-11 15:20:44] [Extra] Compression completed in 0.002 seconds
[2025-12-11 15:20:44] [Extra] Compression did not decrease size, sending uncompressed
[2025-12-11 15:20:44] [Extra] Starting resource hashmap computation with 1 entries...
[2025-12-11 15:20:44] [Extra] Hashmap computation concluded in 0.001 seconds
[2025-12-11 15:20:44] [Extra] Sent resource advertisement for <9d66fa0b77c7fefc050eb51af8b55b5cc51ccf3e095a775f22e602c4c0f0b050>
[2025-12-11 15:20:44] [Debug] Received delivery notification for <LXMessage 0ad7517751a5cf4d40dea1f06a11830ac0b1d49dd9c18a46eb8aec0039a28483>
[2025-12-11 15:20:44] [Verbose] Msg delivered.
The log indicates "Found generated ticket for" but I don't know what causes this to happen and have looked thru the source code but not understanding why.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions