Page MenuHomePhabricator

[lib] introduce context to process Outbound P2P Messages
ClosedPublic

Authored by kamil on May 20 2024, 4:41 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Nov 22, 8:50 AM
Unknown Object (File)
Fri, Nov 8, 6:22 PM
Unknown Object (File)
Fri, Nov 8, 9:30 AM
Unknown Object (File)
Oct 19 2024, 1:51 PM
Unknown Object (File)
Oct 14 2024, 4:42 PM
Unknown Object (File)
Oct 14 2024, 4:42 PM
Unknown Object (File)
Oct 14 2024, 4:42 PM
Unknown Object (File)
Oct 14 2024, 4:42 PM
Subscribers

Details

Summary

Please read inline comments, everything is explained in those

Depends on D12131

Test Plan

Testes in next diff on KeyserverStore example

Diff Detail

Repository
rCOMM Comm
Branch
broadcasting-last
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

kamil held this revision as a draft.
kamil published this revision for review.May 27 2024, 4:52 AM
kamil edited the summary of this revision. (Show Details)
kamil added inline comments.
lib/handlers/db-ops-handler.react.js
43–45

we have new OutboundP2PMessages - we have to start processing them

lib/tunnelbroker/peer-to-peer-context.js
46

debug leftover

52

We want to fetch all messages each time because:

  1. We need to make sure the order is correct, so when encrypting or sending we want to start from the oldest.
  2. If something went wrong in the previous iteration, we want to attempt to start again.

The only improvement here is that in getAllOutboundP2PMessages we should query all messages but not with sent status - creating a follow-up task for it.

54–61

grouping all messages by device - when there is no session or we can not create a session with device we might want to skip the rest of messages

56–60

we need to consider how to detect when messages for a device which is not in a peer list anymore can be deleted - creating a followup task for it

63

this is used three times below - creating lambda to avoid code duplication

105

We should filter if this is an error caused because of not existing session or a malformed session, but there is incompatibility in error messages thrown from the web and native, going to create a follow-up task for it.

This code is for a not existing session, when the session is malformed we should also add a code to resend messages, this will be addressed in Resending messages to peers.

126–127

if this failed we could ignore that device, but on next run we'll attempt again

147

we also might want to consider:

  1. Running this on app start
  2. Running this after a specific time (if there are no changes in DB but still want to send not yet send messages)
147–169
  1. When there is no promise - spawn the promise processing messages
  2. When a promise is running - flip the switch (restartPromise) saying that if the promise is finished it needs to start again because something in DB changed (to avoid spawning multiple promises in parallel)
152

debug leftover

lib/tunnelbroker/tunnelbroker-context.js
476

I see this pattern somewhere in the codebase where Context render another one - I think here it makes sense as PeerToPeerProvider is done using Tunnelbroker, but I am open to update this

lib/types/sqlite-types.js
5–9

adressed - the message was prepared to be sent to other peers but it's not encrypted. It was inserted into DB in the same transaction as making changes to the own store. For example, when adding a keyserver it's important to in the same SQL transaction update our keyserver_store and prepare messages to all devices at the same time. (I think this could be renamed but not sure about a better name).
encrypted - it was encrypted, encryption is done in the same transaction as the persisting crypto module to message order is also tracked on the client side, this means the message can be sent.
sent - the message that was sent to another peer (Tunnelbroker has it), we don't do anything about it, just wait for the confirmation (confirmation handled in peerToPeerMessageHandler)

tomek added inline comments.
lib/tunnelbroker/peer-to-peer-context.js
75

Why do we parse the ciphertext?

126–127

Is there a chance that this will succeed? Does it make sense to backoff or something?

lib/types/sqlite-types.js
5–9

adressed is missleading. How about persisted?

This revision is now accepted and ready to land.May 28 2024, 4:10 AM
lib/types/sqlite-types.js
5–9

Might be good to add these as code comments. It seems useful for understanding the code

  • address review
  • rebase before landing
lib/tunnelbroker/peer-to-peer-context.js
56–60
75

In our case ciphertext is the stringified EncryptedData. If you think this is misleading we can rename it but this will require adding migration to update SQLite schema

105
147
lib/types/sqlite-types.js
5–9

Might be good to add these as code comments. It seems useful for understanding the code

done

adressed is missleading. How about persisted?

done