3 releases (stable)

2.0.0 Aug 21, 2024
1.0.0 Feb 14, 2024
0.1.0 Mar 26, 2022

#10 in #ton

Download history 140/week @ 2024-12-09 64/week @ 2024-12-16 36/week @ 2024-12-23 9/week @ 2024-12-30 66/week @ 2025-01-06 115/week @ 2025-01-13 82/week @ 2025-01-20 80/week @ 2025-01-27 62/week @ 2025-02-03 92/week @ 2025-02-10 101/week @ 2025-02-17 98/week @ 2025-02-24 76/week @ 2025-03-03 184/week @ 2025-03-10 74/week @ 2025-03-17 66/week @ 2025-03-24

405 downloads per month
Used in 3 crates (2 directly)

MIT license

38KB
700 lines

ADNL

crates.io documentation

Minimal client-server ADNL implementation in Rust. Specification of ADNL is available here.

Quickstart

Run this example: cargo run --example time

use adnl::AdnlPeer;
use base64::Engine as _;
use futures::{SinkExt, StreamExt};
use std::error::Error;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    // decode liteserver public key
    let remote_public = base64::engine::general_purpose::STANDARD.decode("n4VDnSCUuSpjnCyUk9e3QOOd6o0ItSWYbTnW3Wnn8wk=")?;

    // act as a client: connect to ADNL server and perform handshake
    let mut client = AdnlPeer::connect(remote_public, "5.9.10.47:19949").await?;

    // already serialized TL with getTime query
    let query = hex::decode("7af98bb435263e6c95d6fecb497dfd0aa5f031e7d412986b5ce720496db512052e8f2d100cdf068c7904345aad16000000000000")?;

    // send over ADNL
    client.send(query.into()).await?;

    // receive result
    let result = client.next().await.ok_or_else(|| "no result")??;

    // get time from serialized TL answer
    println!(
        "received: {}",
        u32::from_le_bytes(result[result.len() - 7..result.len() - 3].try_into()?)
    );
    Ok(())
}

Dependencies

~6–17MB
~208K SLoC