Skip to content

Commit

Permalink
Small changes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthieu Vachon committed Apr 3, 2019
1 parent ea8d35d commit f5b94e1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
8 changes: 6 additions & 2 deletions p2p/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ func (c *Catchup) sendSyncRequest(peer *Peer) error {
zap.Uint32("startBlock", c.requestedStartBlock),
zap.Uint32("endBlock", c.requestedEndBlock))

return errors.Wrapf(peer.SendSyncRequest(c.requestedStartBlock, c.requestedEndBlock+1),
"send sync request to %s", peer.Address)
err := peer.SendSyncRequest(c.requestedStartBlock, c.requestedEndBlock+1)
if err != nil {
return errors.Wrapf(err, "send sync request to %s", peer.Address)
}

return nil
}
16 changes: 12 additions & 4 deletions p2p/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,15 @@ func (p *Peer) WriteP2PMessage(message eos.P2PMessage) (err error) {
encoder := eos.NewEncoder(buff)
err = encoder.Encode(packet)
if err != nil {
return err
return errors.Wrapf(err, "unable to encode message %s", message)
}

_, err = p.Write(buff.Bytes())
if err != nil {
return errors.Wrapf(err, "write msg to %s", p.Address)
}

err = errors.Wrapf(err, "write msg to %s err when send : %s", p.Address, message)
return
return nil
}

func (p *Peer) SendSyncRequest(startBlockNum uint32, endBlockNumber uint32) (err error) {
Expand Down Expand Up @@ -298,5 +301,10 @@ func (p *Peer) SendHandshake(info *HandshakeInfo) error {
Generation: int16(1),
}

return errors.WithStack(p.WriteP2PMessage(handshake))
err = p.WriteP2PMessage(handshake)
if err != nil {
err = errors.Wrapf(err, "sending handshake to %s", p.Address)
}

return nil
}
7 changes: 7 additions & 0 deletions p2p/proxy.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package p2p

import (
"fmt"

"github.com/pkg/errors"

"go.uber.org/zap"
Expand Down Expand Up @@ -112,6 +114,11 @@ func (p *Proxy) Start() error {
go p.read(p.Peer2, p.Peer1, errorChannel)

if p.Peer2.handshakeInfo != nil {
err := triggerHandshake(p.Peer2)
if err != nil {
return fmt.Errorf("connect and start: trigger handshake: %s", err)
}

return errors.Wrap(triggerHandshake(p.Peer2),
"connect and start: trigger handshake")
}
Expand Down

0 comments on commit f5b94e1

Please sign in to comment.