node: Connect to peers on startup

We run `maintain_connections` on initialization so that we're
immediately connected to some peers from our address book.
This commit is contained in:
cloudhead 2023-08-07 13:41:09 +02:00
parent 27865a26b2
commit 508cf4f68c
No known key found for this signature in database
2 changed files with 5 additions and 2 deletions

View File

@ -428,6 +428,8 @@ where
.repo_policies()?
.filter_map(|t| (t.policy == tracking::Policy::Track).then_some(t.id)),
);
// Try to establish some connections.
self.maintain_connections();
// Start periodic tasks.
self.outbox.wakeup(IDLE_INTERVAL);

View File

@ -1015,7 +1015,6 @@ fn test_maintain_connections() {
];
let mut alice = Peer::new("alice", [7, 7, 7, 7]);
alice.import_addresses(&unconnected);
for peer in connected.iter() {
alice.connect_to(peer);
@ -1023,8 +1022,10 @@ fn test_maintain_connections() {
assert_eq!(
connected.len(),
alice.sessions().len(),
"alice should be connected to all peers"
"alice should be connected to the first set of peers"
);
// We now import the other addresses.
alice.import_addresses(&unconnected);
// A transient error such as this will cause Alice to attempt a reconnection.
let error = Arc::new(io::Error::from(io::ErrorKind::ConnectionReset));