blocksync tagging

This commit is contained in:
whyrusleeping 2019-12-16 22:15:06 -08:00
parent eb4077b1af
commit 28b470cb0d
3 changed files with 18 additions and 5 deletions

View File

@ -101,8 +101,13 @@ func (bs *BlockSync) GetBlocks(ctx context.Context, tsk types.TipSetKey, count i
}
if res.Status == 0 {
resp, err := bs.processBlocksResponse(req, res)
if err != nil {
return nil, xerrors.Errorf("success response from peer failed to process: %w", err)
}
bs.syncPeers.logGlobalSuccess(time.Since(start))
return bs.processBlocksResponse(req, res)
bs.host.ConnManager().TagPeer(p, "bsync", 2)
return resp, nil
}
oerr = bs.processStatus(req, res)
if oerr != nil {
@ -264,6 +269,10 @@ func (bs *BlockSync) sendRequestToPeer(ctx context.Context, p peer.ID, req *Bloc
}
func (bs *BlockSync) processBlocksResponse(req *BlockSyncRequest, res *BlockSyncResponse) ([]*types.TipSet, error) {
if len(res.Chain) == 0 {
return nil, xerrors.Errorf("got no blocks in successful blocksync response")
}
cur, err := types.NewTipSet(res.Chain[0].Blocks)
if err != nil {
return nil, err

View File

@ -155,7 +155,9 @@ func libp2p() Option {
Override(new(routing.Routing), lp2p.Routing),
Override(NatPortMapKey, lp2p.NatPortMap),
Override(ConnectionManagerKey, lp2p.ConnectionManager(50, 200, 20*time.Second)),
// TODO: how do i pass config.Libp2p.ProtectedPeers here?
Override(ConnectionManagerKey, lp2p.ConnectionManager(50, 200, 20*time.Second, nil)),
Override(new(*pubsub.PubSub), lp2p.GossipSub()),

View File

@ -69,13 +69,15 @@ func ConnectionManager(low, high int, grace time.Duration, protected []string) f
for _, p := range protected {
pid, err := peer.IDFromString(p)
if err != nil {
return nil, xerrors.Errorf("failed to parse peer ID in protected peers array: %w", err)
return Libp2pOpts{}, xerrors.Errorf("failed to parse peer ID in protected peers array: %w", err)
}
cm.Protect(pid, "config-prot")
}
opts.Opts = append(opts.Opts, libp2p.ConnectionManager(cm))
return
return Libp2pOpts{
Opts: []libp2p.Option{libp2p.ConnectionManager(cm)},
}, nil
}
}