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 {
273
273
fn is_connected ( & self , _addr : & SocketAddr ) -> Result < bool , NetworkControlError > {
274
274
Err ( NetworkControlError :: Disabled )
275
275
}
276
+
277
+ fn get_port ( & self ) -> Result < u16 , NetworkControlError > {
278
+ Err ( NetworkControlError :: Disabled )
279
+ }
276
280
}
277
281
278
282
fn 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 {
25
25
fn connect ( & self , addr : SocketAddr ) -> Result < ( ) , Error > ;
26
26
fn disconnect ( & self , addr : SocketAddr ) -> Result < ( ) , Error > ;
27
27
fn is_connected ( & self , addr : & SocketAddr ) -> Result < bool , Error > ;
28
+ fn get_port ( & self ) -> Result < u16 , Error > ;
28
29
}
29
30
30
31
#[ derive( Clone , Debug ) ]
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ pub struct Service {
35
35
timer : IoService < timer:: Message > ,
36
36
client : Arc < Client > ,
37
37
routing_table : Arc < RoutingTable > ,
38
+ socket_address : SocketAddr ,
38
39
}
39
40
40
41
impl Service {
@@ -68,6 +69,7 @@ impl Service {
68
69
timer,
69
70
client,
70
71
routing_table,
72
+ socket_address : address,
71
73
} ) )
72
74
}
73
75
@@ -126,6 +128,10 @@ impl Control for Service {
126
128
fn is_connected ( & self , addr : & SocketAddr ) -> Result < bool , ControlError > {
127
129
Ok ( self . routing_table . is_connected ( addr) )
128
130
}
131
+
132
+ fn get_port ( & self ) -> Result < u16 , ControlError > {
133
+ Ok ( self . socket_address . port ( ) )
134
+ }
129
135
}
130
136
131
137
#[ derive( Debug ) ]
Original file line number Diff line number Diff line change @@ -54,4 +54,8 @@ impl Net for NetClient {
54
54
fn is_connected ( & self , address : :: std:: net:: IpAddr , port : u16 ) -> Result < bool > {
55
55
Ok ( self . network_control . is_connected ( & SocketAddr :: new ( address, port) ) . map_err ( errors:: network_control) ?)
56
56
}
57
+
58
+ fn get_port ( & self ) -> Result < u16 > {
59
+ Ok ( self . network_control . get_port ( ) . map_err ( errors:: network_control) ?)
60
+ }
57
61
}
Original file line number Diff line number Diff line change @@ -30,5 +30,8 @@ build_rpc_trait! {
30
30
31
31
# [ rpc( name = "net_isConnected" ) ]
32
32
fn is_connected( & self , :: std:: net:: IpAddr , u16 ) -> Result <bool >;
33
+
34
+ # [ rpc( name = "net_getPort" ) ]
35
+ fn get_port( & self ) -> Result <u16 >;
33
36
}
34
37
}
You can’t perform that action at this time.
0 commit comments