|
@@ -374,117 +374,6 @@ impl Slot {
|
|
|
Ok(())
|
|
Ok(())
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- //async fn run(self: Arc<Self>) {
|
|
|
|
|
- // // This is the main outbound connection loop where we try to establish
|
|
|
|
|
- // // a connection in the slot. The `try_connect` function will block in
|
|
|
|
|
- // // case the connection was sucessfully established. If it fails, then
|
|
|
|
|
- // // we will wait for a defined number of seconds and try to fill the
|
|
|
|
|
- // // slot again. This function should never exit during the lifetime of
|
|
|
|
|
- // // the P2P network, as it is supposed to represent an outbound slot we
|
|
|
|
|
- // // want to fill.
|
|
|
|
|
- // // The actual connection logic and peer selection is in `try_connect`.
|
|
|
|
|
- // // If the connection is successful, `try_connect` will wait for a stop
|
|
|
|
|
- // // signal and then exit. Once it exits, we'll run `try_connect` again
|
|
|
|
|
- // // and attempt to fill the slot with another peer.
|
|
|
|
|
- // let hosts = self.p2p().hosts();
|
|
|
|
|
- // loop {
|
|
|
|
|
- // // Activate the slot
|
|
|
|
|
- // debug!(
|
|
|
|
|
- // target: "net::outbound_session::try_connect()",
|
|
|
|
|
- // "[P2P] Finding a host to connect to for outbound slot #{}",
|
|
|
|
|
- // self.slot,
|
|
|
|
|
- // );
|
|
|
|
|
-
|
|
|
|
|
- // // Retrieve outbound transports
|
|
|
|
|
- // let transports = &self.p2p().settings().allowed_transports;
|
|
|
|
|
-
|
|
|
|
|
- // // Find a whitelisted address to connect to. We also do peer discovery here if needed.
|
|
|
|
|
- // // Start by looking up an anchorlist address we can connect to.
|
|
|
|
|
- // let (addr, _last_seen) = if let Some(addr) =
|
|
|
|
|
- // hosts.anchorlist_fetch_address_with_lock(self.p2p(), transports).await
|
|
|
|
|
- // {
|
|
|
|
|
- // addr
|
|
|
|
|
- // } else {
|
|
|
|
|
- // dnetev!(self, OutboundSlotSleeping, {
|
|
|
|
|
- // slot: self.slot,
|
|
|
|
|
- // });
|
|
|
|
|
-
|
|
|
|
|
- // self.wakeup_self.reset();
|
|
|
|
|
- // // Peer discovery
|
|
|
|
|
- // self.session().wakeup_peer_discovery();
|
|
|
|
|
- // // Wait to be woken up by peer discovery
|
|
|
|
|
- // self.wakeup_self.wait().await;
|
|
|
|
|
- // continue
|
|
|
|
|
- // };
|
|
|
|
|
-
|
|
|
|
|
- // info!(
|
|
|
|
|
- // target: "net::outbound_session::try_connect()",
|
|
|
|
|
- // "[P2P] Connecting outbound slot #{} [{}]",
|
|
|
|
|
- // self.slot, addr,
|
|
|
|
|
- // );
|
|
|
|
|
-
|
|
|
|
|
- // dnetev!(self, OutboundSlotConnecting, {
|
|
|
|
|
- // slot: self.slot,
|
|
|
|
|
- // addr: addr.clone(),
|
|
|
|
|
- // });
|
|
|
|
|
-
|
|
|
|
|
- // let (addr_final, channel) = match self.try_connect(addr.clone()).await {
|
|
|
|
|
- // Ok(connect_info) => connect_info,
|
|
|
|
|
- // Err(err) => {
|
|
|
|
|
- // error!(
|
|
|
|
|
- // target: "net::outbound_session",
|
|
|
|
|
- // "[P2P] Outbound slot #{} connection failed: {}",
|
|
|
|
|
- // self.slot, err,
|
|
|
|
|
- // );
|
|
|
|
|
-
|
|
|
|
|
- // dnetev!(self, OutboundSlotDisconnected, {
|
|
|
|
|
- // slot: self.slot,
|
|
|
|
|
- // err: err.to_string()
|
|
|
|
|
- // });
|
|
|
|
|
-
|
|
|
|
|
- // self.channel_id.store(0, Ordering::Relaxed);
|
|
|
|
|
- // continue
|
|
|
|
|
- // }
|
|
|
|
|
- // };
|
|
|
|
|
-
|
|
|
|
|
- // info!(
|
|
|
|
|
- // target: "net::outbound_session::try_connect()",
|
|
|
|
|
- // "[P2P] Outbound slot #{} connected [{}]",
|
|
|
|
|
- // self.slot, addr_final
|
|
|
|
|
- // );
|
|
|
|
|
-
|
|
|
|
|
- // dnetev!(self, OutboundSlotConnected, {
|
|
|
|
|
- // slot: self.slot,
|
|
|
|
|
- // addr: addr_final.clone(),
|
|
|
|
|
- // channel_id: channel.info.id
|
|
|
|
|
- // });
|
|
|
|
|
-
|
|
|
|
|
- // let stop_sub = channel.subscribe_stop().await.expect("Channel should not be stopped");
|
|
|
|
|
- // // Setup new channel
|
|
|
|
|
- // if let Err(err) = self.setup_channel(addr, channel.clone()).await {
|
|
|
|
|
- // info!(
|
|
|
|
|
- // target: "net::outbound_session",
|
|
|
|
|
- // "[P2P] Outbound slot #{} disconnected: {}",
|
|
|
|
|
- // self.slot, err
|
|
|
|
|
- // );
|
|
|
|
|
-
|
|
|
|
|
- // dnetev!(self, OutboundSlotDisconnected, {
|
|
|
|
|
- // slot: self.slot,
|
|
|
|
|
- // err: err.to_string()
|
|
|
|
|
- // });
|
|
|
|
|
-
|
|
|
|
|
- // self.channel_id.store(0, Ordering::Relaxed);
|
|
|
|
|
- // continue
|
|
|
|
|
- // }
|
|
|
|
|
-
|
|
|
|
|
- // self.channel_id.store(channel.info.id, Ordering::Relaxed);
|
|
|
|
|
-
|
|
|
|
|
- // // Wait for channel to close
|
|
|
|
|
- // stop_sub.receive().await;
|
|
|
|
|
- // self.channel_id.store(0, Ordering::Relaxed);
|
|
|
|
|
- // }
|
|
|
|
|
- //}
|
|
|
|
|
-
|
|
|
|
|
/// Start making an outbound connection, using provided [`Connector`].
|
|
/// Start making an outbound connection, using provided [`Connector`].
|
|
|
/// Tries to find a valid address to connect to, otherwise does peer
|
|
/// Tries to find a valid address to connect to, otherwise does peer
|
|
|
/// discovery. The peer discovery loops until some peer we can connect
|
|
/// discovery. The peer discovery loops until some peer we can connect
|