|
78 | 78 | mod balance;
|
79 | 79 | mod builder;
|
80 | 80 | mod config;
|
| 81 | +mod connection; |
81 | 82 | mod error;
|
82 | 83 | mod event;
|
83 | 84 | mod fee_estimator;
|
@@ -124,6 +125,7 @@ use config::{
|
124 | 125 | LDK_PAYMENT_RETRY_TIMEOUT, NODE_ANN_BCAST_INTERVAL, PEER_RECONNECTION_INTERVAL,
|
125 | 126 | RGS_SYNC_INTERVAL, WALLET_SYNC_INTERVAL_MINIMUM_SECS,
|
126 | 127 | };
|
| 128 | +use connection::{connect_peer_if_necessary, do_connect_peer}; |
127 | 129 | use event::{EventHandler, EventQueue};
|
128 | 130 | use gossip::GossipSource;
|
129 | 131 | use liquidity::LiquiditySource;
|
@@ -1849,56 +1851,3 @@ pub struct NodeStatus {
|
1849 | 1851 | /// Will be `None` if we have no public channels or we haven't broadcasted since the [`Node`] was initialized.
|
1850 | 1852 | pub latest_node_announcement_broadcast_timestamp: Option<u64>,
|
1851 | 1853 | }
|
1852 |
| - |
1853 |
| -async fn connect_peer_if_necessary( |
1854 |
| - node_id: PublicKey, addr: SocketAddress, peer_manager: Arc<PeerManager>, |
1855 |
| - logger: Arc<FilesystemLogger>, |
1856 |
| -) -> Result<(), Error> { |
1857 |
| - if peer_manager.peer_by_node_id(&node_id).is_some() { |
1858 |
| - return Ok(()); |
1859 |
| - } |
1860 |
| - |
1861 |
| - do_connect_peer(node_id, addr, peer_manager, logger).await |
1862 |
| -} |
1863 |
| - |
1864 |
| -async fn do_connect_peer( |
1865 |
| - node_id: PublicKey, addr: SocketAddress, peer_manager: Arc<PeerManager>, |
1866 |
| - logger: Arc<FilesystemLogger>, |
1867 |
| -) -> Result<(), Error> { |
1868 |
| - log_info!(logger, "Connecting to peer: {}@{}", node_id, addr); |
1869 |
| - |
1870 |
| - let socket_addr = addr |
1871 |
| - .to_socket_addrs() |
1872 |
| - .map_err(|e| { |
1873 |
| - log_error!(logger, "Failed to resolve network address: {}", e); |
1874 |
| - Error::InvalidSocketAddress |
1875 |
| - })? |
1876 |
| - .next() |
1877 |
| - .ok_or(Error::ConnectionFailed)?; |
1878 |
| - |
1879 |
| - match lightning_net_tokio::connect_outbound(Arc::clone(&peer_manager), node_id, socket_addr) |
1880 |
| - .await |
1881 |
| - { |
1882 |
| - Some(connection_closed_future) => { |
1883 |
| - let mut connection_closed_future = Box::pin(connection_closed_future); |
1884 |
| - loop { |
1885 |
| - match futures::poll!(&mut connection_closed_future) { |
1886 |
| - std::task::Poll::Ready(_) => { |
1887 |
| - log_info!(logger, "Peer connection closed: {}@{}", node_id, addr); |
1888 |
| - return Err(Error::ConnectionFailed); |
1889 |
| - }, |
1890 |
| - std::task::Poll::Pending => {}, |
1891 |
| - } |
1892 |
| - // Avoid blocking the tokio context by sleeping a bit |
1893 |
| - match peer_manager.peer_by_node_id(&node_id) { |
1894 |
| - Some(_) => return Ok(()), |
1895 |
| - None => tokio::time::sleep(Duration::from_millis(10)).await, |
1896 |
| - } |
1897 |
| - } |
1898 |
| - }, |
1899 |
| - None => { |
1900 |
| - log_error!(logger, "Failed to connect to peer: {}@{}", node_id, addr); |
1901 |
| - Err(Error::ConnectionFailed) |
1902 |
| - }, |
1903 |
| - } |
1904 |
| -} |
0 commit comments