为了账号安全,请及时绑定邮箱和手机立即绑定

未定义:运行 go libp2p 时遇到 ctx

未定义:运行 go libp2p 时遇到 ctx

Go
回首忆惘然 2022-10-24 10:01:52
代码如下,它是go-libp2p的官方演示。我没有遇到任何其他引用或未定义的错误    // if a remote peer has been passed on the command line, connect to it    // and send it 5 ping messages, otherwise wait for a signal to stop    if len(os.Args) > 1 {        addr, err := multiaddr.NewMultiaddr(os.Args[1])        if err != nil {            panic(err)        }        peer, err := peerstore.AddrInfoFromP2pAddr(addr)        if err != nil {            panic(err)        }        if err := node.Connect(ctx, *peer); err != nil {            panic(err)        }        fmt.Println("sending 5 ping messages to", addr)导入如下:import (    "fmt"    "os"    "os/signal"    "syscall"    "github.com/libp2p/go-libp2p"    peerstore "github.com/libp2p/go-libp2p-core/peer"    "github.com/libp2p/go-libp2p/p2p/protocol/ping"    multiaddr "github.com/multiformats/go-multiaddr")
查看完整描述

1 回答

?
慕森卡

TA贡献1806条经验 获得超8个赞

// create context

ctx:=context.Background()


// if a remote peer has been passed on the command line, connect to it

// and send it 5 ping messages, otherwise wait for a signal to stop

if len(os.Args) > 1 {

    addr, err := multiaddr.NewMultiaddr(os.Args[1])

    if err != nil {

        panic(err)

    }

    peer, err := peerstore.AddrInfoFromP2pAddr(addr)

    if err != nil {

        panic(err)

    }

    if err := node.Connect(ctx, *peer); err != nil {

        panic(err)

    }

    fmt.Println("sending 5 ping messages to", addr)


查看完整回答
反对 回复 2022-10-24
  • 1 回答
  • 0 关注
  • 53 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信