1- use std:: { fmt:: Display , sync :: Arc , time:: Duration } ;
1+ use std:: { fmt:: Display , time:: Duration } ;
22
33use bitcoin:: { FeeRate , Network } ;
44use p2p:: {
@@ -68,7 +68,7 @@ impl ConnectionConfig {
6868 self . network
6969 }
7070
71- /// Request the peer gossip new addresses at the beginning of the conneciton
71+ /// Request the peer gossip new addresses at the beginning of the connection
7272 pub fn request_addr ( mut self ) -> Self {
7373 self . request_addr = true ;
7474 self
@@ -172,10 +172,9 @@ impl ConnectionConfig {
172172 net_time_difference,
173173 reported_height : version. start_height ,
174174 } ;
175- let preferences = Arc :: new ( Preferences :: default ( ) ) ;
176175 let handshake = InitializedHandshake {
177176 feeler,
178- their_preferences : preferences ,
177+ their_preferences : Preferences :: default ( ) ,
179178 send_cmpct : self . send_cmpct ,
180179 fee_filter : self . fee_filter ,
181180 request_addr : self . request_addr ,
@@ -193,15 +192,15 @@ impl Default for ConnectionConfig {
193192#[ derive( Debug , Clone ) ]
194193pub ( crate ) struct InitializedHandshake {
195194 feeler : FeelerData ,
196- their_preferences : Arc < Preferences > ,
195+ their_preferences : Preferences ,
197196 fee_filter : FeeRate ,
198197 send_cmpct : SendCmpct ,
199198 request_addr : bool ,
200199}
201200
202201impl InitializedHandshake {
203202 pub ( crate ) fn negotiate (
204- & self ,
203+ & mut self ,
205204 message : NetworkMessage ,
206205 ) -> Result < Option < ( CompletedHandshake , Vec < NetworkMessage > ) > , Error > {
207206 match message {
@@ -216,25 +215,25 @@ impl InitializedHandshake {
216215 Ok ( Some ( (
217216 CompletedHandshake {
218217 feeler : self . feeler ,
219- their_preferences : Arc :: clone ( & self . their_preferences ) ,
218+ their_preferences : self . their_preferences ,
220219 } ,
221220 messages,
222221 ) ) )
223222 }
224223 NetworkMessage :: WtxidRelay => {
225- self . their_preferences . prefers_wtxid ( ) ;
224+ self . their_preferences . sendwtxid = true ;
226225 Ok ( None )
227226 }
228227 NetworkMessage :: SendAddrV2 => {
229- self . their_preferences . prefers_addrv2 ( ) ;
228+ self . their_preferences . sendaddrv2 = true ;
230229 Ok ( None )
231230 }
232231 NetworkMessage :: SendCmpct ( cmpct) => {
233- self . their_preferences . prefers_cmpct ( cmpct. version ) ;
232+ self . their_preferences . sendcmpct = cmpct;
234233 Ok ( None )
235234 }
236235 NetworkMessage :: SendHeaders => {
237- self . their_preferences . prefers_header_announcment ( ) ;
236+ self . their_preferences . sendheaders = true ;
238237 Ok ( None )
239238 }
240239 e => Err ( Error :: IrrelevantMessage ( e. command ( ) ) ) ,
@@ -245,7 +244,7 @@ impl InitializedHandshake {
245244#[ derive( Debug , Clone ) ]
246245pub ( crate ) struct CompletedHandshake {
247246 pub ( crate ) feeler : FeelerData ,
248- pub ( crate ) their_preferences : Arc < Preferences > ,
247+ pub ( crate ) their_preferences : Preferences ,
249248}
250249
251250/// Errors that occur during a handshake
@@ -307,7 +306,7 @@ mod tests {
307306 let connection_config = ConnectionConfig :: new ( ) ;
308307 let nonce = 43 ;
309308 let system_time = SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) . unwrap ( ) ;
310- let ( init_handshake, messages) = connection_config
309+ let ( mut init_handshake, messages) = connection_config
311310 . start_handshake ( system_time, NetworkMessage :: Version ( mock) , nonce)
312311 . unwrap ( ) ;
313312 let mut message_iter = messages. into_iter ( ) ;
@@ -333,9 +332,9 @@ mod tests {
333332 assert ! ( matches!( cmpct, NetworkMessage :: SendCmpct ( _) ) ) ;
334333 let fee_filter = message_iter. next ( ) . unwrap ( ) ;
335334 assert ! ( matches!( fee_filter, NetworkMessage :: FeeFilter ( _) ) ) ;
336- assert ! ( completed. their_preferences. wtxid ( ) ) ;
337- assert ! ( completed. their_preferences. addrv2 ( ) ) ;
338- assert ! ( !completed. their_preferences. announce_by_headers ( ) ) ;
335+ assert ! ( completed. their_preferences. sendwtxid ) ;
336+ assert ! ( completed. their_preferences. sendaddrv2 ) ;
337+ assert ! ( !completed. their_preferences. sendheaders ) ;
339338 }
340339
341340 #[ test]
@@ -382,7 +381,7 @@ mod tests {
382381 let connection_config = ConnectionConfig :: new ( ) . request_addr ( ) ;
383382 let nonce = 43 ;
384383 let system_time = SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) . unwrap ( ) ;
385- let ( init_handshake, _) = connection_config
384+ let ( mut init_handshake, _) = connection_config
386385 . start_handshake ( system_time, NetworkMessage :: Version ( mock) , nonce)
387386 . unwrap ( ) ;
388387 let ( _, messages) = init_handshake
0 commit comments