mirror of
https://github.com/chatmail/core.git
synced 2026-09-22 13:01:21 +03:00
feat: mark autorelays for relay operators (#8701)
this PR adds a hack to allow relay operators to differ between manually created relays and autorelays. this is a precaution in case unexpected things happen when introducing autorelay; relay operators then can deny creation on `password_len == 23`, without shutting down manual creation completely. depeding on final initTransport() is done, it may still be that the first created relay is marked as being manual, but that seems fine. `password_len` of the autmatically generated password was chosen as there is otherwise not much data sent - chatmail avoids visible data and metadata everywhere. this hack is about to be removed again asap, once we have some experiences with multi relay. --------- Co-authored-by: l <link2xt@testrun.org>
This commit is contained in:
@@ -118,7 +118,8 @@ async fn maybe_add_additional_relays_inner(context: &Context, skip_network: bool
|
||||
(now, host),
|
||||
)
|
||||
.await?;
|
||||
let param = login_param_from_host(host);
|
||||
let mark_as_autorelay = true;
|
||||
let param = login_param_from_host(host, mark_as_autorelay);
|
||||
let res = crate::configure::configure(context, ¶m, skip_network).await;
|
||||
if let Err(e) = res {
|
||||
warn!(
|
||||
@@ -158,13 +159,20 @@ async fn load_relay_candidates(context: &Context, now: i64) -> Result<Vec<String
|
||||
Ok(candidates)
|
||||
}
|
||||
|
||||
pub(crate) fn login_param_from_host(host: &str) -> EnteredLoginParam {
|
||||
pub(crate) fn login_param_from_host(host: &str, mark_as_autorelay: bool) -> EnteredLoginParam {
|
||||
let rng = &mut rand::rng();
|
||||
let username = Alphanumeric.sample_string(rng, 9);
|
||||
let addr = username + "@" + host;
|
||||
let addr = addr_normalize(&addr);
|
||||
|
||||
// `mark_as_autorelay` is a temporary precaution hack
|
||||
// while introducing onboarding on multiple community relays from a list:
|
||||
// though relay operators were asked to get on that list, unexpected things can happen,
|
||||
// and they want to return to allow only manual onboarding.
|
||||
// this is possible by failing on `password_len == 23`.
|
||||
|
||||
// 22 * log2(26 * 2 + 10) = 130 bits of entropy
|
||||
let password = Alphanumeric.sample_string(rng, 22);
|
||||
let password = Alphanumeric.sample_string(rng, if mark_as_autorelay { 23 } else { 22 });
|
||||
|
||||
EnteredLoginParam {
|
||||
addr,
|
||||
|
||||
@@ -670,7 +670,8 @@ mod tests {
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn test_early_configure_failure_is_reported() -> Result<()> {
|
||||
let t = TestContext::new().await;
|
||||
let mut param = login_param_from_host("example.org");
|
||||
let mark_as_autorelay = false;
|
||||
let mut param = login_param_from_host("example.org", mark_as_autorelay);
|
||||
|
||||
// An ongoing process, e.g. a backup import,
|
||||
// makes configuration fail without ever contacting a relay.
|
||||
|
||||
@@ -838,7 +838,8 @@ pub(crate) async fn login_param_from_account_qr(
|
||||
.context("Invalid DCACCOUNT scheme")?;
|
||||
|
||||
if !payload.starts_with(HTTPS_SCHEME) {
|
||||
let param = login_param_from_host(payload);
|
||||
let mark_as_autorelay = false;
|
||||
let param = login_param_from_host(payload, mark_as_autorelay);
|
||||
return Ok(param);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user