Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@

- [#6430](https://github.com/ChainSafe/forest/issues/6430) Fixed a panic when syncing from genesis on the calibration network.

- [#6456](https://github.com/ChainSafe/forest/pull/6456) Whitelisted nebula and hermes crawlers.

## Forest v0.30.5 "Dulce de Leche"

Non-mandatory release supporting new API methods and addressing a critical panic issue.
Expand Down
33 changes: 32 additions & 1 deletion src/libp2p/peer_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,18 @@ impl PeerManager {
if self.is_peer_protected(&peer) {
return;
}

let user_agent = get_user_agent(&peer);
// Whitelist crawlers
if let Some(ua) = &user_agent
&& is_crawler(ua)
{
tracing::debug!("whitelisted crawler peer {peer} with user agent {ua}");
return;
}

let mut locked = self.peer_ban_list.write().await;
locked.insert(peer, duration.and_then(|d| Instant::now().checked_add(d)));
let user_agent = get_user_agent(&peer);
if let Err(e) = self
.peer_ops_tx
.send_async(PeerOperation::Ban {
Expand Down Expand Up @@ -333,3 +342,25 @@ pub enum PeerOperation {
},
Unban(PeerId),
}

fn is_crawler(user_agent: impl AsRef<str>) -> bool {
let ua = user_agent.as_ref();
ua.starts_with("nebula/") || ua.starts_with("hermes")
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_is_crawler() {
assert!(is_crawler("nebula/"));
assert!(is_crawler("nebula/1.0"));
assert!(is_crawler("hermes"));
assert!(is_crawler("hermes/1.0"));

assert!(!is_crawler("forest"));
assert!(!is_crawler("lotus"));
assert!(!is_crawler("venus"));
}
}
Loading