Skip to main content

OutboundConnectionKeeper

Struct OutboundConnectionKeeper 

Source
pub struct OutboundConnectionKeeper<Z: NetworkZone, A, C> {
    pub new_peers_tx: Sender<Client<Z>>,
    pub make_connection_rx: Receiver<MakeConnectionRequest>,
    pub address_book_svc: A,
    pub connector_svc: C,
    pub outbound_semaphore: Arc<Semaphore>,
    pub extra_peers: usize,
    pub config: P2PConfig<Z>,
    pub peer_type_gen: Bernoulli,
    pub peer_sync_callback: Option<PeerSyncCallback>,
}
Expand description

The outbound connection count keeper.

This handles maintaining a minimum number of connections and making extra connections when needed, upto a maximum.

Fields§

§new_peers_tx: Sender<Client<Z>>

The pool of currently connected peers.

§make_connection_rx: Receiver<MakeConnectionRequest>

The channel that tells us to make new extra outbound connections.

§address_book_svc: A

The address book service

§connector_svc: C

The service to connect to a specific peer.

§outbound_semaphore: Arc<Semaphore>

A semaphore to keep the amount of outbound peers constant.

§extra_peers: usize

The amount of peers we connected to because we needed more peers. If the outbound_semaphore is full, and we need to connect to more peers for blocks or because not enough peers are ready we add a permit to the semaphore and keep track here, upto a value in config.

§config: P2PConfig<Z>

The p2p config.

§peer_type_gen: Bernoulli

The Bernoulli distribution, when sampled will return true if we should connect to a gray peer or false if we should connect to a white peer.

This is weighted to the percentage given in config.

§peer_sync_callback: Option<PeerSyncCallback>

A callback used to notify the syncer about peer sync state changes.

Implementations§

Source§

impl<Z, A, C> OutboundConnectionKeeper<Z, A, C>
where Z: NetworkZone, A: AddressBook<Z>, C: Service<ConnectRequest<Z>, Response = Client<Z>, Error = HandshakeError>, C::Future: Send + 'static,

Source

pub fn new( config: P2PConfig<Z>, new_peers_tx: Sender<Client<Z>>, make_connection_rx: Receiver<MakeConnectionRequest>, address_book_svc: A, connector_svc: C, peer_sync_callback: Option<PeerSyncCallback>, ) -> Self

Source

pub async fn run(self)

Runs the outbound connection count keeper.

Auto Trait Implementations§

§

impl<Z, A, C> !RefUnwindSafe for OutboundConnectionKeeper<Z, A, C>

§

impl<Z, A, C> !UnwindSafe for OutboundConnectionKeeper<Z, A, C>

§

impl<Z, A, C> Freeze for OutboundConnectionKeeper<Z, A, C>
where A: Freeze, C: Freeze, <Z as NetworkZone>::Addr: Freeze,

§

impl<Z, A, C> Send for OutboundConnectionKeeper<Z, A, C>
where A: Send, C: Send,

§

impl<Z, A, C> Sync for OutboundConnectionKeeper<Z, A, C>
where A: Sync, C: Sync,

§

impl<Z, A, C> Unpin for OutboundConnectionKeeper<Z, A, C>
where A: Unpin, C: Unpin,

§

impl<Z, A, C> UnsafeUnpin for OutboundConnectionKeeper<Z, A, C>

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> 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, 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.