Skip to content
Merged
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
25 changes: 20 additions & 5 deletions crates/net/p2p/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,17 @@ pub(crate) struct PendingRequest {

// --- Swarm construction ---

/// [libp2p Behaviour](libp2p::swarm::NetworkBehaviour) combining Gossipsub and Request-Response Behaviours
/// [libp2p Behaviour](libp2p::swarm::NetworkBehaviour) combining identify, Gossipsub
/// and Request-Response Behaviours.
///
/// `identify` is registered purely for interop: go-libp2p (gean) gates gossipsub
/// GRAFT on the identify exchange completing, so a peer that doesn't respond to
/// `/ipfs/id/1.0.0` is silently excluded from the mesh. Events from this
/// behaviour are intentionally not handled: the registration alone is enough
/// to satisfy probing peers. ream and zeam follow the same pattern.
#[derive(NetworkBehaviour)]
pub(crate) struct Behaviour {
identify: libp2p::identify::Behaviour,
gossipsub: libp2p::gossipsub::Behaviour,
req_resp: request_response::Behaviour<Codec>,
}
Expand Down Expand Up @@ -150,17 +158,24 @@ pub fn build_swarm(
Default::default(),
);

let secret_key =
secp256k1::SecretKey::try_from_bytes(config.node_key).expect("invalid node key");
let identity = libp2p::identity::Keypair::from(secp256k1::Keypair::from(secret_key));

// Use the same `protocol_version` string as zeam
let identify = libp2p::identify::Behaviour::new(libp2p::identify::Config::new(
"/ipfs/0.1.0".to_owned(),
Comment thread
MegaRedHand marked this conversation as resolved.
identity.public(),
));

let behavior = Behaviour {
identify,
gossipsub,
req_resp,
};

// TODO: set peer scoring params

let secret_key =
secp256k1::SecretKey::try_from_bytes(config.node_key).expect("invalid node key");
let identity = libp2p::identity::Keypair::from(secp256k1::Keypair::from(secret_key));

let mut swarm = libp2p::SwarmBuilder::with_existing_identity(identity)
.with_tokio()
.with_quic()
Expand Down
Loading