File tree Expand file tree Collapse file tree 4 files changed +26
-5
lines changed Expand file tree Collapse file tree 4 files changed +26
-5
lines changed Original file line number Diff line number Diff line change @@ -30,9 +30,9 @@ const (
3030
3131// Refusal reasons
3232const (
33- RefuseReasonVersionMismatch = 0
34- RefuseReasonDecodeError = 1
35- RefuseReasonRefused = 2
33+ RefuseReasonVersionMismatch uint64 = 0
34+ RefuseReasonDecodeError uint64 = 1
35+ RefuseReasonRefused uint64 = 2
3636)
3737
3838// NewMsgFromCbor parses a Handshake message from CBOR
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ package handshake
1616
1717import (
1818 "fmt"
19+ "sort"
1920
2021 "github.com/blinklabs-io/gouroboros/protocol"
2122)
@@ -82,6 +83,12 @@ func (s *Server) handleProposeVersions(msg protocol.Message) error {
8283 for supportedVersion := range s .config .ProtocolVersionMap {
8384 supportedVersions = append (supportedVersions , supportedVersion )
8485 }
86+
87+ // sort asending - iterating over map is not deterministic
88+ sort .Slice (supportedVersions , func (i , j int ) bool {
89+ return supportedVersions [i ] < supportedVersions [j ]
90+ })
91+
8592 msgRefuse := NewMsgRefuse (
8693 []any {
8794 RefuseReasonVersionMismatch ,
Original file line number Diff line number Diff line change @@ -117,12 +117,12 @@ func TestServerHandshakeRefuseVersionMismatch(t *testing.T) {
117117 InputMessageType : handshake .MessageTypeRefuse ,
118118 InputMessage : handshake .NewMsgRefuse (
119119 []any {
120- uint64 ( handshake .RefuseReasonVersionMismatch ) ,
120+ handshake .RefuseReasonVersionMismatch ,
121121 // Convert []uint16 to []any
122122 func (in []uint16 ) []any {
123123 var ret []any
124124 for _ , item := range in {
125- ret = append (ret , item )
125+ ret = append (ret , uint64 ( item ) )
126126 }
127127 return ret
128128 }(protocol .GetProtocolVersionsNtC ()),
Original file line number Diff line number Diff line change 1414
1515package protocol
1616
17+ import "sort"
18+
1719// The NtC protocol versions have the 15th bit set in the handshake
1820const ProtocolVersionNtCOffset = 0x8000
1921
@@ -258,6 +260,12 @@ func GetProtocolVersionsNtC() []uint16 {
258260 versions = append (versions , key )
259261 }
260262 }
263+
264+ // sort asending - iterating over map is not deterministic
265+ sort .Slice (versions , func (i , j int ) bool {
266+ return versions [i ] < versions [j ]
267+ })
268+
261269 return versions
262270}
263271
@@ -269,6 +277,12 @@ func GetProtocolVersionsNtN() []uint16 {
269277 versions = append (versions , key )
270278 }
271279 }
280+
281+ // sort asending - iterating over map is not deterministic
282+ sort .Slice (versions , func (i , j int ) bool {
283+ return versions [i ] < versions [j ]
284+ })
285+
272286 return versions
273287}
274288
You can’t perform that action at this time.
0 commit comments