|
46 | 46 |
|
47 | 47 | use core::hash; |
48 | 48 | use std::io::{Read, Write}; |
49 | | -use std::net::{IpAddr, Shutdown, SocketAddr, TcpStream}; |
| 49 | +use std::net::{Shutdown, SocketAddr, TcpStream}; |
50 | 50 | use std::sync::atomic::{AtomicU64, Ordering}; |
51 | 51 | use std::sync::Arc; |
52 | 52 | use std::thread::{self, JoinHandle}; |
53 | 53 |
|
54 | 54 | use crossbeam_channel::{select, Receiver, Sender, TryRecvError, TrySendError}; |
55 | 55 |
|
56 | 56 | use bitcoin::secp256k1::PublicKey; |
57 | | -use lightning::ln::msgs::{ChannelMessageHandler, NetAddress, RoutingMessageHandler}; |
| 57 | +use lightning::ln::msgs::{ChannelMessageHandler, RoutingMessageHandler}; |
58 | 58 | use lightning::ln::peer_handler::{ |
59 | 59 | CustomMessageHandler, PeerHandleError, PeerManager, SocketDescriptor, |
60 | 60 | }; |
@@ -132,7 +132,7 @@ where |
132 | 132 |
|
133 | 133 | // Generate a new ID that represents this connection |
134 | 134 | let conn_id = next_connection_id(); |
135 | | - let socket_addr = stream.peer_addr().unwrap(); |
| 135 | + let remote_addr = stream.peer_addr().ok().map(|sock_addr| sock_addr.into()); |
136 | 136 |
|
137 | 137 | // Init TcpReader, TcpWriter, TcpDisconnectooor |
138 | 138 | let writer_stream = stream.try_clone().unwrap(); |
@@ -174,10 +174,10 @@ where |
174 | 174 | // In all cases, return the result of the call into the PeerManager. |
175 | 175 | match conn_type { |
176 | 176 | ConnectionType::Inbound => { |
177 | | - peer_manager.new_inbound_connection(descriptor.clone(), Some(to_net(socket_addr))) |
| 177 | + peer_manager.new_inbound_connection(descriptor.clone(), remote_addr) |
178 | 178 | } |
179 | 179 | ConnectionType::Outbound(their_node_id) => peer_manager |
180 | | - .new_outbound_connection(their_node_id, descriptor.clone(), Some(to_net(socket_addr))) |
| 180 | + .new_outbound_connection(their_node_id, descriptor.clone(), remote_addr) |
181 | 181 | .map(|initial_data| { |
182 | 182 | // PeerManager accepted the outbound connection; queue up the |
183 | 183 | // initial WriteData WriterCommand. |
@@ -209,21 +209,6 @@ where |
209 | 209 | }) |
210 | 210 | } |
211 | 211 |
|
212 | | -// NOTE: It would be nice to have a `impl From<SocketAddr> for NetAddress` in |
213 | | -// the `lightning` crate |
214 | | -fn to_net(socket_addr: SocketAddr) -> NetAddress { |
215 | | - match socket_addr.ip() { |
216 | | - IpAddr::V4(ip) => NetAddress::IPv4 { |
217 | | - addr: ip.octets(), |
218 | | - port: socket_addr.port(), |
219 | | - }, |
220 | | - IpAddr::V6(ip) => NetAddress::IPv6 { |
221 | | - addr: ip.octets(), |
222 | | - port: socket_addr.port(), |
223 | | - }, |
224 | | - } |
225 | | -} |
226 | | - |
227 | 212 | /// Commands that can be sent to the Reader. |
228 | 213 | enum ReaderCommand { |
229 | 214 | ResumeRead, |
|
0 commit comments