Skip to content

Commit b8c465e

Browse files
committed
Connect mode enable listen so that current node is connectable too
1 parent eaef166 commit b8c465e

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

src/lib.rs

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ impl BitcoinD {
145145
let p2p_socket = SocketAddrV4::new(LOCAL_IP, p2p_port);
146146
let p2p_arg = format!("-port={}", p2p_port);
147147
let connect = format!("-connect={}", other_node_url);
148-
let args = vec![p2p_arg, connect];
148+
let listen = "-listen=1".to_string(); // With connect specified listen is not defaulted to 1
149+
let args = vec![p2p_arg, connect, listen];
149150
(args, Some(p2p_socket))
150151
}
151152
};
@@ -336,8 +337,40 @@ mod test {
336337
assert_eq!(other_bitcoind.client.get_peer_info().unwrap().len(), 1);
337338
}
338339

339-
fn init() -> String {
340-
let _ = env_logger::try_init();
340+
#[test]
341+
fn test_multi_p2p() {
342+
let conf_node1 = Conf {
343+
p2p: P2P::Yes,
344+
..Default::default()
345+
};
346+
let node1 = BitcoinD::with_conf(exe_path(), &conf_node1).unwrap();
347+
348+
// Create Node 2 connected Node 1
349+
let conf_node2 = Conf {
350+
p2p: node1.p2p_connect().unwrap(),
351+
..Default::default()
352+
};
353+
let node2 = BitcoinD::with_conf(exe_path(), &conf_node2).unwrap();
354+
355+
// Create Node 3 Connected To Node 2
356+
let conf_node3 = Conf {
357+
p2p: node2.p2p_connect().unwrap(),
358+
..Default::default()
359+
};
360+
let node3 = BitcoinD::with_conf(exe_path(), &conf_node3).unwrap();
361+
362+
// Get each nodes Peers
363+
let node1_peers = node1.client.get_peer_info().unwrap();
364+
let node2_peers = node2.client.get_peer_info().unwrap();
365+
let node3_peers = node3.client.get_peer_info().unwrap();
366+
367+
// Peers found
368+
assert!(node1_peers.len() >= 1);
369+
assert!(node2_peers.len() >= 1);
370+
assert!(node3_peers.len() >= 1);
371+
}
372+
373+
fn exe_path() -> String {
341374
if let Some(downloaded_exe_path) = downloaded_exe_path() {
342375
downloaded_exe_path
343376
} else {
@@ -346,4 +379,9 @@ mod test {
346379
)
347380
}
348381
}
382+
383+
fn init() -> String {
384+
let _ = env_logger::try_init();
385+
exe_path()
386+
}
349387
}

0 commit comments

Comments
 (0)