pub struct Connector {
key_pair: KeyPair,
task_group: TaskGroup,
connection_slots: Arc<ConnectionSlots>,
max_retries: usize,
enable_tls: bool,
monitor: Arc<Monitor>,
}
Expand description
Responsible for creating outbound connections with other peers.
Fields§
§key_pair: KeyPair
Identity Key pair
task_group: TaskGroup
Managing spawned tasks.
connection_slots: Arc<ConnectionSlots>
Manages available outbound slots.
max_retries: usize
The maximum number of retries allowed before successfully establishing a connection.
enable_tls: bool
Enables secure connection.
monitor: Arc<Monitor>
Responsible for network and system monitoring.
Implementations§
Source§impl Connector
impl Connector
Sourcepub fn new(
key_pair: &KeyPair,
max_retries: usize,
connection_slots: Arc<ConnectionSlots>,
enable_tls: bool,
monitor: Arc<Monitor>,
ex: Executor,
) -> Arc<Self>
pub fn new( key_pair: &KeyPair, max_retries: usize, connection_slots: Arc<ConnectionSlots>, enable_tls: bool, monitor: Arc<Monitor>, ex: Executor, ) -> Arc<Self>
Creates a new Connector
Sourcepub async fn connect(
&self,
endpoint: &Endpoint,
peer_id: &Option<PeerID>,
) -> Result<Conn<NetMsg, Error>>
pub async fn connect( &self, endpoint: &Endpoint, peer_id: &Option<PeerID>, ) -> Result<Conn<NetMsg, Error>>
Establish a connection to the specified endpoint
. If the connection
attempt fails, it performs a backoff and retries until the maximum allowed
number of retries is exceeded. On a successful connection, it returns a
Conn
instance.
This method will block until it finds an available slot.
Sourcepub async fn connect_with_cback<Fut>(
self: &Arc<Self>,
endpoint: &Endpoint,
peer_id: &Option<PeerID>,
callback: impl FnOnce(Conn<NetMsg, Error>) -> Fut + Send + 'static,
) -> Result<()>
pub async fn connect_with_cback<Fut>( self: &Arc<Self>, endpoint: &Endpoint, peer_id: &Option<PeerID>, callback: impl FnOnce(Conn<NetMsg, Error>) -> Fut + Send + 'static, ) -> Result<()>
Establish a connection to the given endpoint
. For each new connection,
it invokes the provided callback
, and pass the connection to the callback.
async fn dial( &self, endpoint: &Endpoint, peer_id: &Option<PeerID>, ) -> Result<Conn<NetMsg, Error>>
Auto Trait Implementations§
impl !Freeze for Connector
impl !RefUnwindSafe for Connector
impl Send for Connector
impl Sync for Connector
impl Unpin for Connector
impl !UnwindSafe for Connector
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more