@@ -73,23 +73,26 @@ pub async fn start_p2p(
7373 let gossipsub = libp2p:: gossipsub:: Behaviour :: new ( MessageAuthenticity :: Anonymous , config)
7474 . expect ( "failed to initiate behaviour" ) ;
7575
76- let req_resp = request_response:: Behaviour :: new (
77- vec ! [
78- (
79- StreamProtocol :: new( STATUS_PROTOCOL_V1 ) ,
80- request_response:: ProtocolSupport :: Full ,
81- ) ,
82- (
83- StreamProtocol :: new( BLOCKS_BY_ROOT_PROTOCOL_V1 ) ,
84- request_response:: ProtocolSupport :: Full ,
85- ) ,
86- ] ,
76+ let status_req_resp = request_response:: Behaviour :: new (
77+ vec ! [ (
78+ StreamProtocol :: new( STATUS_PROTOCOL_V1 ) ,
79+ request_response:: ProtocolSupport :: Full ,
80+ ) ] ,
81+ Default :: default ( ) ,
82+ ) ;
83+
84+ let blocks_by_root_req_resp = request_response:: Behaviour :: new (
85+ vec ! [ (
86+ StreamProtocol :: new( BLOCKS_BY_ROOT_PROTOCOL_V1 ) ,
87+ request_response:: ProtocolSupport :: Full ,
88+ ) ] ,
8789 Default :: default ( ) ,
8890 ) ;
8991
9092 let behavior = Behaviour {
9193 gossipsub,
92- req_resp,
94+ status_req_resp,
95+ blocks_by_root_req_resp,
9396 } ;
9497
9598 // TODO: set peer scoring params
@@ -166,7 +169,8 @@ pub async fn start_p2p(
166169#[ derive( NetworkBehaviour ) ]
167170pub ( crate ) struct Behaviour {
168171 gossipsub : libp2p:: gossipsub:: Behaviour ,
169- req_resp : request_response:: Behaviour < Codec > ,
172+ status_req_resp : request_response:: Behaviour < Codec > ,
173+ blocks_by_root_req_resp : request_response:: Behaviour < req_resp:: Codec > ,
170174}
171175
172176pub ( crate ) struct P2PServer {
@@ -204,7 +208,10 @@ async fn event_loop(mut server: P2PServer) {
204208
205209async fn handle_swarm_event ( server : & mut P2PServer , event : SwarmEvent < BehaviourEvent > ) {
206210 match event {
207- SwarmEvent :: Behaviour ( BehaviourEvent :: ReqResp ( req_resp_event) ) => {
211+ SwarmEvent :: Behaviour ( BehaviourEvent :: StatusReqResp ( req_resp_event) ) => {
212+ req_resp:: handle_req_resp_message ( server, req_resp_event) . await ;
213+ }
214+ SwarmEvent :: Behaviour ( BehaviourEvent :: BlocksByRootReqResp ( req_resp_event) ) => {
208215 req_resp:: handle_req_resp_message ( server, req_resp_event) . await ;
209216 }
210217 SwarmEvent :: Behaviour ( BehaviourEvent :: Gossipsub (
@@ -228,7 +235,7 @@ async fn handle_swarm_event(server: &mut P2PServer, event: SwarmEvent<BehaviourE
228235 server
229236 . swarm
230237 . behaviour_mut ( )
231- . req_resp
238+ . status_req_resp
232239 . send_request ( & peer_id, Request :: Status ( our_status) ) ;
233240 } else {
234241 info ! ( %peer_id, %direction, "Added peer connection" ) ;
0 commit comments