Skip to content

Commit ba076a9

Browse files
Merge pull request #305 from boschresearch/302-wire-msg-types-rename
Rename wire message types
2 parents 99c04ed + 810b319 commit ba076a9

16 files changed

Lines changed: 222 additions & 210 deletions

client/channel.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func (c *Channel) initExchangeSigsAndEnable(ctx context.Context) error {
209209

210210
send := make(chan error)
211211
go func() {
212-
send <- c.conn.Send(ctx, &msgChannelUpdateAcc{
212+
send <- c.conn.Send(ctx, &ChannelUpdateAccMsg{
213213
ChannelID: c.ID(),
214214
Version: 0,
215215
Sig: sig,
@@ -220,7 +220,7 @@ func (c *Channel) initExchangeSigsAndEnable(ctx context.Context) error {
220220
if err != nil {
221221
return errors.WithMessage(err, "receiving initial state sig")
222222
}
223-
acc, ok := cm.(*msgChannelUpdateAcc)
223+
acc, ok := cm.(*ChannelUpdateAccMsg)
224224
if !ok {
225225
return errors.Errorf(
226226
"received unexpected message of type (%T) from peer[%d]: %v",

client/client.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,19 +171,19 @@ func (c *Client) Handle(ph ProposalHandler, uh UpdateHandler) {
171171
msg := env.Msg
172172

173173
switch msg := msg.(type) {
174-
case *LedgerChannelProposal:
174+
case *LedgerChannelProposalMsg:
175175
go c.handleChannelProposal(ph, env.Sender, msg)
176-
case *SubChannelProposal:
176+
case *SubChannelProposalMsg:
177177
go c.handleChannelProposal(ph, env.Sender, msg)
178-
case *VirtualChannelProposal:
178+
case *VirtualChannelProposalMsg:
179179
go c.handleChannelProposal(ph, env.Sender, msg)
180-
case *msgChannelUpdate:
180+
case *ChannelUpdateMsg:
181181
go c.handleChannelUpdate(uh, env.Sender, msg)
182-
case *virtualChannelFundingProposal:
182+
case *VirtualChannelFundingProposalMsg:
183183
go c.handleChannelUpdate(uh, env.Sender, msg)
184-
case *virtualChannelSettlementProposal:
184+
case *VirtualChannelSettlementProposalMsg:
185185
go c.handleChannelUpdate(uh, env.Sender, msg)
186-
case *msgChannelSync:
186+
case *ChannelSyncMsg:
187187
go c.handleSyncMsg(env.Sender, msg)
188188
default:
189189
c.log.Error("Unexpected %T message received in request loop")

client/proposal.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ func (c *Client) handleChannelProposalRej(
279279
ctx context.Context, p wire.Address,
280280
req ChannelProposal, reason string,
281281
) error {
282-
msgReject := &ChannelProposalRej{
282+
msgReject := &ChannelProposalRejMsg{
283283
ProposalID: req.ProposalID(),
284284
Reason: reason,
285285
}
@@ -310,7 +310,7 @@ func (c *Client) proposeTwoPartyChannel(
310310
acc, isAcc := e.Msg.(ChannelProposalAccept)
311311
return (isAcc && acc.Base().ProposalID == proposalID) ||
312312
(e.Msg.Type() == wire.ChannelProposalRej &&
313-
e.Msg.(*ChannelProposalRej).ProposalID == proposalID)
313+
e.Msg.(*ChannelProposalRejMsg).ProposalID == proposalID)
314314
}
315315
receiver := wire.NewReceiver()
316316
defer receiver.Close()
@@ -330,7 +330,7 @@ func (c *Client) proposeTwoPartyChannel(
330330
}
331331
return nil, errors.WithMessage(err, "receiving proposal response")
332332
}
333-
if rej, ok := env.Msg.(*ChannelProposalRej); ok {
333+
if rej, ok := env.Msg.(*ChannelProposalRejMsg); ok {
334334
return nil, newPeerRejectedError("channel proposal", rej.Reason)
335335
}
336336

@@ -384,11 +384,11 @@ func (c *Client) validTwoPartyProposal(
384384
}
385385

386386
switch prop := proposal.(type) {
387-
case *SubChannelProposal:
387+
case *SubChannelProposalMsg:
388388
if err := c.validSubChannelProposal(prop); err != nil {
389389
return errors.WithMessage(err, "validate subchannel proposal")
390390
}
391-
case *VirtualChannelProposal:
391+
case *VirtualChannelProposalMsg:
392392
if err := c.validVirtualChannelProposal(prop, ourIdx); err != nil {
393393
return errors.WithMessage(err, "validate subchannel proposal")
394394
}
@@ -397,7 +397,7 @@ func (c *Client) validTwoPartyProposal(
397397
return nil
398398
}
399399

400-
func (c *Client) validSubChannelProposal(proposal *SubChannelProposal) error {
400+
func (c *Client) validSubChannelProposal(proposal *SubChannelProposalMsg) error {
401401
parent, ok := c.channels.Channel(proposal.Parent)
402402
if !ok {
403403
return errors.New("parent channel does not exist")
@@ -417,7 +417,7 @@ func (c *Client) validSubChannelProposal(proposal *SubChannelProposal) error {
417417
return nil
418418
}
419419

420-
func (c *Client) validVirtualChannelProposal(prop *VirtualChannelProposal, ourIdx channel.Index) error {
420+
func (c *Client) validVirtualChannelProposal(prop *VirtualChannelProposalMsg, ourIdx channel.Index) error {
421421
numParents := len(prop.Parents)
422422
numPeers := prop.NumPeers()
423423
if numParents != numPeers {
@@ -569,9 +569,9 @@ func (c *Client) completeCPP(
569569

570570
func (c *Client) proposalParent(prop ChannelProposal, partIdx channel.Index) (parentChannelID *channel.ID, parent *Channel, err error) {
571571
switch prop := prop.(type) {
572-
case *SubChannelProposal:
572+
case *SubChannelProposalMsg:
573573
parentChannelID = &prop.Parent
574-
case *VirtualChannelProposal:
574+
case *VirtualChannelProposalMsg:
575575
parentChannelID = &prop.Parents[partIdx]
576576
}
577577

@@ -591,20 +591,20 @@ func (c *Client) mpcppParts(
591591
acc ChannelProposalAccept,
592592
) (parts []wallet.Address) {
593593
switch p := prop.(type) {
594-
case *LedgerChannelProposal:
594+
case *LedgerChannelProposalMsg:
595595
parts = participants(
596596
p.Participant,
597-
acc.(*LedgerChannelProposalAcc).Participant)
598-
case *SubChannelProposal:
597+
acc.(*LedgerChannelProposalAccMsg).Participant)
598+
case *SubChannelProposalMsg:
599599
ch, ok := c.channels.Channel(p.Parent)
600600
if !ok {
601601
c.log.Panic("unknown parent channel ID")
602602
}
603603
parts = ch.Params().Parts
604-
case *VirtualChannelProposal:
604+
case *VirtualChannelProposalMsg:
605605
parts = participants(
606606
p.Proposer,
607-
acc.(*VirtualChannelProposalAcc).Responder,
607+
acc.(*VirtualChannelProposalAccMsg).Responder,
608608
)
609609
default:
610610
c.log.Panicf("unhandled %T", p)
@@ -614,13 +614,13 @@ func (c *Client) mpcppParts(
614614

615615
func (c *Client) fundChannel(ctx context.Context, ch *Channel, prop ChannelProposal) error {
616616
switch prop := prop.(type) {
617-
case *LedgerChannelProposal:
617+
case *LedgerChannelProposalMsg:
618618
err := c.fundLedgerChannel(ctx, ch, prop.Base().FundingAgreement)
619619
return errors.WithMessage(err, "funding ledger channel")
620-
case *SubChannelProposal:
620+
case *SubChannelProposalMsg:
621621
err := c.fundSubchannel(ctx, prop, ch)
622622
return errors.WithMessage(err, "funding subchannel")
623-
case *VirtualChannelProposal:
623+
case *VirtualChannelProposalMsg:
624624
err := c.fundVirtualChannel(ctx, ch, prop)
625625
return errors.WithMessage(err, "funding virtual channel")
626626
}
@@ -657,7 +657,7 @@ func (c *Client) fundLedgerChannel(ctx context.Context, ch *Channel, agreement c
657657
return c.completeFunding(ctx, ch)
658658
}
659659

660-
func (c *Client) fundSubchannel(ctx context.Context, prop *SubChannelProposal, subChannel *Channel) (err error) {
660+
func (c *Client) fundSubchannel(ctx context.Context, prop *SubChannelProposalMsg, subChannel *Channel) (err error) {
661661
parentChannel, ok := c.channels.Channel(prop.Parent)
662662
if !ok {
663663
return errors.New("referenced parent channel not found")
@@ -684,7 +684,7 @@ func (c *Client) fundSubchannel(ctx context.Context, prop *SubChannelProposal, s
684684
func enableVer0Cache(c wire.Cacher) *wire.Predicate {
685685
p := func(m *wire.Envelope) bool {
686686
return m.Msg.Type() == wire.ChannelUpdateAcc &&
687-
m.Msg.(*msgChannelUpdateAcc).Version == 0
687+
m.Msg.(*ChannelUpdateAccMsg).Version == 0
688688
}
689689
c.Cache(&p)
690690
return &p

client/proposal_internal_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ func TestClient_validTwoPartyProposal(t *testing.T) {
4545
require.Len(t, validProp.Peers, 2)
4646

4747
validProp3Peers := NewRandomLedgerChannelProposal(rng, channeltest.WithNumParts(3))
48-
invalidProp := &LedgerChannelProposal{}
48+
invalidProp := &LedgerChannelProposalMsg{}
4949
*invalidProp = *validProp // shallow copy
5050
invalidProp.Base().ChallengeDuration = 0 // invalidate
5151

5252
tests := []struct {
53-
prop *LedgerChannelProposal
53+
prop *LedgerChannelProposalMsg
5454
ourIdx channel.Index
5555
peerAddr wallet.Address
5656
valid bool
@@ -104,7 +104,7 @@ func TestChannelProposal_assertValidNumParts(t *testing.T) {
104104

105105
func TestProposalResponder_Accept_Nil(t *testing.T) {
106106
p := new(ProposalResponder)
107-
_, err := p.Accept(nil, new(LedgerChannelProposalAcc)) //nolint:staticcheck
107+
_, err := p.Accept(nil, new(LedgerChannelProposalAccMsg)) //nolint:staticcheck
108108
assert.Error(t, err, "context")
109109
}
110110

@@ -149,11 +149,11 @@ func NewRandomBaseChannelProposal(rng *rand.Rand, opts ...channeltest.RandomOpt)
149149
return prop
150150
}
151151

152-
func NewRandomLedgerChannelProposal(rng *rand.Rand, opts ...channeltest.RandomOpt) *LedgerChannelProposal {
152+
func NewRandomLedgerChannelProposal(rng *rand.Rand, opts ...channeltest.RandomOpt) *LedgerChannelProposalMsg {
153153
opt := make(channeltest.RandomOpt).Append(opts...)
154154
base := NewRandomBaseChannelProposal(rng, opt)
155155
peers := wiretest.NewRandomAddresses(rng, base.NumPeers())
156-
return &LedgerChannelProposal{
156+
return &LedgerChannelProposalMsg{
157157
BaseChannelProposal: base,
158158
Participant: wallettest.NewRandomAddress(rng),
159159
Peers: peers,

0 commit comments

Comments
 (0)