lotus/node/modules/core.go

46 lines
1.3 KiB
Go
Raw Normal View History

package modules
import (
2019-07-08 13:36:43 +00:00
"context"
2019-07-08 13:36:43 +00:00
"github.com/ipfs/go-bitswap"
"github.com/ipfs/go-bitswap/network"
blockstore "github.com/ipfs/go-ipfs-blockstore"
exchange "github.com/ipfs/go-ipfs-exchange-interface"
2019-07-03 17:39:07 +00:00
logging "github.com/ipfs/go-log"
2019-07-08 13:36:43 +00:00
"github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/peerstore"
2019-07-08 13:36:43 +00:00
"github.com/libp2p/go-libp2p-core/routing"
record "github.com/libp2p/go-libp2p-record"
2019-07-08 13:36:43 +00:00
"go.uber.org/fx"
"github.com/filecoin-project/go-lotus/chain"
"github.com/filecoin-project/go-lotus/node/modules/helpers"
)
2019-07-03 17:39:07 +00:00
var log = logging.Logger("modules")
2019-07-08 13:36:43 +00:00
type Genesis *chain.BlockHeader
// RecordValidator provides namesys compatible routing record validator
func RecordValidator(ps peerstore.Peerstore) record.Validator {
return record.NamespacedValidator{
"pk": record.PublicKeyValidator{},
}
}
2019-07-08 13:36:43 +00:00
func Bitswap(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host, rt routing.Routing, bs blockstore.GCBlockstore) exchange.Interface {
bitswapNetwork := network.NewFromIpfsHost(host, rt)
exch := bitswap.New(helpers.LifecycleCtx(mctx, lc), bitswapNetwork, bs)
lc.Append(fx.Hook{
OnStop: func(ctx context.Context) error {
return exch.Close()
},
})
return exch
}
func SetGenesis(cs *chain.ChainStore, g Genesis) error {
return cs.SetGenesis(g)
}