node: Small initialization changes

* Connect to nodes at the end, not the beginning
* Skip sync-status stuff if we're not seeding the repo
* Move debug message to be higher signal
This commit is contained in:
cloudhead 2023-12-11 16:29:39 +01:00
parent 472a1e6545
commit bfdf82a69a
No known key found for this signature in database
1 changed files with 11 additions and 8 deletions

View File

@ -510,11 +510,6 @@ where
) )
.expect("Service::initialize: error adding local node to address database"); .expect("Service::initialize: error adding local node to address database");
// Connect to configured peers.
let addrs = self.config.connect.clone();
for (id, addr) in addrs.into_iter().map(|ca| ca.into()) {
self.connect(id, addr);
}
// Ensure that our inventory is recorded in our routing table, and we are seeding // Ensure that our inventory is recorded in our routing table, and we are seeding
// all of it. It can happen that inventory is not properly seeded if for eg. the // all of it. It can happen that inventory is not properly seeded if for eg. the
// user creates a new repository while the node is stopped. // user creates a new repository while the node is stopped.
@ -529,8 +524,10 @@ where
for rid in rids { for rid in rids {
let repo = self.storage.repository(rid)?; let repo = self.storage.repository(rid)?;
// If we're not seeding this repo, just skip it.
if !self.policies.is_seeding(&rid)? { if !self.policies.is_seeding(&rid)? {
warn!(target: "service", "Local repository {rid} is not seeded"); warn!(target: "service", "Local repository {rid} is not seeded");
continue;
} }
// If we have no owned refs for this repo, then there's nothing to announce. // If we have no owned refs for this repo, then there's nothing to announce.
let Ok(updated_at) = SyncedAt::load(&repo, nid) else { let Ok(updated_at) = SyncedAt::load(&repo, nid) else {
@ -544,13 +541,14 @@ where
} }
} }
// Make sure our local node's sync status is up to date with storage. // Make sure our local node's sync status is up to date with storage.
debug!(target: "service", "Saving local sync status for {rid}.."); if self.db.seeds_mut().synced(
self.db.seeds_mut().synced(
&rid, &rid,
&nid, &nid,
updated_at.oid, updated_at.oid,
updated_at.timestamp.as_millis(), updated_at.timestamp.as_millis(),
)?; )? {
debug!(target: "service", "Saved local sync status for {rid}..");
}
// If we got here, it likely means a repo was updated while the node was stopped. // If we got here, it likely means a repo was updated while the node was stopped.
// Therefore, we pre-load a refs announcement for this repo, so that it is included in // Therefore, we pre-load a refs announcement for this repo, so that it is included in
@ -567,6 +565,11 @@ where
.seed_policies()? .seed_policies()?
.filter_map(|t| (t.policy == Policy::Allow).then_some(t.id)), .filter_map(|t| (t.policy == Policy::Allow).then_some(t.id)),
); );
// Connect to configured peers.
let addrs = self.config.connect.clone();
for (id, addr) in addrs.into_iter().map(|ca| ca.into()) {
self.connect(id, addr);
}
// Try to establish some connections. // Try to establish some connections.
self.maintain_connections(); self.maintain_connections();
// Start periodic tasks. // Start periodic tasks.