本文整理汇总了Golang中github.com/ipfs/go-ipfs/metrics.NewBandwidthCounter函数的典型用法代码示例。如果您正苦于以下问题:Golang NewBandwidthCounter函数的具体用法?Golang NewBandwidthCounter怎么用?Golang NewBandwidthCounter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewBandwidthCounter函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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:andradeandrey,项目名称:go-ipfs,代码行数:58,代码来源:core.go
示例2: GenSwarmNetwork
func GenSwarmNetwork(t *testing.T, ctx context.Context) *swarm.Network {
p := tu.RandPeerNetParamsOrFatal(t)
ps := peer.NewPeerstore()
ps.AddPubKey(p.ID, p.PubKey)
ps.AddPrivKey(p.ID, p.PrivKey)
n, err := swarm.NewNetwork(ctx, []ma.Multiaddr{p.Addr}, p.ID, ps, metrics.NewBandwidthCounter())
if err != nil {
t.Fatal(err)
}
ps.AddAddrs(p.ID, n.ListenAddresses(), peer.PermanentAddrTTL)
return n
}
开发者ID:andradeandrey,项目名称:go-ipfs,代码行数:12,代码来源:util.go
示例3: New
// New constructs and sets up a new *BasicHost with given Network
func New(net inet.Network, opts ...interface{}) *BasicHost {
h := &BasicHost{
network: net,
mux: msmux.NewMultistreamMuxer(),
bwc: metrics.NewBandwidthCounter(),
}
h.proc = goprocess.WithTeardown(func() error {
if h.natmgr != nil {
h.natmgr.Close()
}
return h.Network().Close()
})
// setup host services
h.ids = identify.NewIDService(h)
muxh := h.Mux().Handle
handle := func(s inet.Stream) {
muxh(s)
}
h.relay = relay.NewRelayService(h, handle)
for _, o := range opts {
switch o := o.(type) {
case Option:
switch o {
case NATPortMap:
h.natmgr = newNatManager(h)
}
case metrics.Reporter:
h.bwc = o
}
}
net.SetConnHandler(h.newConnHandler)
net.SetStreamHandler(h.newStreamHandler)
return h
}
开发者ID:noffle,项目名称:go-ipfs,代码行数:42,代码来源:basic_host.go
示例4: makeSwarms
func makeSwarms(ctx context.Context, t *testing.T, num int) []*Swarm {
swarms := make([]*Swarm, 0, num)
for i := 0; i < num; i++ {
localnp := testutil.RandPeerNetParamsOrFatal(t)
peerstore := peer.NewPeerstore()
peerstore.AddPubKey(localnp.ID, localnp.PubKey)
peerstore.AddPrivKey(localnp.ID, localnp.PrivKey)
addrs := []ma.Multiaddr{localnp.Addr}
swarm, err := NewSwarm(ctx, addrs, localnp.ID, peerstore, metrics.NewBandwidthCounter())
if err != nil {
t.Fatal(err)
}
swarm.SetStreamHandler(EchoStreamHandler)
swarms = append(swarms, swarm)
}
return swarms
}
开发者ID:avbalu,项目名称:go-ipfs,代码行数:22,代码来源:swarm_test.go
示例5: TestFilterAddrs
func TestFilterAddrs(t *testing.T) {
m := func(s string) ma.Multiaddr {
maddr, err := ma.NewMultiaddr(s)
if err != nil {
t.Fatal(err)
}
return maddr
}
bad := []ma.Multiaddr{
m("/ip4/1.2.3.4/udp/1234"), // unreliable
m("/ip4/1.2.3.4/udp/1234/sctp/1234"), // not in manet
m("/ip4/1.2.3.4/udp/1234/utp"), // utp is broken
m("/ip4/1.2.3.4/udp/1234/udt"), // udt is broken on arm
m("/ip6/fe80::1/tcp/0"), // link local
m("/ip6/fe80::100/tcp/1234"), // link local
}
good := []ma.Multiaddr{
m("/ip4/127.0.0.1/tcp/0"),
m("/ip6/::1/tcp/0"),
}
goodAndBad := append(good, bad...)
// test filters
for _, a := range bad {
if addrutil.AddrUsable(a, true) {
t.Errorf("addr %s should be unusable", a)
}
}
for _, a := range good {
if !addrutil.AddrUsable(a, true) {
t.Errorf("addr %s should be usable", a)
}
}
subtestAddrsEqual(t, addrutil.FilterUsableAddrs(bad), []ma.Multiaddr{})
subtestAddrsEqual(t, addrutil.FilterUsableAddrs(good), good)
subtestAddrsEqual(t, addrutil.FilterUsableAddrs(goodAndBad), good)
// now test it with swarm
id, err := testutil.RandPeerID()
if err != nil {
t.Fatal(err)
}
ps := peer.NewPeerstore()
ctx := context.Background()
if _, err := NewNetwork(ctx, bad, id, ps, metrics.NewBandwidthCounter()); err == nil {
t.Fatal("should have failed to create swarm")
}
if _, err := NewNetwork(ctx, goodAndBad, id, ps, metrics.NewBandwidthCounter()); err != nil {
t.Fatal("should have succeeded in creating swarm", err)
}
}
开发者ID:andradeandrey,项目名称:go-ipfs,代码行数:62,代码来源:swarm_addr_test.go
注:本文中的github.com/ipfs/go-ipfs/metrics.NewBandwidthCounter函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论