@@ -72,17 +72,17 @@ function parseNegotiatedResponse (buffer, log) {
72
72
return Number ( h [ 3 ] + '.' + h [ 2 ] )
73
73
}
74
74
75
- function newNegotiation ( channel , buffer , log ) {
75
+ function handshakeNegotiationV2 ( channel , buffer , log ) {
76
76
const numVersions = buffer . readVarInt ( )
77
77
let versions = [ ]
78
78
for ( let i = 0 ; i < numVersions ; i ++ ) {
79
- const h = [
79
+ const versionRange = [
80
80
buffer . readUInt8 ( ) ,
81
81
buffer . readUInt8 ( ) ,
82
82
buffer . readUInt8 ( ) ,
83
83
buffer . readUInt8 ( )
84
84
]
85
- versions = versions . concat ( getVersions ( h ) )
85
+ versions = versions . concat ( getVersions ( versionRange ) )
86
86
}
87
87
const capabilityBitMask = buffer . readVarInt ( )
88
88
const capabilites = selectCapabilites ( capabilityBitMask )
@@ -91,6 +91,7 @@ function newNegotiation (channel, buffer, log) {
91
91
// select preferrable protocol and respond
92
92
let major
93
93
let minor
94
+ versions . sort ( ( a , b ) => Number ( a . major + '.' + a . minor ) - Number ( b . major + '.' + b . minor ) )
94
95
for ( let i = 0 ; i < versions . length ; i ++ ) {
95
96
const version = versions [ i ]
96
97
if ( AVAILABLE_BOLT_PROTOCOLS . includes ( Number ( version . major + '.' + version . minor ) ) ) {
@@ -156,7 +157,7 @@ function newHandshakeBuffer () {
156
157
export default function handshake ( channel , log ) {
157
158
return initialHandshake ( channel , log ) . then ( ( result ) => {
158
159
if ( result . protocolVersion === 255.1 ) {
159
- return newNegotiation ( channel , result . buffer , log )
160
+ return handshakeNegotiationV2 ( channel , result . buffer , log )
160
161
} else {
161
162
return result
162
163
}
0 commit comments