本文整理汇总了Golang中github.com/ipfs/go-ipfs/exchange/reprovide.NewReprovider函数的典型用法代码示例。如果您正苦于以下问题:Golang NewReprovider函数的具体用法?Golang NewReprovider怎么用?Golang NewReprovider使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewReprovider函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: startOnlineServices
func (n *IpfsNode) startOnlineServices(ctx context.Context, routingOption RoutingOption, hostOption HostOption, do DiscoveryOption) error {
if n.PeerHost != nil { // already online.
return errors.New("node already online")
}
// load private key
if err := n.LoadPrivateKey(); err != nil {
return err
}
// Set reporter
n.Reporter = metrics.NewBandwidthCounter()
// get undialable addrs from config
cfg, err := n.Repo.Config()
if err != nil {
return err
}
var addrfilter []*net.IPNet
for _, s := range cfg.Swarm.AddrFilters {
f, err := mamask.NewMask(s)
if err != nil {
return fmt.Errorf("incorrectly formatted address filter in config: %s", s)
}
addrfilter = append(addrfilter, f)
}
peerhost, err := hostOption(ctx, n.Identity, n.Peerstore, n.Reporter, addrfilter)
if err != nil {
return err
}
if err := n.startOnlineServicesWithHost(ctx, peerhost, routingOption); err != nil {
return err
}
// Ok, now we're ready to listen.
if err := startListening(ctx, n.PeerHost, cfg); err != nil {
return err
}
n.Reprovider = rp.NewReprovider(n.Routing, n.Blockstore)
go n.Reprovider.ProvideEvery(ctx, kReprovideFrequency)
// setup local discovery
if do != nil {
service, err := do(n.PeerHost)
if err != nil {
log.Error("mdns error: ", err)
} else {
service.RegisterNotifee(n)
n.Discovery = service
}
}
return n.Bootstrap(DefaultBootstrapConfig)
}
开发者ID:yuanwr,项目名称:go-ipfs,代码行数:58,代码来源:core.go
示例2: startOnlineServices
func (n *IpfsNode) startOnlineServices(ctx context.Context, routingOption RoutingOption, hostOption HostOption, do DiscoveryOption, pubsub, mplex bool) error {
if n.PeerHost != nil { // already online.
return errors.New("node already online")
}
// load private key
if err := n.LoadPrivateKey(); err != nil {
return err
}
// get undialable addrs from config
cfg, err := n.Repo.Config()
if err != nil {
return err
}
var addrfilter []*net.IPNet
for _, s := range cfg.Swarm.AddrFilters {
f, err := mamask.NewMask(s)
if err != nil {
return fmt.Errorf("incorrectly formatted address filter in config: %s", s)
}
addrfilter = append(addrfilter, f)
}
if !cfg.Swarm.DisableBandwidthMetrics {
// Set reporter
n.Reporter = metrics.NewBandwidthCounter()
}
tpt := makeSmuxTransport(mplex)
peerhost, err := hostOption(ctx, n.Identity, n.Peerstore, n.Reporter, addrfilter, tpt)
if err != nil {
return err
}
if err := n.startOnlineServicesWithHost(ctx, peerhost, routingOption); err != nil {
return err
}
// Ok, now we're ready to listen.
if err := startListening(ctx, n.PeerHost, cfg); err != nil {
return err
}
n.Reprovider = rp.NewReprovider(n.Routing, n.Blockstore)
if cfg.Reprovider.Interval != "0" {
interval := kReprovideFrequency
if cfg.Reprovider.Interval != "" {
dur, err := time.ParseDuration(cfg.Reprovider.Interval)
if err != nil {
return err
}
interval = dur
}
go n.Reprovider.ProvideEvery(ctx, interval)
}
if pubsub {
n.Floodsub = floodsub.NewFloodSub(ctx, peerhost)
}
// setup local discovery
if do != nil {
service, err := do(ctx, n.PeerHost)
if err != nil {
log.Error("mdns error: ", err)
} else {
service.RegisterNotifee(n)
n.Discovery = service
}
}
return n.Bootstrap(DefaultBootstrapConfig)
}
开发者ID:tswindell,项目名称:go-ipfs,代码行数:79,代码来源:core.go
注:本文中的github.com/ipfs/go-ipfs/exchange/reprovide.NewReprovider函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论