Skip to content

Commit

Permalink
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions pkg/chainsync/syncer/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ func (syncer *Syncer) HandleNewTipSet(ctx context.Context, target *syncTypes.Tar
return errors.New("do not sync to a target has synced before")
}

syncer.exchangeClient.AddPeer(target.Sender)
tipsets, err := syncer.fetchChainBlocks(ctx, head, target.Head)
if err != nil {
return errors.Wrapf(err, "failure fetching or validating headers")
Expand Down
24 changes: 22 additions & 2 deletions pkg/net/helloprotocol/hello_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ func (h *HelloProtocolHandler) handleNewStream(s net.Stream) {
time.Sleep(time.Millisecond * 300)
}

h.peerMgr.AddFilecoinPeer(from) //must add peer before get tipset, because have issue on 2k network

fullTipSet, err := h.loadLocalFullTipset(ctx, types.NewTipSetKey(hello.HeaviestTipSetCids...))
if err != nil {
fullTipSet, err = h.exchange.GetFullTipSet(ctx, []peer.ID{from}, types.NewTipSetKey(hello.HeaviestTipSetCids...)) //nolint
Expand Down Expand Up @@ -181,7 +183,6 @@ func (h *HelloProtocolHandler) handleNewStream(s net.Stream) {
}

// notify the local node of the new `block.ChainInfo`
h.peerMgr.AddFilecoinPeer(from)
ci := types.NewChainInfo(from, from, fullTipSet.TipSet())
h.peerDiscovered(ci)
}
Expand Down Expand Up @@ -309,6 +310,8 @@ func (hn *helloProtocolNotifiee) Connected(n net.Network, c net.Conn) {
return
}
defer func() { _ = s.Close() }()

t0 := time.Now()
// send out the hello message
err = hn.asHandler().sendHello(s)
if err != nil {
Expand All @@ -318,11 +321,28 @@ func (hn *helloProtocolNotifiee) Connected(n net.Network, c net.Conn) {
}

// now receive latency message
_, err = hn.asHandler().receiveLatency(ctx, s)
lmsg, err := hn.asHandler().receiveLatency(ctx, s)
if err != nil {
log.Debugf("failed to receive hello latency msg from peer %s: %s", c.RemotePeer(), err)
return
}

t3 := time.Now()
lat := t3.Sub(t0)
// add to peer tracker
hn.peerMgr.SetPeerLatency(s.Conn().RemotePeer(), lat)

if err == nil {
if lmsg.TArrival != 0 && lmsg.TSent != 0 {
t1 := time.Unix(0, lmsg.TArrival)
t2 := time.Unix(0, lmsg.TSent)
offset := t0.Sub(t1) + t3.Sub(t2)
offset /= 2
if offset > 5*time.Second || offset < -5*time.Second {
log.Infow("time offset", "offset", offset.Seconds(), "peerid", c.RemotePeer().String())
}
}
}
}()
}

Expand Down

0 comments on commit a6289d0

Please sign in to comment.