Skip to content

Commit 5657fa0

Browse files
authored
Merge pull request #422 from blinklabs-io/feat/handshake-version-data-types
feat: types for handshake version data
2 parents f0d7bea + e81efd8 commit 5657fa0

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

protocol/handshake/client.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,24 @@ func (c *Client) Start() {
7474
if c.Mode() == protocol.ProtocolModeNodeToNode {
7575
if version >= 11 {
7676
// TODO: make peer sharing mode configurable once it actually works
77-
versionMap[version] = []interface{}{
78-
c.config.NetworkMagic,
79-
diffusionMode,
80-
PeerSharingModeNoPeerSharing,
81-
QueryModeDisabled,
77+
versionMap[version] = NtNVersionDataPeerSharingQuery{
78+
NetworkMagic: c.config.NetworkMagic,
79+
InitiatorAndResponderDiffusionMode: diffusionMode,
80+
PeerSharing: PeerSharingModeNoPeerSharing,
81+
Query: QueryModeDisabled,
8282
}
8383
} else {
84-
versionMap[version] = []interface{}{c.config.NetworkMagic, diffusionMode}
84+
versionMap[version] = NtNVersionDataLegacy{
85+
NetworkMagic: c.config.NetworkMagic,
86+
InitiatorAndResponderDiffusionMode: diffusionMode,
87+
}
8588
}
8689
} else {
8790
if (version - NodeToClientVersionOffset) >= 15 {
88-
versionMap[version] = []any{c.config.NetworkMagic, QueryModeDisabled}
91+
versionMap[version] = NtCVersionData{
92+
NetworkMagic: c.config.NetworkMagic,
93+
Query: QueryModeDisabled,
94+
}
8995
} else {
9096
versionMap[version] = c.config.NetworkMagic
9197
}
@@ -122,6 +128,8 @@ func (c *Client) handleAcceptVersion(msgGeneric protocol.Message) error {
122128
msg := msgGeneric.(*MsgAcceptVersion)
123129
fullDuplex := false
124130
if c.Mode() == protocol.ProtocolModeNodeToNode {
131+
// TODO: switch to using the VersionData types
132+
// this is more annoying than it would seem until we fix some other things
125133
versionData := msg.VersionData.([]interface{})
126134
//nolint:gosimple
127135
if versionData[1].(bool) == DiffusionModeInitiatorAndResponder {

protocol/handshake/versiondata.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package handshake
2+
3+
import "github.com/blinklabs-io/gouroboros/cbor"
4+
5+
type NtCVersionDataLegacy uint32
6+
7+
type NtCVersionData struct {
8+
cbor.StructAsArray
9+
NetworkMagic uint32
10+
Query bool
11+
}
12+
13+
type NtNVersionDataLegacy struct {
14+
cbor.StructAsArray
15+
NetworkMagic uint32
16+
InitiatorAndResponderDiffusionMode bool
17+
}
18+
19+
type NtNVersionDataPeerSharingQuery struct {
20+
cbor.StructAsArray
21+
NetworkMagic uint32
22+
InitiatorAndResponderDiffusionMode bool
23+
PeerSharing uint
24+
Query bool
25+
}

0 commit comments

Comments
 (0)