@@ -16,6 +16,7 @@ mod builder_states;
1616mod database;
1717mod light_client;
1818mod metrics;
19+ mod peer;
1920mod produce_block;
2021mod proposer_duties;
2122mod publish_attestations;
@@ -3022,15 +3023,13 @@ pub fn serve<T: BeaconChainTypes>(
30223023 } ;
30233024
30243025 // the eth2 API spec implies only peers we have been connected to at some point should be included.
3025- if let Some ( dir) = peer_info. connection_direction ( ) . as_ref ( ) {
3026+ if let Some ( & dir) = peer_info. connection_direction ( ) {
30263027 return Ok ( api_types:: GenericResponse :: from ( api_types:: PeerData {
30273028 peer_id : peer_id. to_string ( ) ,
30283029 enr : peer_info. enr ( ) . map ( |enr| enr. to_base64 ( ) ) ,
30293030 last_seen_p2p_address : address,
3030- direction : api_types:: PeerDirection :: from_connection_direction ( dir) ,
3031- state : api_types:: PeerState :: from_peer_connection_status (
3032- peer_info. connection_status ( ) ,
3033- ) ,
3031+ direction : dir. into ( ) ,
3032+ state : peer_info. connection_status ( ) . clone ( ) . into ( ) ,
30343033 } ) ) ;
30353034 }
30363035 }
@@ -3071,12 +3070,9 @@ pub fn serve<T: BeaconChainTypes>(
30713070 } ;
30723071
30733072 // the eth2 API spec implies only peers we have been connected to at some point should be included.
3074- if let Some ( dir) = peer_info. connection_direction ( ) {
3075- let direction =
3076- api_types:: PeerDirection :: from_connection_direction ( dir) ;
3077- let state = api_types:: PeerState :: from_peer_connection_status (
3078- peer_info. connection_status ( ) ,
3079- ) ;
3073+ if let Some ( & dir) = peer_info. connection_direction ( ) {
3074+ let direction = dir. into ( ) ;
3075+ let state = peer_info. connection_status ( ) . clone ( ) . into ( ) ;
30803076
30813077 let state_matches = query. state . as_ref ( ) . is_none_or ( |states| {
30823078 states. iter ( ) . any ( |state_param| * state_param == state)
@@ -3128,9 +3124,8 @@ pub fn serve<T: BeaconChainTypes>(
31283124 . read ( )
31293125 . peers ( )
31303126 . for_each ( |( _, peer_info) | {
3131- let state = api_types:: PeerState :: from_peer_connection_status (
3132- peer_info. connection_status ( ) ,
3133- ) ;
3127+ let state =
3128+ api_types:: PeerState :: from ( peer_info. connection_status ( ) . clone ( ) ) ;
31343129 match state {
31353130 api_types:: PeerState :: Connected => connected += 1 ,
31363131 api_types:: PeerState :: Connecting => connecting += 1 ,
@@ -4089,7 +4084,7 @@ pub fn serve<T: BeaconChainTypes>(
40894084 . peers
40904085 . read ( )
40914086 . peers ( )
4092- . map ( |( peer_id, peer_info) | eth2 :: lighthouse :: Peer {
4087+ . map ( |( peer_id, peer_info) | peer :: Peer {
40934088 peer_id : peer_id. to_string ( ) ,
40944089 peer_info : peer_info. clone ( ) ,
40954090 } )
@@ -4109,15 +4104,14 @@ pub fn serve<T: BeaconChainTypes>(
41094104 |task_spawner : TaskSpawner < T :: EthSpec > ,
41104105 network_globals : Arc < NetworkGlobals < T :: EthSpec > > | {
41114106 task_spawner. blocking_json_task ( Priority :: P1 , move || {
4112- Ok ( network_globals
4113- . peers
4114- . read ( )
4115- . connected_peers ( )
4116- . map ( |( peer_id, peer_info) | eth2:: lighthouse:: Peer {
4107+ let mut peers = vec ! [ ] ;
4108+ for ( peer_id, peer_info) in network_globals. peers . read ( ) . connected_peers ( ) {
4109+ peers. push ( peer:: Peer {
41174110 peer_id : peer_id. to_string ( ) ,
41184111 peer_info : peer_info. clone ( ) ,
4119- } )
4120- . collect :: < Vec < _ > > ( ) )
4112+ } ) ;
4113+ }
4114+ Ok ( peers)
41214115 } )
41224116 } ,
41234117 ) ;
0 commit comments