Skip to main content

HandshakerBuilder

Struct HandshakerBuilder 

Source
pub struct HandshakerBuilder<N: NetworkZone, T: Transport<N>, AdrBook = DummyAddressBook, CSync = DummyCoreSyncSvc, ProtoHdlrMkr = MapErr<Shared<DummyProtocolRequestHandler>, fn(Infallible) -> BoxError>, BrdcstStrmMkr = fn(InternalPeerID<<N as NetworkZone>::Addr>) -> Pending<BroadcastMessage>> { /* private fields */ }
Expand description

A HandShaker Service builder.

This builder applies default values to make usage easier, behaviour and drawbacks of the defaults are documented on the with_* method to change it, for example HandshakerBuilder::with_protocol_request_handler_maker.

If you want to use any network other than Mainnet you will need to change the core sync service with HandshakerBuilder::with_core_sync_svc, see that method for details.

Implementations§

Source§

impl<N: NetworkZone, T: Transport<N>> HandshakerBuilder<N, T>

Source

pub fn new( our_basic_node_data: BasicNodeData, transport_client_config: T::ClientConfig, ) -> Self

Creates a new builder with our node’s basic node data.

Source§

impl<N: NetworkZone, T: Transport<N>, AdrBook, CSync, ProtoHdlr, BrdcstStrmMkr> HandshakerBuilder<N, T, AdrBook, CSync, ProtoHdlr, BrdcstStrmMkr>

Source

pub fn with_address_book<NAdrBook>( self, new_address_book: NAdrBook, ) -> HandshakerBuilder<N, T, NAdrBook, CSync, ProtoHdlr, BrdcstStrmMkr>
where NAdrBook: AddressBook<N> + Clone,

Changes the address book to the provided one.

§Default Address Book

The default address book is used if this function is not called.

The default address book’s only drawback is that it does not keep track of peers and therefore bans.

Source

pub fn with_core_sync_svc<NCSync>( self, new_core_sync_svc: NCSync, ) -> HandshakerBuilder<N, T, AdrBook, NCSync, ProtoHdlr, BrdcstStrmMkr>
where NCSync: CoreSyncSvc + Clone,

Changes the core sync service to the provided one.

The core sync service should keep track of our nodes core sync data.

§Default Core Sync Service

The default core sync service is used if this method is not called.

The default core sync service will just use the mainnet genesis block, to use other network’s genesis see DummyCoreSyncSvc::static_stagenet_genesis and DummyCoreSyncSvc::static_testnet_genesis. The drawbacks to keeping this the default is that it will always return the mainnet genesis as our nodes sync info, which means peers won’t know our actual chain height, this may or may not be a problem for different use cases.

Source

pub fn with_protocol_request_handler_maker<NProtoHdlrMkr>( self, new_protocol_request_svc_maker: NProtoHdlrMkr, ) -> HandshakerBuilder<N, T, AdrBook, CSync, NProtoHdlrMkr, BrdcstStrmMkr>
where NProtoHdlrMkr: ProtocolRequestHandlerMaker<N> + Clone,

Changes the protocol request handler maker, which creates the service that handles ProtocolRequests to our node.

§Default Protocol Request Handler

The default service maker will create services that will not respond to any protocol requests, this should not be an issue as long as peers do not think we are ahead of them, if they do they will send requests for our blocks, and we won’t respond which will cause them to disconnect.

Source

pub fn with_broadcast_stream_maker<NBrdcstStrmMkr, BrdcstStrm>( self, new_broadcast_stream_maker: NBrdcstStrmMkr, ) -> HandshakerBuilder<N, T, AdrBook, CSync, ProtoHdlr, NBrdcstStrmMkr>
where BrdcstStrm: Stream<Item = BroadcastMessage> + Send + 'static, NBrdcstStrmMkr: Fn(InternalPeerID<N::Addr>) -> BrdcstStrm + Clone + Send + 'static,

Changes the broadcast stream maker, which is used to create streams that yield messages to broadcast.

§Default Broadcast Stream Maker

The default broadcast stream maker just returns [stream::Pending], i.e. the returned stream will not produce any messages to broadcast, this is not a problem if your use case does not require broadcasting messages.

Source

pub fn with_peer_sync_callback(self, on_peer_sync: PeerSyncCallback) -> Self

Sets the callback invoked with a peer’s CoreSyncData.

§Default

No callback is set by default.

Source

pub fn with_connection_parent_span(self, connection_parent_span: Span) -> Self

Changes the parent [Span] of the connection task to the one provided.

§Default Connection Parent Span

The default connection span will be [Span::none].

Source

pub fn build(self) -> HandShaker<N, T, AdrBook, CSync, ProtoHdlr, BrdcstStrmMkr>

Builds the HandShaker.

Trait Implementations§

Source§

impl<N: Clone + NetworkZone, T: Clone + Transport<N>, AdrBook: Clone, CSync: Clone, ProtoHdlrMkr: Clone, BrdcstStrmMkr: Clone> Clone for HandshakerBuilder<N, T, AdrBook, CSync, ProtoHdlrMkr, BrdcstStrmMkr>
where T::ClientConfig: Clone,

Source§

fn clone( &self, ) -> HandshakerBuilder<N, T, AdrBook, CSync, ProtoHdlrMkr, BrdcstStrmMkr>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<N: Debug + NetworkZone, T: Debug + Transport<N>, AdrBook: Debug, CSync: Debug, ProtoHdlrMkr: Debug, BrdcstStrmMkr: Debug> Debug for HandshakerBuilder<N, T, AdrBook, CSync, ProtoHdlrMkr, BrdcstStrmMkr>
where T::ClientConfig: Debug,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<N, T, AdrBook = DummyAddressBook, CSync = DummyCoreSyncSvc, ProtoHdlrMkr = MapErr<Shared<DummyProtocolRequestHandler>, fn(Infallible) -> Box<dyn Error + Sync + Send>>, BrdcstStrmMkr = fn(InternalPeerID<<N as NetworkZone>::Addr>) -> Pending<BroadcastMessage>> !RefUnwindSafe for HandshakerBuilder<N, T, AdrBook, CSync, ProtoHdlrMkr, BrdcstStrmMkr>

§

impl<N, T, AdrBook = DummyAddressBook, CSync = DummyCoreSyncSvc, ProtoHdlrMkr = MapErr<Shared<DummyProtocolRequestHandler>, fn(Infallible) -> Box<dyn Error + Sync + Send>>, BrdcstStrmMkr = fn(InternalPeerID<<N as NetworkZone>::Addr>) -> Pending<BroadcastMessage>> !UnwindSafe for HandshakerBuilder<N, T, AdrBook, CSync, ProtoHdlrMkr, BrdcstStrmMkr>

§

impl<N, T, AdrBook, CSync, ProtoHdlrMkr, BrdcstStrmMkr> Freeze for HandshakerBuilder<N, T, AdrBook, CSync, ProtoHdlrMkr, BrdcstStrmMkr>
where AdrBook: Freeze, CSync: Freeze, ProtoHdlrMkr: Freeze, BrdcstStrmMkr: Freeze, <T as Transport<N>>::ClientConfig: Freeze,

§

impl<N, T, AdrBook, CSync, ProtoHdlrMkr, BrdcstStrmMkr> Send for HandshakerBuilder<N, T, AdrBook, CSync, ProtoHdlrMkr, BrdcstStrmMkr>
where AdrBook: Send, CSync: Send, ProtoHdlrMkr: Send, BrdcstStrmMkr: Send,

§

impl<N, T, AdrBook, CSync, ProtoHdlrMkr, BrdcstStrmMkr> Sync for HandshakerBuilder<N, T, AdrBook, CSync, ProtoHdlrMkr, BrdcstStrmMkr>
where AdrBook: Sync, CSync: Sync, ProtoHdlrMkr: Sync, BrdcstStrmMkr: Sync, N: Sync,

§

impl<N, T, AdrBook, CSync, ProtoHdlrMkr, BrdcstStrmMkr> Unpin for HandshakerBuilder<N, T, AdrBook, CSync, ProtoHdlrMkr, BrdcstStrmMkr>
where AdrBook: Unpin, CSync: Unpin, ProtoHdlrMkr: Unpin, BrdcstStrmMkr: Unpin, <T as Transport<N>>::ClientConfig: Unpin, N: Unpin,

§

impl<N, T, AdrBook, CSync, ProtoHdlrMkr, BrdcstStrmMkr> UnsafeUnpin for HandshakerBuilder<N, T, AdrBook, CSync, ProtoHdlrMkr, BrdcstStrmMkr>
where AdrBook: UnsafeUnpin, CSync: UnsafeUnpin, ProtoHdlrMkr: UnsafeUnpin, BrdcstStrmMkr: UnsafeUnpin, <T as Transport<N>>::ClientConfig: UnsafeUnpin,

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

Layout§

Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.