Skip to content

api: Add init_transports() API - #8707

Open
Hocuri wants to merge 15 commits into
mainfrom
hoc/init_transports_api
Open

Hocuri wants to merge 15 commits into
mainfrom
hoc/init_transports_api

Conversation

@Hocuri

@Hocuri Hocuri commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

Fix #8693

This adds a new API init_transports() that cares about adding one or more transports to the profile. It takes an optional QR code which can be DCLOGIN, DCACCOUNT, or securejoin, and takes them into account for the transports. The further details of what it does are not important from the UI point of view.

Currently, init_transports() onboards only on nine.testrun.org, and then enables Config::Autorelay, so that more relays will be added later. If a qr code is passed, then the addresses from there are put into the relay_candidates table so that they will be considered by autorelay.

It would be easy now to modify init_transports() to randomly select the first relay that is used for onboarding, but I decided not to until we have a clear picture where we want to go.

This PR also updates the list of default relays, and modifies load_relay_candidates() so that we do not need a migration everytime we update the list but can instead simply update const DEFAULT_RELAY_CANDIDATES.

@Hocuri
Hocuri marked this pull request as draft September 16, 2026 21:25
Comment thread src/configure.rs Outdated
Comment thread src/autorelay.rs Outdated
Comment thread src/autorelay.rs
@Hocuri
Hocuri force-pushed the hoc/init_transports_api branch from 08608e0 to f308e73 Compare September 17, 2026 16:20
@Hocuri
Hocuri force-pushed the hoc/init_transports_api branch from 04b6f5c to 28b1aa6 Compare September 17, 2026 17:07
@Hocuri
Hocuri marked this pull request as ready for review September 17, 2026 19:22
@Hocuri
Hocuri requested a review from link2xt September 17, 2026 19:31

@hpk42 hpk42 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

haven't fully gotten through the PR yet, and only a few preliminary comments. Overall i am not sure this is the right approach to get reliable initial onboarding on multiple transports. In #8444 you already introduced the basic multi-relay onboarding support and i think it's worthwhile to just use that approach. Did you consider just amending it instead of introducing a parallel new mechanism (which frankly looks complex to reason about)?

Comment thread src/autorelay.rs Outdated
Comment thread src/autorelay/autorelay_tests.rs Outdated
Comment thread src/autorelay.rs Outdated
Comment thread src/autorelay.rs Outdated
@Hocuri

Hocuri commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator Author

Did you consider just amending it instead of introducing a parallel new mechanism

I considered amending it, yes, but there is only very little code that could have been re-used

(which frankly looks complex to reason about)?

Not sure which part of the complexity you would prefer to see removed?

FTR, most of the complexity is self-contained rather than being spread around the codebase.

  • We need the channel and the JoinSet in order to try multiple relays at once (so that one bad relay doesn't block onboarding until the timeout is reached; not sure how long the timeouts are, but we have quite generous timeouts so that DC works in very slow networks); you agreed while talking to @r10s that that's worth it
    • By doing connection attempts sequentially, we could likely save some tens LOC, and then either call into maybe_add_additional_relays_inner() or just directly call configure() in a loop, both would be equally easy
  • The calls to login_param_from_host() and configure() could be extracted into a new function that is shared with the maybe_add_additional_relays() logic, but I didn't see the need to extract a function just for two function calls
  • Thinking about it, calling set_config_bool(Config::AutorelayFinished, true) isn't actually necessary here, automatic relay management will do it the first time it runs. I find it nice to have it here because it makes local reasoning easier, but others may disagree
  • The additions to configure.rs are needed in order to use this mechanism during onboarding
  • The changes to load_relay_candidates() are so that we don't need to do a migration everytime the default relay candidates change, and so that e.g. Nami can make a PR to change the default relay candidates without needing me
    • Adding query_map_vec() in sql.rs is adding some boilerplate code so that we can use the same code with transactions as without transactions, because we want to use async less and transactions more, both for performance and for correctness reasons; I wanted to add this since quite some time already

@Hocuri
Hocuri force-pushed the hoc/init_transports_api branch from 70869ba to 35776b5 Compare September 18, 2026 10:26
ctx.add_transport_from_qr(&qr).await
}

/// Automatically adds up to three transports.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is not really true if we scan a QR code, then only one relay is added and autorelay is disabled.

This will likely be kept like this because we don't want to onboard users on more relays if they specifically selected one relay and also because we are using this in tests and don't want to onboard on non-CI relays when testing.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

That's why I said "up to three".

I'm happy to change the wording if you have another suggestion, I just don't want to describe what it does in detail, because the UIs shouldn't mind.

Comment thread src/configure.rs Outdated
@Hocuri
Hocuri force-pushed the hoc/init_transports_api branch 2 times, most recently from 784ad78 to 19ee906 Compare September 18, 2026 16:30
@Hocuri
Hocuri force-pushed the hoc/init_transports_api branch from 19ee906 to 37a04a8 Compare September 18, 2026 17:02
@Hocuri
Hocuri marked this pull request as draft September 18, 2026 17:44
@Hocuri
Hocuri marked this pull request as ready for review September 18, 2026 18:03
@Hocuri

Hocuri commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator Author

OK, after talking with @link2xt let's go for an intermediate solution:

  • Remove the concurrency code and only onboard on nine.testrun.org, but don't do any larger changes to the PR as-is. This made it easy to switch away from the concurrent onboarding for now, and will make it easy to switch back to it later. But we won't have any concurrency in the to-be-released release, in order to minimize the risk. (83b870b)
  • Don't write the relay candidates into the database, so that it will be easier to remove relay candidates later. (db6b7d9)

@hpk42 hpk42 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

now that the PR uses nine.testrun.org i am not sure there is a sufficiently big advantage over #8444 to warrant this new shape of onboarding. On an iOS build i also saw that configure-progress events jump to and fro.

Comment thread src/autorelay.rs
"chtml.ca",
"deltachat.me",
"e2e.sus.fr",
"jp.deltachat.me",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nami asked to not add this host for now (and i agree, it's buggy).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yeah, it was updated now and might just be buggy for us Europeans, but as it's hard to figure out what isn't working, let's leave it out for now.

Comment thread src/autorelay.rs
context
.sql
.transaction(|transaction| {
let mut stmt = transaction.prepare("INSERT INTO relay_candidates(host) VALUES(?)")?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  1. this writes addresses not host names, and 2. no test catches it although it can not possibly succeed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

even if we extract the hosts from the addresses, we might have twice the same host (i've seen such profiles), so need to be careful to not get an SQL Constraint error.

Comment thread src/configure.rs

let skip_network = false;
let res = autorelay::init_transports_inner(self, addrs_from_qr, skip_network)
.race(cancel_channel.recv().map(|_| Err(format_err!("Canceled"))))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if canceled, the init_transports_inner is dropped at a random async point and might have written already something into the transports table, rendering is_configured to True, but IO remains stopped. AutoRelay remains off, so no multi-relay fill up will happen.

Comment thread src/configure.rs
}
crate::qr::Qr::AskVerifyContact { addrs, .. }
| crate::qr::Qr::AskVerifyGroup { addrs, .. }
| crate::qr::Qr::AskJoinBroadcast { addrs, .. } => addrs_from_qr = addrs,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is potentially an unlimited number of addresses (given a bad securejoin link). We should probably prevent ever getting more than MAX_RELAYS, probably in qr.rs already.

hpk42 added a commit that referenced this pull request Sep 19, 2026
Closes #8693 and supsersedes #8707 from which the API
and some overall shape of this commit is inspired.

UIs call `init_transports(None)` or `init_transports(qr)`
to initialize a first transport on the fresh profile,
with more transports added in the background later.
hpk42 added a commit that referenced this pull request Sep 19, 2026
Closes #8693 and supsersedes #8707 from which the API
and some overall shape of this commit is inspired.

UIs call `init_transports(None)` or `init_transports(qr)`
to initialize a first transport on the fresh profile,
with more transports added in the background later.
hpk42 added a commit that referenced this pull request Sep 19, 2026
Closes #8693 and supsersedes #8707 from which the API
and some overall shape of this commit is inspired.

UIs call `init_transports(None)` or `init_transports(qr)`
to initialize a first transport on the fresh profile,
with more transports added in the background later.
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.

add new api initTransports()

4 participants