Skip to content

Commit

Permalink
fix mchannel links
Browse files Browse the repository at this point in the history
  • Loading branch information
ivcosla committed Mar 13, 2019
1 parent 6c16069 commit eb9f3ff
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
11 changes: 6 additions & 5 deletions pkg/messaging/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,14 @@ func (c *Client) Dial(ctx context.Context, remote cipher.PubKey) (transport.Tran
if err != nil {
return nil, fmt.Errorf("noise setup: %s", err)
}
channel.ID = clientLink.chans.add(channel)
localID := clientLink.chans.add(channel)

msg, err := channel.noise.HandshakeMessage()
if err != nil {
return nil, fmt.Errorf("noise handshake: %s", err)
}

if _, err := clientLink.link.SendOpenChannel(channel.ID, remote, msg); err != nil {
if _, err := clientLink.link.SendOpenChannel(localID, remote, msg); err != nil {
return nil, fmt.Errorf("failed to open channel: %s", err)
}

Expand All @@ -178,7 +178,7 @@ func (c *Client) Dial(ctx context.Context, remote cipher.PubKey) (transport.Tran
return nil, ctx.Err()
}

c.Logger.Infof("Opened new channel ID %d with %s", channel.ID, remote)
c.Logger.Infof("Opened new channel local ID %d, remote ID %d with %s", localID, channel.ID, remote)
return newAckedChannel(channel), nil
}

Expand Down Expand Up @@ -296,7 +296,7 @@ func (c *Client) onData(l *Link, frameType FrameType, body []byte) error {
} else {
c.Logger.Infof("Opened new channel local ID %d, remote ID %d with %s", lID, channelID,
hex.EncodeToString(body[1:34]))
_, sendErr = l.SendChannelOpened(lID, msg)
_, sendErr = l.SendChannelOpened(channelID, lID, msg)
}

return c.warnSendError(remotePK, sendErr)
Expand All @@ -316,7 +316,8 @@ func (c *Client) onData(l *Link, frameType FrameType, body []byte) error {
_, sendErr = l.SendChannelClosed(channel.ID)
c.Logger.Debugf("Closed channel ID %d", channelID)
case FrameTypeChannelOpened:
if err := channel.noise.ProcessMessage(body[1:]); err != nil {
channel.ID = body[1]
if err := channel.noise.ProcessMessage(body[2:]); err != nil {
sendErr = fmt.Errorf("noise handshake: %s", err)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/messaging/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (s *mockServer) onData(l *Link, frameType FrameType, body []byte) error {
case FrameTypeOpenChannel:
_, err = ol.SendOpenChannel(channelID, l.Remote(), body[34:])
case FrameTypeChannelOpened:
_, err = ol.SendChannelOpened(channelID, body[1:])
_, err = ol.SendChannelOpened(channelID, channelID, body[2:])
case FrameTypeCloseChannel:
l.SendChannelClosed(channelID) // nolint
_, err = ol.SendCloseChannel(channelID)
Expand Down
4 changes: 2 additions & 2 deletions pkg/messaging/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ func (c *Link) SendOpenChannel(channelID byte, remotePK cipher.PubKey, noiseMsg
}

// SendChannelOpened sends ChannelOpened frame.
func (c *Link) SendChannelOpened(channelID byte, noiseMsg []byte) (int, error) {
return c.writeFrame(FrameTypeChannelOpened, append([]byte{channelID}, noiseMsg...))
func (c *Link) SendChannelOpened(channelID byte, remoteID byte, noiseMsg []byte) (int, error) {
return c.writeFrame(FrameTypeChannelOpened, append([]byte{channelID, remoteID}, noiseMsg...))
}

// SendCloseChannel sends CloseChannel request.
Expand Down

0 comments on commit eb9f3ff

Please sign in to comment.