Initial pass at a peer manager
This commit is contained in:
committed by
Łukasz Magiera
parent
ec5e075fa8
commit
fc7c7ddd97
@@ -37,6 +37,7 @@ import (
|
||||
"github.com/filecoin-project/lotus/node/modules/testing"
|
||||
"github.com/filecoin-project/lotus/node/repo"
|
||||
"github.com/filecoin-project/lotus/paych"
|
||||
"github.com/filecoin-project/lotus/peermgr"
|
||||
"github.com/filecoin-project/lotus/retrieval"
|
||||
"github.com/filecoin-project/lotus/retrieval/discovery"
|
||||
"github.com/filecoin-project/lotus/storage"
|
||||
@@ -78,6 +79,7 @@ const (
|
||||
|
||||
RunHelloKey
|
||||
RunBlockSyncKey
|
||||
RunPeerMgrKey
|
||||
|
||||
HandleIncomingBlocksKey
|
||||
HandleIncomingMessagesKey
|
||||
@@ -227,8 +229,11 @@ func Online() Option {
|
||||
|
||||
Override(new(*hello.Service), hello.NewHelloService),
|
||||
Override(new(*chain.BlockSyncService), chain.NewBlockSyncService),
|
||||
Override(new(*peermgr.PeerMgr), peermgr.NewPeerMgr),
|
||||
|
||||
Override(RunHelloKey, modules.RunHello),
|
||||
Override(RunBlockSyncKey, modules.RunBlockSync),
|
||||
Override(RunPeerMgrKey, modules.RunPeerMgr),
|
||||
Override(HandleIncomingBlocksKey, modules.HandleIncomingBlocks),
|
||||
Override(HeadMetricsKey, metrics.SendHeadNotifs("")),
|
||||
|
||||
|
||||
+7
-2
@@ -3,7 +3,6 @@ package hello
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
|
||||
"github.com/ipfs/go-cid"
|
||||
cbor "github.com/ipfs/go-ipld-cbor"
|
||||
@@ -14,7 +13,9 @@ import (
|
||||
|
||||
"github.com/filecoin-project/lotus/chain"
|
||||
"github.com/filecoin-project/lotus/chain/store"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/lib/cborrpc"
|
||||
"github.com/filecoin-project/lotus/peermgr"
|
||||
)
|
||||
|
||||
const ProtocolID = "/fil/hello/1.0.0"
|
||||
@@ -36,14 +37,16 @@ type Service struct {
|
||||
|
||||
cs *store.ChainStore
|
||||
syncer *chain.Syncer
|
||||
pmgr *peermgr.PeerMgr
|
||||
}
|
||||
|
||||
func NewHelloService(h host.Host, cs *store.ChainStore, syncer *chain.Syncer) *Service {
|
||||
func NewHelloService(h host.Host, cs *store.ChainStore, syncer *chain.Syncer, pmgr *peermgr.PeerMgr) *Service {
|
||||
return &Service{
|
||||
newStream: h.NewStream,
|
||||
|
||||
cs: cs,
|
||||
syncer: syncer,
|
||||
pmgr: pmgr,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +77,7 @@ func (hs *Service) HandleStream(s inet.Stream) {
|
||||
|
||||
log.Infof("Got new tipset through Hello: %s from %s", ts.Cids(), s.Conn().RemotePeer())
|
||||
hs.syncer.InformNewHead(s.Conn().RemotePeer(), ts)
|
||||
hs.pmgr.AddFilecoinPeer(s.Conn().RemotePeer())
|
||||
}
|
||||
|
||||
func (hs *Service) SayHello(ctx context.Context, pid peer.ID) error {
|
||||
@@ -88,6 +92,7 @@ func (hs *Service) SayHello(ctx context.Context, pid peer.ID) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
gen, err := hs.cs.GetGenesis()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/filecoin-project/lotus/chain/sub"
|
||||
"github.com/filecoin-project/lotus/node/hello"
|
||||
"github.com/filecoin-project/lotus/node/modules/helpers"
|
||||
"github.com/filecoin-project/lotus/peermgr"
|
||||
"github.com/filecoin-project/lotus/retrieval/discovery"
|
||||
"github.com/filecoin-project/lotus/storage/sector"
|
||||
)
|
||||
@@ -33,6 +34,10 @@ func RunHello(mctx helpers.MetricsCtx, lc fx.Lifecycle, h host.Host, svc *hello.
|
||||
h.Network().Notify(&bundle)
|
||||
}
|
||||
|
||||
func RunPeerMgr(mctx helpers.MetricsCtx, lc fx.Lifecycle, pmgr *peermgr.PeerMgr) {
|
||||
go pmgr.Run(helpers.LifecycleCtx(mctx, lc))
|
||||
}
|
||||
|
||||
func RunBlockSync(h host.Host, svc *chain.BlockSyncService) {
|
||||
h.SetStreamHandler(chain.BlockSyncProtocolID, svc.HandleStream)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user