File tree Expand file tree Collapse file tree 1 file changed +28
-2
lines changed
Expand file tree Collapse file tree 1 file changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -10,8 +10,34 @@ use std::collections::BTreeMap;
1010pub struct Identity {
1111 pub name : NodeId ,
1212 pub networking_key : String ,
13- pub ws_routing : Option < ( String , u16 ) > ,
14- pub allowed_routers : Vec < NodeId > ,
13+ pub routing : NodeRouting ,
14+ }
15+
16+ #[ derive( Clone , Debug , Serialize , Deserialize ) ]
17+ pub enum NodeRouting {
18+ Routers ( Vec < NodeId > ) ,
19+ Direct {
20+ ip : String ,
21+ ports : BTreeMap < String , u16 > ,
22+ } ,
23+ }
24+
25+ impl Identity {
26+ pub fn is_direct ( & self ) -> bool {
27+ matches ! ( & self . routing, NodeRouting :: Direct { .. } )
28+ }
29+ pub fn get_protocol_port ( & self , protocol : & str ) -> Option < u16 > {
30+ match & self . routing {
31+ NodeRouting :: Routers ( _) => None ,
32+ NodeRouting :: Direct { ports, .. } => ports. get ( protocol) . cloned ( ) ,
33+ }
34+ }
35+ pub fn routers ( & self ) -> Option < & Vec < NodeId > > {
36+ match & self . routing {
37+ NodeRouting :: Routers ( routers) => Some ( routers) ,
38+ NodeRouting :: Direct { .. } => None ,
39+ }
40+ }
1541}
1642
1743/// Must be parsed from message pack vector.
You can’t perform that action at this time.
0 commit comments