Seen addresses store port (#1841)

## Issue Addressed
#1764
This commit is contained in:
divma
2020-11-09 04:01:03 +00:00
parent 63fe5542e7
commit b0e9e3dcef
6 changed files with 96 additions and 80 deletions

View File

@@ -1286,10 +1286,16 @@ pub fn serve<T: BeaconChainTypes>(
})?;
if let Some(peer_info) = network_globals.peers.read().peer_info(&peer_id) {
//TODO: update this to seen_addresses once #1764 is resolved
let address = match peer_info.listening_addresses.get(0) {
Some(addr) => addr.to_string(),
None => "".to_string(), // this field is non-nullable in the eth2 API spec
let address = if let Some(socket_addr) =
peer_info.seen_addresses.iter().next()
{
let mut addr = eth2_libp2p::Multiaddr::from(socket_addr.ip());
addr.push(eth2_libp2p::multiaddr::Protocol::Tcp(socket_addr.port()));
addr.to_string()
} else if let Some(addr) = peer_info.listening_addresses.first() {
addr.to_string()
} else {
String::new()
};
// the eth2 API spec implies only peers we have been connected to at some point should be included.
@@ -1297,7 +1303,7 @@ pub fn serve<T: BeaconChainTypes>(
return Ok(api_types::GenericResponse::from(api_types::PeerData {
peer_id: peer_id.to_string(),
enr: peer_info.enr.as_ref().map(|enr| enr.to_base64()),
last_seen_p2p_address: address,
address,
direction: api_types::PeerDirection::from_connection_direction(
&dir,
),
@@ -1330,16 +1336,23 @@ pub fn serve<T: BeaconChainTypes>(
// the eth2 API spec implies only peers we have been connected to at some point should be included.
.filter(|(_, peer_info)| peer_info.connection_direction.is_some())
.for_each(|(peer_id, peer_info)| {
//TODO: update this to seen_addresses once #1764 is resolved
let address = match peer_info.listening_addresses.get(0) {
Some(addr) => addr.to_string(),
None => "".to_string(), // this field is non-nullable in the eth2 API spec
let address = if let Some(socket_addr) =
peer_info.seen_addresses.iter().next()
{
let mut addr = eth2_libp2p::Multiaddr::from(socket_addr.ip());
addr.push(eth2_libp2p::multiaddr::Protocol::Tcp(socket_addr.port()));
addr.to_string()
} else if let Some(addr) = peer_info.listening_addresses.first() {
addr.to_string()
} else {
String::new()
};
if let Some(dir) = peer_info.connection_direction.as_ref() {
peers.push(api_types::PeerData {
peer_id: peer_id.to_string(),
enr: peer_info.enr.as_ref().map(|enr| enr.to_base64()),
last_seen_p2p_address: address,
address,
direction: api_types::PeerDirection::from_connection_direction(
&dir,
),

View File

@@ -37,7 +37,7 @@ const FINALIZED_EPOCH: u64 = 3;
const TCP_PORT: u16 = 42;
const UDP_PORT: u16 = 42;
const SEQ_NUMBER: u64 = 0;
const EXTERNAL_ADDR: &str = "/ip4/0.0.0.0";
const EXTERNAL_ADDR: &str = "/ip4/0.0.0.0/tcp/9000";
/// Skipping the slots around the epoch boundary allows us to check that we're obtaining states
/// from skipped slots for the finalized and justified checkpoints (instead of the state from the
@@ -162,10 +162,6 @@ impl ApiTester {
EXTERNAL_ADDR.parse().unwrap(),
None,
);
//TODO: have to update this once #1764 is resolved
if let Some(peer_info) = network_globals.peers.write().peer_info_mut(&peer_id) {
peer_info.listening_addresses = vec![EXTERNAL_ADDR.parse().unwrap()];
}
*network_globals.sync_state.write() = SyncState::Synced;
@@ -1115,7 +1111,7 @@ impl ApiTester {
let expected = PeerData {
peer_id: self.external_peer_id.to_string(),
enr: None,
last_seen_p2p_address: EXTERNAL_ADDR.to_string(),
address: EXTERNAL_ADDR.to_string(),
state: PeerState::Connected,
direction: PeerDirection::Inbound,
};
@@ -1131,7 +1127,7 @@ impl ApiTester {
let expected = PeerData {
peer_id: self.external_peer_id.to_string(),
enr: None,
last_seen_p2p_address: EXTERNAL_ADDR.to_string(),
address: EXTERNAL_ADDR.to_string(),
state: PeerState::Connected,
direction: PeerDirection::Inbound,
};