Skip to content

Commit 93ada99

Browse files
committed
Embed Protocol object in mini-protocol objects
Fixes #55
1 parent 5ed7991 commit 93ada99

File tree

7 files changed

+27
-27
lines changed

7 files changed

+27
-27
lines changed

protocol/blockfetch/blockfetch.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ var StateMap = protocol.StateMap{
6565
}
6666

6767
type BlockFetch struct {
68-
proto *protocol.Protocol
68+
*protocol.Protocol
6969
callbackConfig *BlockFetchCallbackConfig
7070
}
7171

@@ -98,7 +98,7 @@ func New(options protocol.ProtocolOptions, callbackConfig *BlockFetchCallbackCon
9898
StateMap: StateMap,
9999
InitialState: STATE_IDLE,
100100
}
101-
b.proto = protocol.New(protoConfig)
101+
b.Protocol = protocol.New(protoConfig)
102102
return b
103103
}
104104

@@ -121,12 +121,12 @@ func (b *BlockFetch) messageHandler(msg protocol.Message, isResponse bool) error
121121

122122
func (b *BlockFetch) RequestRange(start []interface{}, end []interface{}) error {
123123
msg := NewMsgRequestRange(start, end)
124-
return b.proto.SendMessage(msg, false)
124+
return b.SendMessage(msg, false)
125125
}
126126

127127
func (b *BlockFetch) ClientDone() error {
128128
msg := NewMsgClientDone()
129-
return b.proto.SendMessage(msg, false)
129+
return b.SendMessage(msg, false)
130130
}
131131

132132
func (b *BlockFetch) handleStartBatch() error {

protocol/chainsync/chainsync.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ var StateMap = protocol.StateMap{
8888
}
8989

9090
type ChainSync struct {
91-
proto *protocol.Protocol
91+
*protocol.Protocol
9292
callbackConfig *ChainSyncCallbackConfig
9393
}
9494

@@ -133,7 +133,7 @@ func New(options protocol.ProtocolOptions, callbackConfig *ChainSyncCallbackConf
133133
StateMap: StateMap,
134134
InitialState: STATE_IDLE,
135135
}
136-
c.proto = protocol.New(protoConfig)
136+
c.Protocol = protocol.New(protoConfig)
137137
return c
138138
}
139139

@@ -160,12 +160,12 @@ func (c *ChainSync) messageHandler(msg protocol.Message, isResponse bool) error
160160

161161
func (c *ChainSync) RequestNext() error {
162162
msg := NewMsgRequestNext()
163-
return c.proto.SendMessage(msg, false)
163+
return c.SendMessage(msg, false)
164164
}
165165

166166
func (c *ChainSync) FindIntersect(points []interface{}) error {
167167
msg := NewMsgFindIntersect(points)
168-
return c.proto.SendMessage(msg, false)
168+
return c.SendMessage(msg, false)
169169
}
170170

171171
func (c *ChainSync) handleAwaitReply() error {
@@ -180,7 +180,7 @@ func (c *ChainSync) handleRollForward(msgGeneric protocol.Message) error {
180180
if c.callbackConfig.RollForwardFunc == nil {
181181
return fmt.Errorf("received chain-sync RollForward message but no callback function is defined")
182182
}
183-
if c.proto.Mode() == protocol.ProtocolModeNodeToNode {
183+
if c.Mode() == protocol.ProtocolModeNodeToNode {
184184
msg := msgGeneric.(*MsgRollForwardNtN)
185185
var blockHeader interface{}
186186
var blockType uint

protocol/handshake/handshake.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ var StateMap = protocol.StateMap{
4848
}
4949

5050
type Handshake struct {
51-
proto *protocol.Protocol
51+
*protocol.Protocol
5252
allowedVersions []uint16
5353
Version uint16
5454
Finished chan bool
@@ -71,7 +71,7 @@ func New(options protocol.ProtocolOptions, allowedVersions []uint16) *Handshake
7171
StateMap: StateMap,
7272
InitialState: STATE_PROPOSE,
7373
}
74-
h.proto = protocol.New(protoConfig)
74+
h.Protocol = protocol.New(protoConfig)
7575
return h
7676
}
7777

@@ -94,14 +94,14 @@ func (h *Handshake) ProposeVersions(versions []uint16, networkMagic uint32) erro
9494
// Create our request
9595
versionMap := make(map[uint16]interface{})
9696
for _, version := range versions {
97-
if h.proto.Mode() == protocol.ProtocolModeNodeToNode {
97+
if h.Mode() == protocol.ProtocolModeNodeToNode {
9898
versionMap[version] = []interface{}{networkMagic, DIFFUSION_MODE_INITIATOR_ONLY}
9999
} else {
100100
versionMap[version] = networkMagic
101101
}
102102
}
103103
msg := NewMsgProposeVersions(versionMap)
104-
return h.proto.SendMessage(msg, false)
104+
return h.SendMessage(msg, false)
105105
}
106106

107107
func (h *Handshake) handleProposeVersions(msgGeneric protocol.Message) error {
@@ -121,7 +121,7 @@ func (h *Handshake) handleProposeVersions(msgGeneric protocol.Message) error {
121121
}
122122
if highestVersion > 0 {
123123
resp := NewMsgAcceptVersion(highestVersion, versionData)
124-
if err := h.proto.SendMessage(resp, true); err != nil {
124+
if err := h.SendMessage(resp, true); err != nil {
125125
return err
126126
}
127127
h.Version = highestVersion

protocol/keepalive/keepalive.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ var StateMap = protocol.StateMap{
4949
}
5050

5151
type KeepAlive struct {
52-
proto *protocol.Protocol
52+
*protocol.Protocol
5353
callbackConfig *KeepAliveCallbackConfig
5454
timer *time.Timer
5555
}
@@ -81,7 +81,7 @@ func New(options protocol.ProtocolOptions, callbackConfig *KeepAliveCallbackConf
8181
StateMap: StateMap,
8282
InitialState: STATE_CLIENT,
8383
}
84-
k.proto = protocol.New(protoConfig)
84+
k.Protocol = protocol.New(protoConfig)
8585
return k
8686
}
8787

@@ -103,7 +103,7 @@ func (k *KeepAlive) messageHandler(msg protocol.Message, isResponse bool) error
103103
func (k *KeepAlive) Start() {
104104
k.timer = time.AfterFunc(KEEP_ALIVE_PERIOD*time.Second, func() {
105105
if err := k.KeepAlive(0); err != nil {
106-
k.proto.SendError(err)
106+
k.SendError(err)
107107
}
108108
})
109109
}
@@ -118,7 +118,7 @@ func (k *KeepAlive) Stop() {
118118

119119
func (k *KeepAlive) KeepAlive(cookie uint16) error {
120120
msg := NewMsgKeepAlive(cookie)
121-
return k.proto.SendMessage(msg, false)
121+
return k.SendMessage(msg, false)
122122
}
123123

124124
func (k *KeepAlive) handleKeepAlive(msgGeneric protocol.Message) error {
@@ -129,7 +129,7 @@ func (k *KeepAlive) handleKeepAlive(msgGeneric protocol.Message) error {
129129
} else {
130130
// Send the keep-alive response
131131
resp := NewMsgKeepAliveResponse(msg.Cookie)
132-
return k.proto.SendMessage(resp, true)
132+
return k.SendMessage(resp, true)
133133
}
134134
}
135135

protocol/localstatequery/localstatequery.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ var StateMap = protocol.StateMap{
8585
}
8686

8787
type LocalStateQuery struct {
88-
proto *protocol.Protocol
88+
*protocol.Protocol
8989
callbackConfig *CallbackConfig
9090
}
9191

@@ -127,7 +127,7 @@ func New(options protocol.ProtocolOptions, callbackConfig *CallbackConfig) *Loca
127127
StateMap: StateMap,
128128
InitialState: STATE_IDLE,
129129
}
130-
l.proto = protocol.New(protoConfig)
130+
l.Protocol = protocol.New(protoConfig)
131131
return l
132132
}
133133

protocol/localtxsubmission/localtxsubmission.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var StateMap = protocol.StateMap{
4545
}
4646

4747
type LocalTxSubmission struct {
48-
proto *protocol.Protocol
48+
*protocol.Protocol
4949
callbackConfig *CallbackConfig
5050
}
5151

@@ -78,7 +78,7 @@ func New(options protocol.ProtocolOptions, callbackConfig *CallbackConfig) *Loca
7878
StateMap: StateMap,
7979
InitialState: STATE_IDLE,
8080
}
81-
l.proto = protocol.New(protoConfig)
81+
l.Protocol = protocol.New(protoConfig)
8282
return l
8383
}
8484

@@ -101,12 +101,12 @@ func (l *LocalTxSubmission) messageHandler(msg protocol.Message, isResponse bool
101101

102102
func (l *LocalTxSubmission) SubmitTx(eraId uint16, tx []byte) error {
103103
msg := NewMsgSubmitTx(eraId, tx)
104-
return l.proto.SendMessage(msg, false)
104+
return l.SendMessage(msg, false)
105105
}
106106

107107
func (l *LocalTxSubmission) Done(tx interface{}) error {
108108
msg := NewMsgDone()
109-
return l.proto.SendMessage(msg, false)
109+
return l.SendMessage(msg, false)
110110
}
111111

112112
func (l *LocalTxSubmission) handleSubmitTx(msgGeneric protocol.Message) error {

protocol/txsubmission/txsubmission.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ var StateMap = protocol.StateMap{
8989
}
9090

9191
type TxSubmission struct {
92-
proto *protocol.Protocol
92+
*protocol.Protocol
9393
callbackConfig *CallbackConfig
9494
}
9595

@@ -126,7 +126,7 @@ func New(options protocol.ProtocolOptions, callbackConfig *CallbackConfig) *TxSu
126126
StateMap: StateMap,
127127
InitialState: STATE_HELLO,
128128
}
129-
t.proto = protocol.New(protoConfig)
129+
t.Protocol = protocol.New(protoConfig)
130130
return t
131131
}
132132

0 commit comments

Comments
 (0)