@@ -472,9 +472,9 @@ impl From<RpcOut> for proto::RPC {
472472 }
473473}
474474
475- /// An RPC received/sent .
475+ /// A Gossipsub RPC message received.
476476#[ derive( Clone , PartialEq , Eq , Hash ) ]
477- pub struct Rpc {
477+ pub struct RpcIn {
478478 /// List of messages that were part of this RPC query.
479479 pub messages : Vec < RawMessage > ,
480480 /// List of subscriptions.
@@ -483,120 +483,7 @@ pub struct Rpc {
483483 pub control_msgs : Vec < ControlAction > ,
484484}
485485
486- impl Rpc {
487- /// Converts the GossipsubRPC into its protobuf format.
488- // A convenience function to avoid explicitly specifying types.
489- pub fn into_protobuf ( self ) -> proto:: RPC {
490- self . into ( )
491- }
492- }
493-
494- impl From < Rpc > for proto:: RPC {
495- /// Converts the RPC into protobuf format.
496- fn from ( rpc : Rpc ) -> Self {
497- // Messages
498- let mut publish = Vec :: new ( ) ;
499-
500- for message in rpc. messages . into_iter ( ) {
501- let message = proto:: Message {
502- from : message. source . map ( |m| m. to_bytes ( ) ) ,
503- data : Some ( message. data ) ,
504- seqno : message. sequence_number . map ( |s| s. to_be_bytes ( ) . to_vec ( ) ) ,
505- topic : TopicHash :: into_string ( message. topic ) ,
506- signature : message. signature ,
507- key : message. key ,
508- } ;
509-
510- publish. push ( message) ;
511- }
512-
513- // subscriptions
514- let subscriptions = rpc
515- . subscriptions
516- . into_iter ( )
517- . map ( |sub| proto:: SubOpts {
518- subscribe : Some ( sub. action == SubscriptionAction :: Subscribe ) ,
519- topic_id : Some ( sub. topic_hash . into_string ( ) ) ,
520- } )
521- . collect :: < Vec < _ > > ( ) ;
522-
523- // control messages
524- let mut control = proto:: ControlMessage {
525- ihave : Vec :: new ( ) ,
526- iwant : Vec :: new ( ) ,
527- graft : Vec :: new ( ) ,
528- prune : Vec :: new ( ) ,
529- idontwant : Vec :: new ( ) ,
530- } ;
531-
532- let empty_control_msg = rpc. control_msgs . is_empty ( ) ;
533-
534- for action in rpc. control_msgs {
535- match action {
536- // collect all ihave messages
537- ControlAction :: IHave ( IHave {
538- topic_hash,
539- message_ids,
540- } ) => {
541- let rpc_ihave = proto:: ControlIHave {
542- topic_id : Some ( topic_hash. into_string ( ) ) ,
543- message_ids : message_ids. into_iter ( ) . map ( |msg_id| msg_id. 0 ) . collect ( ) ,
544- } ;
545- control. ihave . push ( rpc_ihave) ;
546- }
547- ControlAction :: IWant ( IWant { message_ids } ) => {
548- let rpc_iwant = proto:: ControlIWant {
549- message_ids : message_ids. into_iter ( ) . map ( |msg_id| msg_id. 0 ) . collect ( ) ,
550- } ;
551- control. iwant . push ( rpc_iwant) ;
552- }
553- ControlAction :: Graft ( Graft { topic_hash } ) => {
554- let rpc_graft = proto:: ControlGraft {
555- topic_id : Some ( topic_hash. into_string ( ) ) ,
556- } ;
557- control. graft . push ( rpc_graft) ;
558- }
559- ControlAction :: Prune ( Prune {
560- topic_hash,
561- peers,
562- backoff,
563- } ) => {
564- let rpc_prune = proto:: ControlPrune {
565- topic_id : Some ( topic_hash. into_string ( ) ) ,
566- peers : peers
567- . into_iter ( )
568- . map ( |info| proto:: PeerInfo {
569- peer_id : info. peer_id . map ( |id| id. to_bytes ( ) ) ,
570- // TODO, see https://github.com/libp2p/specs/pull/217
571- signed_peer_record : None ,
572- } )
573- . collect ( ) ,
574- backoff,
575- } ;
576- control. prune . push ( rpc_prune) ;
577- }
578- ControlAction :: IDontWant ( IDontWant { message_ids } ) => {
579- let rpc_idontwant = proto:: ControlIDontWant {
580- message_ids : message_ids. into_iter ( ) . map ( |msg_id| msg_id. 0 ) . collect ( ) ,
581- } ;
582- control. idontwant . push ( rpc_idontwant) ;
583- }
584- }
585- }
586-
587- proto:: RPC {
588- subscriptions,
589- publish,
590- control : if empty_control_msg {
591- None
592- } else {
593- Some ( control)
594- } ,
595- }
596- }
597- }
598-
599- impl fmt:: Debug for Rpc {
486+ impl fmt:: Debug for RpcIn {
600487 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
601488 let mut b = f. debug_struct ( "GossipsubRpc" ) ;
602489 if !self . messages . is_empty ( ) {
0 commit comments