pub struct NetworkBuilder<T, I>(_, _);
Expand description

Convenient network layer builder

Implementations

Creates a basic network layer that is an ADNL node

See with_adnl_ext if you need a node with a peer filter

Examples
use std::error::Error;

use everscale_network::{adnl, NetworkBuilder};

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let keystore = adnl::Keystore::builder()
        .with_tagged_key([0; 32], 0)?
        .build();

    let options = adnl::NodeOptions::default();

    let adnl = NetworkBuilder::with_adnl("127.0.0.1:10000", keystore, options).build()?;

    Ok(())
}

Creates a basic network layer that is an ADNL node with additional filter

Examples
use std::error::Error;
use std::net::SocketAddrV4;
use std::sync::Arc;

use everscale_network::{adnl, NetworkBuilder};

struct MyFilter;

impl adnl::PeerFilter for MyFilter {
    fn check(
        &self,
        ctx: adnl::NewPeerContext,
        addr: SocketAddrV4,
        peer_id: &adnl::NodeIdShort,
    ) -> bool {
        // Allow only non-loopback IPs
        !addr.ip().is_loopback()
    }
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let keystore = adnl::Keystore::builder()
        .with_tagged_key([0; 32], 0)?
        .build();

    let options = adnl::NodeOptions::default();

    let peer_filter = Arc::new(MyFilter);

    let adnl = NetworkBuilder::with_adnl_ext("127.0.0.1:10000", keystore, options, peer_filter)
        .build()?;

    Ok(())
}

Creates DHT network layer

Examples
use std::error::Error;

use everscale_network::{adnl, dht, NetworkBuilder};

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    const DHT_KEY_TAG: usize = 0;

    let keystore = adnl::Keystore::builder()
        .with_tagged_key([0; 32], DHT_KEY_TAG)?
        .build();

    let adnl_options = adnl::NodeOptions::default();
    let dht_options = dht::NodeOptions::default();

    let (adnl, dht) = NetworkBuilder::with_adnl("127.0.0.1:10000", keystore, adnl_options)
        .with_dht(DHT_KEY_TAG, dht_options)
        .build()?;
    Ok(())
}

Creates overlay network layer.

NOTE: RLDP network layer must be present before calling this method.

Examples
use std::error::Error;

use everscale_network::{adnl, rldp, NetworkBuilder};

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    const OVERLAY_KEY_TAG: usize = 0;

    let keystore = adnl::Keystore::builder()
        .with_tagged_key([0; 32], OVERLAY_KEY_TAG)?
        .build();

    let adnl_options = adnl::NodeOptions::default();
    let rldp_options = rldp::NodeOptions::default();

    let (adnl, rldp, overlay) =
        NetworkBuilder::with_adnl("127.0.0.1:10000", keystore, adnl_options)
            .with_rldp(rldp_options)
            .with_overlay(OVERLAY_KEY_TAG)
            .build()?;
    Ok(())
}

Creates RLDP network layer

See with_rldp_ext if you need an RLDP node with additional subscribers

Examples
use std::error::Error;

use everscale_network::{adnl, rldp, NetworkBuilder};

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let keystore = adnl::Keystore::builder()
        .with_tagged_key([0; 32], 0)?
        .build();

    let adnl_options = adnl::NodeOptions::default();
    let rldp_options = rldp::NodeOptions::default();

    let (adnl, rldp) = NetworkBuilder::with_adnl("127.0.0.1:10000", keystore, adnl_options)
        .with_rldp(rldp_options)
        .build()?;
    Ok(())
}

Creates RLDP network layer with additional RLDP query subscribers

Examples
use std::borrow::Cow;
use std::error::Error;
use std::sync::Arc;

use anyhow::Result;
use everscale_network::{
    adnl, rldp, NetworkBuilder, QueryConsumingResult, QuerySubscriber, SubscriberContext,
};

struct LoggerSubscriber;

#[async_trait::async_trait]
impl QuerySubscriber for LoggerSubscriber {
    async fn try_consume_query<'a>(
        &self,
        ctx: SubscriberContext<'a>,
        constructor: u32,
        query: Cow<'a, [u8]>,
    ) -> Result<QueryConsumingResult<'a>> {
        println!("received {constructor}");
        Ok(QueryConsumingResult::Rejected(query))
    }
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let keystore = adnl::Keystore::builder()
        .with_tagged_key([0; 32], 0)?
        .build();

    let adnl_options = adnl::NodeOptions::default();
    let rldp_options = rldp::NodeOptions::default();

    let subscriber = Arc::new(LoggerSubscriber);

    let (adnl, rldp) = NetworkBuilder::with_adnl("127.0.0.1:10000", keystore, adnl_options)
        .with_rldp_ext(rldp_options, vec![subscriber])
        .build()?;
    Ok(())
}

Initializes all layers into a tuple of components

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Extract a subset of the possible types in a coproduct (or get the remaining possibilities) Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Performs the indexed conversion.
Should always be Self
Consumes the current HList and returns an HList with the requested shape. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more