mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-06-19 06:25:58 +08:00
Merge branch 'develop' into fix/3400
This commit is contained in:
@@ -6097,6 +6097,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_http_response_type_codec() {
|
||||
let test_neighbors_info = RPCNeighborsInfo {
|
||||
bootstrap: vec![],
|
||||
sample: vec![
|
||||
RPCNeighbor {
|
||||
network_id: 1,
|
||||
@@ -6698,9 +6699,9 @@ mod test {
|
||||
#[test]
|
||||
fn test_http_duplicate_concurrent_streamed_response_fails() {
|
||||
// do not permit multiple in-flight chunk-encoded HTTP responses with the same request ID.
|
||||
let valid_neighbors_response = "HTTP/1.1 200 OK\r\nServer: stacks/v2.0\r\nX-Request-Id: 123\r\nContent-Type: application/json\r\nTransfer-Encoding: chunked\r\n\r\n28\r\n{\"sample\":[],\"inbound\":[],\"outbound\":[]}\r\n0\r\n\r\n";
|
||||
let valid_neighbors_response = "HTTP/1.1 200 OK\r\nServer: stacks/v2.0\r\nX-Request-Id: 123\r\nContent-Type: application/json\r\nTransfer-Encoding: chunked\r\n\r\n37\r\n{\"bootstrap\":[],\"sample\":[],\"inbound\":[],\"outbound\":[]}\r\n0\r\n\r\n";
|
||||
let invalid_neighbors_response = "HTTP/1.1 200 OK\r\nServer: stacks/v2.0\r\nX-Request-Id: 123\r\nContent-Type: application/json\r\nTransfer-Encoding: chunked\r\n\r\n10\r\nxxxxxxxxxxxxxxxx\r\n0\r\n\r\n";
|
||||
let invalid_chunked_response = "HTTP/1.1 200 OK\r\nServer: stacks/v2.0\r\nX-Request-Id: 123\r\nContent-Type: application/json\r\nTransfer-Encoding: chunked\r\n\r\n29\r\n{\"sample\":[],\"inbound\":[],\"outbound\":[]}\r\n0\r\n\r\n";
|
||||
let invalid_chunked_response = "HTTP/1.1 200 OK\r\nServer: stacks/v2.0\r\nX-Request-Id: 123\r\nContent-Type: application/json\r\nTransfer-Encoding: chunked\r\n\r\n38\r\n{\"bootstrap\":[],\"sample\":[],\"inbound\":[],\"outbound\":[]}\r\n0\r\n\r\n";
|
||||
|
||||
let mut http = StacksHttp::new("127.0.0.1:20443".parse().unwrap());
|
||||
|
||||
@@ -6731,6 +6732,7 @@ mod test {
|
||||
) => assert_eq!(
|
||||
neighbors_data,
|
||||
RPCNeighborsInfo {
|
||||
bootstrap: vec![],
|
||||
sample: vec![],
|
||||
inbound: vec![],
|
||||
outbound: vec![]
|
||||
|
||||
@@ -1401,6 +1401,7 @@ impl RPCNeighbor {
|
||||
/// Struct given back from a call to `/v2/neighbors`.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct RPCNeighborsInfo {
|
||||
pub bootstrap: Vec<RPCNeighbor>,
|
||||
pub sample: Vec<RPCNeighbor>,
|
||||
pub inbound: Vec<RPCNeighbor>,
|
||||
pub outbound: Vec<RPCNeighbor>,
|
||||
|
||||
@@ -444,6 +444,19 @@ impl RPCNeighborsInfo {
|
||||
chain_view: &BurnchainView,
|
||||
peerdb: &PeerDB,
|
||||
) -> Result<RPCNeighborsInfo, net_error> {
|
||||
let bootstrap_nodes =
|
||||
PeerDB::get_bootstrap_peers(peerdb.conn(), network_id).map_err(net_error::DBError)?;
|
||||
let bootstrap = bootstrap_nodes
|
||||
.into_iter()
|
||||
.map(|n| {
|
||||
RPCNeighbor::from_neighbor_key_and_pubkh(
|
||||
n.addr.clone(),
|
||||
Hash160::from_node_public_key(&n.public_key),
|
||||
true,
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
||||
let neighbor_sample = PeerDB::get_random_neighbors(
|
||||
peerdb.conn(),
|
||||
network_id,
|
||||
@@ -486,9 +499,10 @@ impl RPCNeighborsInfo {
|
||||
}
|
||||
|
||||
Ok(RPCNeighborsInfo {
|
||||
sample: sample,
|
||||
inbound: inbound,
|
||||
outbound: outbound,
|
||||
bootstrap,
|
||||
sample,
|
||||
inbound,
|
||||
outbound,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -4275,6 +4289,11 @@ mod test {
|
||||
HttpResponseType::Neighbors(response_md, neighbor_info) => {
|
||||
assert_eq!(neighbor_info.sample.len(), 1);
|
||||
assert_eq!(neighbor_info.sample[0].port, peer_client.config.server_port); // we see ourselves as the neighbor
|
||||
assert_eq!(neighbor_info.bootstrap.len(), 1);
|
||||
assert_eq!(
|
||||
neighbor_info.bootstrap[0].port,
|
||||
peer_client.config.server_port
|
||||
); // we see ourselves as the bootstrap
|
||||
true
|
||||
}
|
||||
_ => {
|
||||
|
||||
Reference in New Issue
Block a user