2019-07-08 14:07:09 +00:00
|
|
|
package modules
|
|
|
|
|
|
|
|
import (
|
2019-08-01 17:12:41 +00:00
|
|
|
"context"
|
2019-08-14 20:27:10 +00:00
|
|
|
"github.com/filecoin-project/go-lotus/storage/sector"
|
2019-08-01 17:12:41 +00:00
|
|
|
|
2019-07-08 14:07:09 +00:00
|
|
|
"github.com/libp2p/go-libp2p-core/host"
|
|
|
|
inet "github.com/libp2p/go-libp2p-core/network"
|
|
|
|
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
|
|
|
"go.uber.org/fx"
|
2019-07-08 15:14:36 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/go-lotus/chain"
|
2019-08-01 17:12:41 +00:00
|
|
|
"github.com/filecoin-project/go-lotus/chain/deals"
|
2019-07-08 15:14:36 +00:00
|
|
|
"github.com/filecoin-project/go-lotus/chain/sub"
|
|
|
|
"github.com/filecoin-project/go-lotus/node/hello"
|
|
|
|
"github.com/filecoin-project/go-lotus/node/modules/helpers"
|
2019-07-08 14:07:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func RunHello(mctx helpers.MetricsCtx, lc fx.Lifecycle, h host.Host, svc *hello.Service) {
|
|
|
|
h.SetStreamHandler(hello.ProtocolID, svc.HandleStream)
|
|
|
|
|
|
|
|
bundle := inet.NotifyBundle{
|
|
|
|
ConnectedF: func(_ inet.Network, c inet.Conn) {
|
|
|
|
go func() {
|
|
|
|
if err := svc.SayHello(helpers.LifecycleCtx(mctx, lc), c.RemotePeer()); err != nil {
|
|
|
|
log.Warnw("failed to say hello", "error", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
},
|
|
|
|
}
|
|
|
|
h.Network().Notify(&bundle)
|
|
|
|
}
|
|
|
|
|
|
|
|
func RunBlockSync(h host.Host, svc *chain.BlockSyncService) {
|
|
|
|
h.SetStreamHandler(chain.BlockSyncProtocolID, svc.HandleStream)
|
|
|
|
}
|
|
|
|
|
|
|
|
func HandleIncomingBlocks(mctx helpers.MetricsCtx, lc fx.Lifecycle, pubsub *pubsub.PubSub, s *chain.Syncer) {
|
|
|
|
ctx := helpers.LifecycleCtx(mctx, lc)
|
|
|
|
|
|
|
|
blocksub, err := pubsub.Subscribe("/fil/blocks")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
go sub.HandleIncomingBlocks(ctx, blocksub, s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func HandleIncomingMessages(mctx helpers.MetricsCtx, lc fx.Lifecycle, pubsub *pubsub.PubSub, mpool *chain.MessagePool) {
|
|
|
|
ctx := helpers.LifecycleCtx(mctx, lc)
|
|
|
|
|
|
|
|
msgsub, err := pubsub.Subscribe("/fil/messages")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
go sub.HandleIncomingMessages(ctx, mpool, msgsub)
|
|
|
|
}
|
2019-08-01 17:12:41 +00:00
|
|
|
|
|
|
|
func RunDealClient(lc fx.Lifecycle, c *deals.Client) {
|
|
|
|
lc.Append(fx.Hook{
|
|
|
|
OnStart: func(context.Context) error {
|
|
|
|
c.Run()
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
OnStop: func(context.Context) error {
|
|
|
|
c.Stop()
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2019-08-14 20:27:10 +00:00
|
|
|
|
|
|
|
func RunSectorService(lc fx.Lifecycle, secst *sector.Store) {
|
|
|
|
lc.Append(fx.Hook{
|
|
|
|
OnStart: func(context.Context) error {
|
|
|
|
secst.Service()
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
OnStop: func(context.Context) error {
|
|
|
|
secst.Stop()
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|