File tree Expand file tree Collapse file tree 5 files changed +18
-0
lines changed Expand file tree Collapse file tree 5 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -273,6 +273,10 @@ impl NetworkControl for DummyNetworkService {
273273 fn is_connected ( & self , _addr : & SocketAddr ) -> Result < bool , NetworkControlError > {
274274 Err ( NetworkControlError :: Disabled )
275275 }
276+
277+ fn get_port ( & self ) -> Result < u16 , NetworkControlError > {
278+ Err ( NetworkControlError :: Disabled )
279+ }
276280}
277281
278282fn run_node ( matches : ArgMatches ) -> Result < ( ) , String > {
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ pub trait Control: Send + Sync {
2525 fn connect ( & self , addr : SocketAddr ) -> Result < ( ) , Error > ;
2626 fn disconnect ( & self , addr : SocketAddr ) -> Result < ( ) , Error > ;
2727 fn is_connected ( & self , addr : & SocketAddr ) -> Result < bool , Error > ;
28+ fn get_port ( & self ) -> Result < u16 , Error > ;
2829}
2930
3031#[ derive( Clone , Debug ) ]
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ pub struct Service {
3535 timer : IoService < timer:: Message > ,
3636 client : Arc < Client > ,
3737 routing_table : Arc < RoutingTable > ,
38+ socket_address : SocketAddr ,
3839}
3940
4041impl Service {
@@ -68,6 +69,7 @@ impl Service {
6869 timer,
6970 client,
7071 routing_table,
72+ socket_address,
7173 } ) )
7274 }
7375
@@ -126,6 +128,10 @@ impl Control for Service {
126128 fn is_connected ( & self , addr : & SocketAddr ) -> Result < bool , ControlError > {
127129 Ok ( self . routing_table . is_connected ( addr) )
128130 }
131+
132+ fn get_port ( & self ) -> Result < u16 , ControlError > {
133+ Ok ( self . socket_address . port ( ) )
134+ }
129135}
130136
131137#[ derive( Debug ) ]
Original file line number Diff line number Diff line change @@ -54,4 +54,8 @@ impl Net for NetClient {
5454 fn is_connected ( & self , address : :: std:: net:: IpAddr , port : u16 ) -> Result < bool > {
5555 Ok ( self . network_control . is_connected ( & SocketAddr :: new ( address, port) ) . map_err ( errors:: network_control) ?)
5656 }
57+
58+ fn get_port ( & self ) -> Result < u16 > {
59+ Ok ( self . network_control . get_port ( ) . map_err ( errors:: network_control) ?)
60+ }
5761}
Original file line number Diff line number Diff line change @@ -30,5 +30,8 @@ build_rpc_trait! {
3030
3131 # [ rpc( name = "net_isConnected" ) ]
3232 fn is_connected( & self , :: std:: net:: IpAddr , u16 ) -> Result <bool >;
33+
34+ # [ rpc( name = "net_getPort" ) ]
35+ fn get_port( & self ) -> Result <u16 >;
3336 }
3437}
You can’t perform that action at this time.
0 commit comments