@@ -70,6 +70,7 @@ impl ConnectionContext {
7070 read_half : ReadHalf ,
7171 negotiation : Negotiation ,
7272 their_services : ServiceFlags ,
73+ their_version : ProtocolVerison ,
7374 ) -> Self {
7475 let read_ctx = ReadContext {
7576 read_half,
@@ -83,6 +84,7 @@ impl ConnectionContext {
8384 write_half,
8485 negotiation,
8586 their_services,
87+ their_protocol_verison : their_version,
8688 } ;
8789 Self {
8890 read_ctx,
@@ -210,6 +212,7 @@ pub struct WriteContext {
210212 write_half : WriteHalf ,
211213 negotiation : Negotiation ,
212214 their_services : ServiceFlags ,
215+ their_protocol_verison : ProtocolVerison ,
213216}
214217
215218impl WriteContext {
@@ -432,6 +435,12 @@ impl Default for Offered {
432435 }
433436}
434437
438+ #[ derive( Debug , Clone , Copy ) ]
439+ pub struct Feeler {
440+ pub services : ServiceFlags ,
441+ pub protocol_version : ProtocolVerison ,
442+ }
443+
435444pub ( crate ) struct MessageHeader {
436445 magic : Magic ,
437446 _command : CommandString ,
@@ -490,7 +499,7 @@ fn interpret_first_message(
490499 nonce : u64 ,
491500 their_expected_version : ProtocolVerison ,
492501 their_expected_services : ServiceFlags ,
493- ) -> Result < ( ) , HandshakeError > {
502+ ) -> Result < ( ProtocolVerison , ServiceFlags ) , HandshakeError > {
494503 if let NetworkMessage :: Version ( version) = message {
495504 if version. nonce . eq ( & nonce) {
496505 return Err ( HandshakeError :: ConnectedToSelf ) ;
@@ -503,10 +512,10 @@ fn interpret_first_message(
503512 if !version. services . has ( their_expected_services) {
504513 return Err ( HandshakeError :: UnsupportedFeature ) ;
505514 }
515+ Ok ( ( ProtocolVerison ( version. version ) , version. services ) )
506516 } else {
507- return Err ( HandshakeError :: IrrelevantMessage ( message) ) ;
517+ Err ( HandshakeError :: IrrelevantMessage ( message) )
508518 }
509- Ok ( ( ) )
510519}
511520
512521/// Errors when parsing a peer-to-peer message.
@@ -656,8 +665,15 @@ macro_rules! define_version_message_logic {
656665 let version = $awaiter!( read_half. read_message( & mut $reader) ) ?;
657666 match version {
658667 Some ( version) => {
659- interpret_first_message( version, nonce, $conn. their_version, $conn. their_services)
660- . map_err( ConnectionError :: Protocol ) ?;
668+ let ( protocol, services) = interpret_first_message(
669+ version,
670+ nonce,
671+ $conn. their_version,
672+ $conn. their_services,
673+ )
674+ . map_err( ConnectionError :: Protocol ) ?;
675+ $conn. their_services = services;
676+ $conn. their_version = protocol;
661677 }
662678 None => {
663679 return Err ( ConnectionError :: Protocol ( HandshakeError :: BadDecoy ) ) ;
@@ -717,8 +733,13 @@ macro_rules! define_version_message_logic {
717733 & mut write_half,
718734 ) ) ?;
719735 }
720- let context =
721- ConnectionContext :: new( write_half, read_half, negotiation, $conn. their_services) ;
736+ let context = ConnectionContext :: new(
737+ write_half,
738+ read_half,
739+ negotiation,
740+ $conn. their_services,
741+ $conn. their_version,
742+ ) ;
722743 Ok ( ( $reader, context) )
723744 } } ;
724745}
0 commit comments