Skip to content

Commit 490f20b

Browse files
committed
ConnectivityEvent::Misbehaved was added back; a TODO was added in the place where it could be used in the future
1 parent 854be60 commit 490f20b

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

dns_server/src/crawler_p2p/crawler_manager/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,13 @@ where
219219
ConnectivityEvent::ConnectionClosed { peer_id } => {
220220
self.send_crawler_event(CrawlerEvent::Disconnected { peer_id });
221221
}
222+
ConnectivityEvent::Misbehaved {
223+
peer_id: _,
224+
error: _,
225+
} => {
226+
// Ignore all misbehave reports
227+
// TODO: Should we ban peers when they send unexpected messages?
228+
}
222229
}
223230
}
224231

p2p/src/net/default_backend/peer.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,11 @@ where
274274
// TODO: Use a bounded channel to send messages to the peer manager
275275
match msg.categorize() {
276276
CategorizedMessage::Handshake(_) => {
277-
log::error!("peer {peer} sent handshaking message");
277+
// TODO: this must be reported to the peer manager, so that it can adjust
278+
// the peer's ban score. (We may add a separate PeerEvent for this and Backend
279+
// can then use the now unused ConnectivityEvent::Misbehaved to forward the error
280+
// to the peer manager.)
281+
log::error!("Peer {peer} sent unexpected handshake message");
278282
}
279283
CategorizedMessage::PeerManagerMessage(msg) => {
280284
peer_event_tx.send((peer, PeerEvent::MessageReceived { message: msg }))?

p2p/src/net/types.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,15 @@ pub enum ConnectivityEvent {
157157
peer_id: PeerId,
158158
},
159159

160+
/// Protocol violation
161+
Misbehaved {
162+
/// Unique ID of the peer
163+
peer_id: PeerId,
164+
165+
/// Error code of the violation
166+
error: P2pError,
167+
},
168+
160169
/// Handshake failed
161170
HandshakeFailed {
162171
/// Peer's address

p2p/src/peer_manager/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,9 @@ where
12821282
ConnectivityEvent::ConnectionError { address, error } => {
12831283
self.handle_outbound_error(address, error);
12841284
}
1285+
ConnectivityEvent::Misbehaved { peer_id, error } => {
1286+
self.adjust_peer_score(peer_id, error.ban_score());
1287+
}
12851288
ConnectivityEvent::HandshakeFailed { address, error } => {
12861289
self.adjust_peer_score_on_failed_handshake(address, error.ban_score());
12871290
}

0 commit comments

Comments
 (0)