Skip to main content

Testnet

Struct Testnet 

Source
pub struct Testnet {
    pub bootstrap: Vec<String>,
    pub nodes: Vec<Dht>,
}
Expand description

Create a testnet of Dht nodes to run tests against instead of the real mainline network.

§Bind Address

The convenience methods (Self::new, Self::new_unseeded, etc.) bind to 0.0.0.0 for backwards compatibility. Use Self::builder to bind to a different address.

Fields§

§bootstrap: Vec<String>

bootstrapping nodes for this testnet.

§nodes: Vec<Dht>

all nodes in this testnet

Implementations§

Source§

impl Testnet

Source

pub fn builder(count: usize) -> TestnetBuilder

Returns a builder to configure and create a Testnet.

The builder defaults to binding to 127.0.0.1 (localhost).

§Example
let testnet = Testnet::builder(3).build().unwrap();
Source

pub fn new(count: usize) -> Result<Testnet, Error>

Create a new testnet with a certain size.

Note: this network will be shutdown as soon as this struct gets dropped, if you want the network to be 'static, then you should call Self::leak.

This will block until all nodes are seeded with local peers. If you are using an async runtime, consider using Self::new_async.

§Bind Address

Nodes are bound to 0.0.0.0 (all interfaces). Use Self::builder to bind to a different address.

Source

pub fn new_unseeded(count: usize) -> Result<Testnet, Error>

Create a new testnet without pre-seeding routing tables.

This is faster at startup, but nodes will not start with fully populated routing tables. Use this when your tests do not require immediate full connectivity.

§Bind Address

Nodes are bound to 0.0.0.0 (all interfaces). Use Self::builder with .seeded(false) to bind to a different address.

Source

pub async fn new_async(count: usize) -> Result<Testnet, Error>

Similar to Self::new, but available for async contexts.

§Bind Address

Nodes are bound to 0.0.0.0 (all interfaces). Use Self::builder to bind to a different address.

Source

pub async fn new_unseeded_async(count: usize) -> Result<Testnet, Error>

Similar to Self::new_unseeded, but available for async contexts.

§Bind Address

Nodes are bound to 0.0.0.0 (all interfaces). Use Self::builder with .seeded(false) to bind to a different address.

Source

pub fn leak(&self)

By default as soon as this testnet gets dropped, all the nodes get dropped and the entire network is shutdown.

This method uses Box::leak to keep nodes running, which is useful if you need to keep running the testnet in the process even if this struct gets dropped.

Trait Implementations§

Source§

impl Debug for Testnet

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more