Skip to content

Commit dfa1548

Browse files
authored
Merge pull request #265 from blinklabs-io/feat/protocol-identifiers-public
feat: make protocol identifiers public
2 parents 413a3fb + 34637fb commit dfa1548

File tree

20 files changed

+53
-53
lines changed

20 files changed

+53
-53
lines changed

protocol/chainsync/chainsync.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ import (
2424

2525
// Protocol identifiers
2626
const (
27-
protocolName = "chain-sync"
28-
protocolIdNtN uint16 = 2
29-
protocolIdNtC uint16 = 5
27+
ProtocolName = "chain-sync"
28+
ProtocolIdNtN uint16 = 2
29+
ProtocolIdNtC uint16 = 5
3030
)
3131

3232
var (

protocol/chainsync/client.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ type Client struct {
4040
// NewClient returns a new ChainSync client object
4141
func NewClient(protoOptions protocol.ProtocolOptions, cfg *Config) *Client {
4242
// Use node-to-client protocol ID
43-
protocolId := protocolIdNtC
43+
ProtocolId := ProtocolIdNtC
4444
msgFromCborFunc := NewMsgFromCborNtC
4545
if protoOptions.Mode == protocol.ProtocolModeNodeToNode {
4646
// Use node-to-node protocol ID
47-
protocolId = protocolIdNtN
47+
ProtocolId = ProtocolIdNtN
4848
msgFromCborFunc = NewMsgFromCborNtN
4949
}
5050
if cfg == nil {
@@ -72,8 +72,8 @@ func NewClient(protoOptions protocol.ProtocolOptions, cfg *Config) *Client {
7272
}
7373
// Configure underlying Protocol
7474
protoConfig := protocol.ProtocolConfig{
75-
Name: protocolName,
76-
ProtocolId: protocolId,
75+
Name: ProtocolName,
76+
ProtocolId: ProtocolId,
7777
Muxer: protoOptions.Muxer,
7878
ErrorChan: protoOptions.ErrorChan,
7979
Mode: protoOptions.Mode,
@@ -109,7 +109,7 @@ func (c *Client) messageHandler(msg protocol.Message, isResponse bool) error {
109109
case MessageTypeIntersectNotFound:
110110
err = c.handleIntersectNotFound(msg)
111111
default:
112-
err = fmt.Errorf("%s: received unexpected message type %d", protocolName, msg.Type())
112+
err = fmt.Errorf("%s: received unexpected message type %d", ProtocolName, msg.Type())
113113
}
114114
return err
115115
}

protocol/chainsync/messages.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func NewMsgFromCbor(protoMode protocol.ProtocolMode, msgType uint, data []byte)
6969
ret = &MsgDone{}
7070
}
7171
if _, err := cbor.Decode(data, ret); err != nil {
72-
return nil, fmt.Errorf("%s: decode error: %s", protocolName, err)
72+
return nil, fmt.Errorf("%s: decode error: %s", ProtocolName, err)
7373
}
7474
if ret != nil {
7575
// Store the raw message CBOR

protocol/chainsync/server.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ type Server struct {
2828
// NewServer returns a new ChainSync server object
2929
func NewServer(protoOptions protocol.ProtocolOptions, cfg *Config) *Server {
3030
// Use node-to-client protocol ID
31-
protocolId := protocolIdNtC
31+
ProtocolId := ProtocolIdNtC
3232
msgFromCborFunc := NewMsgFromCborNtC
3333
if protoOptions.Mode == protocol.ProtocolModeNodeToNode {
3434
// Use node-to-node protocol ID
35-
protocolId = protocolIdNtN
35+
ProtocolId = ProtocolIdNtN
3636
msgFromCborFunc = NewMsgFromCborNtN
3737
}
3838
s := &Server{
3939
config: cfg,
4040
}
4141
protoConfig := protocol.ProtocolConfig{
42-
Name: protocolName,
43-
ProtocolId: protocolId,
42+
Name: ProtocolName,
43+
ProtocolId: ProtocolId,
4444
Muxer: protoOptions.Muxer,
4545
ErrorChan: protoOptions.ErrorChan,
4646
Mode: protoOptions.Mode,
@@ -64,7 +64,7 @@ func (s *Server) messageHandler(msg protocol.Message, isResponse bool) error {
6464
case MessageTypeDone:
6565
err = s.handleDone()
6666
default:
67-
err = fmt.Errorf("%s: received unexpected message type %d", protocolName, msg.Type())
67+
err = fmt.Errorf("%s: received unexpected message type %d", ProtocolName, msg.Type())
6868
}
6969
return err
7070
}

protocol/handshake/client.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ func NewClient(protoOptions protocol.ProtocolOptions, cfg *Config) *Client {
4343
}
4444
// Configure underlying Protocol
4545
protoConfig := protocol.ProtocolConfig{
46-
Name: protocolName,
47-
ProtocolId: protocolId,
46+
Name: ProtocolName,
47+
ProtocolId: ProtocolId,
4848
Muxer: protoOptions.Muxer,
4949
ErrorChan: protoOptions.ErrorChan,
5050
Mode: protoOptions.Mode,
@@ -86,7 +86,7 @@ func (c *Client) handleMessage(msg protocol.Message, isResponse bool) error {
8686
case MessageTypeRefuse:
8787
err = c.handleRefuse(msg)
8888
default:
89-
err = fmt.Errorf("%s: received unexpected message type %d", protocolName, msg.Type())
89+
err = fmt.Errorf("%s: received unexpected message type %d", ProtocolName, msg.Type())
9090
}
9191
return err
9292
}
@@ -112,11 +112,11 @@ func (c *Client) handleRefuse(msgGeneric protocol.Message) error {
112112
var err error
113113
switch msg.Reason[0].(uint64) {
114114
case RefuseReasonVersionMismatch:
115-
err = fmt.Errorf("%s: version mismatch", protocolName)
115+
err = fmt.Errorf("%s: version mismatch", ProtocolName)
116116
case RefuseReasonDecodeError:
117-
err = fmt.Errorf("%s: decode error: %s", protocolName, msg.Reason[2].(string))
117+
err = fmt.Errorf("%s: decode error: %s", ProtocolName, msg.Reason[2].(string))
118118
case RefuseReasonRefused:
119-
err = fmt.Errorf("%s: refused: %s", protocolName, msg.Reason[2].(string))
119+
err = fmt.Errorf("%s: refused: %s", ProtocolName, msg.Reason[2].(string))
120120
}
121121
return err
122122
}

protocol/handshake/handshake.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import (
2323

2424
// Protocol identifiers
2525
const (
26-
protocolName = "handshake"
27-
protocolId = 0
26+
ProtocolName = "handshake"
27+
ProtocolId = 0
2828
)
2929

3030
// Diffusion modes

protocol/handshake/messages.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func NewMsgFromCbor(msgType uint, data []byte) (protocol.Message, error) {
4747
ret = &MsgRefuse{}
4848
}
4949
if _, err := cbor.Decode(data, ret); err != nil {
50-
return nil, fmt.Errorf("%s: decode error: %s", protocolName, err)
50+
return nil, fmt.Errorf("%s: decode error: %s", ProtocolName, err)
5151
}
5252
if ret != nil {
5353
// Store the raw message CBOR

protocol/handshake/server.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ func NewServer(protoOptions protocol.ProtocolOptions, cfg *Config) *Server {
3232
config: cfg,
3333
}
3434
protoConfig := protocol.ProtocolConfig{
35-
Name: protocolName,
36-
ProtocolId: protocolId,
35+
Name: ProtocolName,
36+
ProtocolId: ProtocolId,
3737
Muxer: protoOptions.Muxer,
3838
ErrorChan: protoOptions.ErrorChan,
3939
Mode: protoOptions.Mode,
@@ -53,7 +53,7 @@ func (s *Server) handleMessage(msg protocol.Message, isResponse bool) error {
5353
case MessageTypeProposeVersions:
5454
err = s.handleProposeVersions(msg)
5555
default:
56-
err = fmt.Errorf("%s: received unexpected message type %d", protocolName, msg.Type())
56+
err = fmt.Errorf("%s: received unexpected message type %d", ProtocolName, msg.Type())
5757
}
5858
return err
5959
}

protocol/localstatequery/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ func NewClient(protoOptions protocol.ProtocolOptions, cfg *Config) *Client {
6262
}
6363
// Configure underlying Protocol
6464
protoConfig := protocol.ProtocolConfig{
65-
Name: protocolName,
66-
ProtocolId: protocolId,
65+
Name: ProtocolName,
66+
ProtocolId: ProtocolId,
6767
Muxer: protoOptions.Muxer,
6868
ErrorChan: protoOptions.ErrorChan,
6969
Mode: protoOptions.Mode,
@@ -101,7 +101,7 @@ func (c *Client) messageHandler(msg protocol.Message, isResponse bool) error {
101101
case MessageTypeResult:
102102
err = c.handleResult(msg)
103103
default:
104-
err = fmt.Errorf("%s: received unexpected message type %d", protocolName, msg.Type())
104+
err = fmt.Errorf("%s: received unexpected message type %d", ProtocolName, msg.Type())
105105
}
106106
return err
107107
}

protocol/localstatequery/localstatequery.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import (
2323

2424
// Protocol identifiers
2525
const (
26-
protocolName = "local-state-query"
27-
protocolId uint16 = 7
26+
ProtocolName = "local-state-query"
27+
ProtocolId uint16 = 7
2828
)
2929

3030
var (

0 commit comments

Comments
 (0)