Skip to content

Commit 1777921

Browse files
committed
Offer inv after receiving every object we requested
1 parent cb8a5f3 commit 1777921

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ async-std = { version = "1.12.0", features = ["attributes"] }
1414
pretty_env_logger = "0.4.0"
1515
directories = "5.0.1"
1616
chrono = "0.4.24"
17+
18+
[profile.release]
19+
panic = "abort"

core/src/network/node/handler.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ impl Handler {
9090
self.inventory_repo
9191
.get_missing_objects(&mut inv)
9292
.await
93-
.expect("Repo not to fail");
93+
.expect("db won't fail");
9494
if !inv.is_empty() {
95+
log::debug!("requesting {} missing objects...", inv.len());
9596
return Some(NetworkMessage {
9697
command: MessageCommand::GetData,
9798
payload: MessagePayload::GetData { inventory: inv },
@@ -110,7 +111,7 @@ impl Handler {
110111

111112
for obj in objects {
112113
let hash_str = bs58::encode(&obj.hash).into_string();
113-
self.requested_objects.retain(|v| *v == hash_str);
114+
self.requested_objects.retain(|v| *v != hash_str);
114115

115116
if self
116117
.inventory_repo
@@ -119,7 +120,10 @@ impl Handler {
119120
.unwrap()
120121
.is_some()
121122
{
122-
log::debug!("object {hash_str} is already in the inventory, skipping it");
123+
log::debug!(
124+
"object {} is already in the inventory, skipping it",
125+
hash_str
126+
);
123127
continue;
124128
}
125129

@@ -131,19 +135,14 @@ impl Handler {
131135
let pow_check_res =
132136
pow::check_pow(target, BigUint::from_bytes_be(&obj.nonce), obj.hash.clone());
133137
if pow_check_res.is_err() {
134-
log::warn!(
135-
"object with hash {:?} has invalid nonce! skipping it",
136-
bs58::encode(obj.hash).into_string()
137-
);
138+
log::warn!("object {:?} has invalid nonce! skipping it", hash_str);
138139
continue;
139140
}
140141

141142
self.inventory_repo
142143
.store_object(obj.clone())
143144
.await
144-
.expect("repo not to fail");
145-
146-
self.offer_inv().await;
145+
.expect("db won't fail");
147146

148147
let handler_result = match &obj.kind {
149148
ObjectKind::Msg { encrypted: _ } => self.handle_msg_object(obj.clone()).await,
@@ -164,6 +163,8 @@ impl Handler {
164163
continue;
165164
}
166165
}
166+
167+
self.offer_inv().await;
167168
}
168169

169170
async fn handle_pubkey_object(&mut self, object: Object) -> Result<(), Box<dyn Error>> {

0 commit comments

Comments
 (0)