Skip to content

Commit 8555d74

Browse files
committed
fix: retrun early if sent_at or started_at missing
1 parent ba58a29 commit 8555d74

2 files changed

Lines changed: 62 additions & 52 deletions

File tree

Cargo.lock

Lines changed: 46 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/peerinfo/src/protocol.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,22 @@ impl ProtocolState {
147147
}
148148

149149
async fn validate_peer_info(&self, peer_info: &PeerInfo, rtt: Duration) {
150+
let Some(started_at) = peer_info.started_at else {
151+
warn!(
152+
peer = self.name,
153+
"Invalid peer info response: started at not provided"
154+
);
155+
return;
156+
};
157+
158+
let Some(sent_at) = peer_info.sent_at else {
159+
warn!(
160+
peer = self.name,
161+
"Invalid peer info response: sent at not provided"
162+
);
163+
return;
164+
};
165+
150166
let prev_nickname = {
151167
let mut nicknames = self.nicknames.lock();
152168
let prev_nickname = nicknames.get(&self.name).cloned();
@@ -165,10 +181,6 @@ impl ProtocolState {
165181
return;
166182
}
167183

168-
let Some(sent_at) = peer_info.sent_at else {
169-
warn!(peer = self.name, "Peer sent at not provided");
170-
return;
171-
};
172184
#[allow(
173185
clippy::cast_precision_loss,
174186
clippy::arithmetic_side_effects,
@@ -195,10 +207,6 @@ impl ProtocolState {
195207
// Set peer compatibility to true.
196208
PEERINFO_METRICS.version_support[&self.name].set(1);
197209

198-
let Some(started_at) = peer_info.started_at else {
199-
warn!(peer = self.name, "Invalid peer started at");
200-
return;
201-
};
202210
let Some(started_at) = chrono::DateTime::<chrono::Utc>::from_timestamp(
203211
started_at.seconds,
204212
u32::try_from(started_at.nanos).unwrap_or(0),

0 commit comments

Comments
 (0)