亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

未定義:運行 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 關注
  • 96 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號