@@ -49,7 +49,7 @@ use sn_messaging::{
4949 section_info:: {
5050 Error as TargetSectionError , GetSectionResponse , Message as SectionInfoMsg , SectionInfo ,
5151 } ,
52- DstLocation , EndUser , Itinerary , MessageType , SrcLocation ,
52+ Aggregation , DstLocation , EndUser , Itinerary , MessageType , SrcLocation ,
5353} ;
5454use std:: { cmp, net:: SocketAddr , slice} ;
5555use tokio:: sync:: mpsc;
@@ -820,7 +820,7 @@ impl Approved {
820820 } ;
821821
822822 let bounce_dst_key = * self . section_key_by_name ( & src_name) ;
823- let bounce_dst = if msg. aggregate_at_src ( ) {
823+ let bounce_dst = if matches ! ( msg. aggregation ( ) , Aggregation :: AtSource ) {
824824 DstLocation :: Section ( src_name)
825825 } else {
826826 DstLocation :: Node ( src_name)
@@ -1002,46 +1002,39 @@ impl Approved {
10021002 message: MessageType :: ClientMessage ( ClientMessage :: from( content) ?) ,
10031003 } ] ) ;
10041004 }
1005- if msg. aggregate_at_dst ( ) {
1006- if !matches ! ( dst, DstLocation :: Node ( _) ) {
1007- return Err ( Error :: InvalidDstLocation ) ;
1008- }
1009- if let SrcAuthority :: BlsShare {
1010- proof_share,
1011- src_section,
1012- ..
1013- } = & src
1005+ if let SrcAuthority :: BlsShare {
1006+ proof_share,
1007+ src_section,
1008+ ..
1009+ } = & src
1010+ {
1011+ let signed_bytes = bincode:: serialize ( & msg. signable_view ( ) ) ?;
1012+ match self
1013+ . message_accumulator
1014+ . add ( & signed_bytes, proof_share. clone ( ) )
10141015 {
1015- let signed_bytes = bincode:: serialize ( & msg. signable_view ( ) ) ?;
1016- match self
1017- . message_accumulator
1018- . add ( & signed_bytes, proof_share. clone ( ) )
1019- {
1020- Ok ( proof) => {
1021- trace ! ( "Successfully aggregated signatures for message: {:?}" , msg) ;
1022- let key = msg. proof_chain_last_key ( ) ?;
1023- if key. verify ( & proof. signature , signed_bytes) {
1024- self . send_event ( Event :: MessageReceived {
1025- content,
1026- src : SrcLocation :: Section ( * src_section) ,
1027- dst,
1028- } ) ;
1029- } else {
1030- trace ! (
1031- "Aggregated signature is invalid. Handling message {:?} skipped" ,
1032- msg
1033- ) ;
1034- }
1035- }
1036- Err ( AggregatorError :: NotEnoughShares ) => { }
1037- Err ( err) => {
1038- trace ! ( "Error accumulating message at destination: {:?}" , err) ;
1016+ Ok ( proof) => {
1017+ trace ! ( "Successfully aggregated signatures for message: {:?}" , msg) ;
1018+ let key = msg. proof_chain_last_key ( ) ?;
1019+ if key. verify ( & proof. signature , signed_bytes) {
1020+ self . send_event ( Event :: MessageReceived {
1021+ content,
1022+ src : SrcLocation :: Section ( * src_section) ,
1023+ dst,
1024+ } ) ;
1025+ } else {
1026+ trace ! (
1027+ "Aggregated signature is invalid. Handling message {:?} skipped" ,
1028+ msg
1029+ ) ;
10391030 }
10401031 }
1041- return Ok ( vec ! [ ] ) ;
1042- } else {
1043- return Err ( Error :: InvalidSrcLocation ) ;
1032+ Err ( AggregatorError :: NotEnoughShares ) => { }
1033+ Err ( err) => {
1034+ trace ! ( "Error accumulating message at destination: {:?}" , err) ;
1035+ }
10441036 }
1037+ return Ok ( vec ! [ ] ) ;
10451038 }
10461039
10471040 self . send_event ( Event :: MessageReceived {
@@ -2036,53 +2029,60 @@ impl Approved {
20362029 Ok ( commands)
20372030 }
20382031
2039- pub fn send_user_message ( & mut self , itry : Itinerary , content : Bytes ) -> Result < Vec < Command > > {
2040- let are_we_src =
2041- matches ! ( itry. src, SrcLocation :: Node ( _) ) && itry. src . name ( ) == self . node . name ( ) ;
2032+ pub fn send_user_message (
2033+ & mut self ,
2034+ itinerary : Itinerary ,
2035+ content : Bytes ,
2036+ ) -> Result < Vec < Command > > {
2037+ let are_we_src = itinerary. src . equals ( & self . node . name ( ) )
2038+ || itinerary. src . equals ( & self . section ( ) . prefix ( ) . name ( ) ) ;
20422039 if !are_we_src {
20432040 error ! (
20442041 "Not sending user message {:?} -> {:?}: we are not the source location" ,
2045- itry . src, itry . dst
2042+ itinerary . src, itinerary . dst
20462043 ) ;
20472044 return Err ( Error :: InvalidSrcLocation ) ;
20482045 }
2049- if matches ! ( itry . src, SrcLocation :: EndUser ( _) ) {
2046+ if matches ! ( itinerary . src, SrcLocation :: EndUser ( _) ) {
20502047 return Err ( Error :: InvalidSrcLocation ) ;
20512048 }
2052- if matches ! ( itry . dst, DstLocation :: Direct ) {
2049+ if matches ! ( itinerary . dst, DstLocation :: Direct ) {
20532050 error ! (
20542051 "Not sending user message {:?} -> {:?}: direct dst not supported" ,
2055- itry . src, itry . dst
2052+ itinerary . src, itinerary . dst
20562053 ) ;
20572054 return Err ( Error :: InvalidDstLocation ) ;
20582055 }
20592056
2060- // If the source is a single node , we don't even need to vote, so let's cut this short .
2061- let msg = if itry . aggregate_at_dst ( ) {
2057+ // If the msg is to be aggregated at dst , we don't vote among our peers, wemsimply send the msg as our vote to the dst .
2058+ let msg = if itinerary . aggregate_at_dst ( ) {
20622059 Message :: for_dst_accumulation (
20632060 & self . node ,
20642061 self . section_keys_provider . key_share ( ) ?,
2065- itry . dst ,
2062+ itinerary . dst ,
20662063 content,
20672064 self . section ( ) . create_proof_chain_for_our_info ( None ) ,
20682065 None ,
20692066 self . section ( ) . prefix ( ) . name ( ) ,
20702067 ) ?
2071- } else if itry . aggregate_at_src ( ) {
2068+ } else if itinerary . aggregate_at_src ( ) {
20722069 let variant = Variant :: UserMessage ( content) ;
2073- let vote = self . create_send_message_vote ( itry . dst , variant, None ) ?;
2070+ let vote = self . create_send_message_vote ( itinerary . dst , variant, None ) ?;
20742071 let recipients = delivery_group:: signature_targets (
2075- & itry . dst ,
2072+ & itinerary . dst ,
20762073 self . section . elders_info ( ) . peers ( ) . copied ( ) ,
20772074 ) ;
20782075 return self . send_vote ( & recipients, vote) ;
20792076 } else {
20802077 let variant = Variant :: UserMessage ( content) ;
2081- Message :: single_src ( & self . node , itry . dst , variant, None , None ) ?
2078+ Message :: single_src ( & self . node , itinerary . dst , variant, None , None ) ?
20822079 } ;
20832080 let mut commands = vec ! [ ] ;
20842081
2085- if itry. dst . contains ( & self . node . name ( ) , self . section . prefix ( ) ) {
2082+ if itinerary
2083+ . dst
2084+ . contains ( & self . node . name ( ) , self . section . prefix ( ) )
2085+ {
20862086 commands. push ( Command :: HandleMessage {
20872087 sender : Some ( self . node . addr ) ,
20882088 message : msg. clone ( ) ,
0 commit comments