Skip to main content

vector_core/i2p/
probe.rs

1//! I2P's side of twin checks: the shared ones in `transport::twins`, plus a probe through an
2//! instance that need not be the one installed.
3
4use crate::transport::twins;
5use crate::transport::{ConnectError, Kind, Lane};
6
7pub use twins::{check_alias, find_alias, FindAlias};
8
9use super::I2pTransport;
10
11/// Stream to `via:443` on the Shared session, then a TLS handshake for `host`. Ok means the
12/// twin serves `host`'s certificate.
13pub async fn probe_twin(t: &I2pTransport, host: &str, via: &str) -> Result<(), String> {
14    let stream = match t.inner.nick(Lane::Shared) {
15        Some(nick) => t.inner.open(&nick, via, 443).await,
16        None => Err(ConnectError::NotReady(Some(Kind::I2p))),
17    };
18    let check = twins::tls_check(host, stream).await;
19    match check.state {
20        crate::transport::aliases::CheckState::Ok => Ok(()),
21        _ => Err(check.text.unwrap_or_else(|| twins::not_served_text(host))),
22    }
23}
24
25/// The first `privacy_addresses` entry that names a `.b32.i2p` host, as that host.
26pub fn first_b32(doc: &serde_json::Value) -> Option<String> {
27    twins::first_privacy_address(doc, Kind::I2p)
28}
29
30/// Check every unchecked twin now, when I2P is up for the account on screen.
31pub fn check_unchecked() {
32    twins::check_pending();
33}