fix: remove say hello
This commit is contained in:
parent
5a961c90f5
commit
9c33816c90
@ -4,22 +4,14 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
cborutil "github.com/filecoin-project/go-cbor-util"
|
cborutil "github.com/filecoin-project/go-cbor-util"
|
||||||
"github.com/filecoin-project/lotus/blockstore"
|
|
||||||
"github.com/filecoin-project/lotus/chain/consensus/filcns"
|
|
||||||
"github.com/filecoin-project/lotus/chain/store"
|
|
||||||
lcli "github.com/filecoin-project/lotus/cli"
|
lcli "github.com/filecoin-project/lotus/cli"
|
||||||
"github.com/filecoin-project/lotus/node/hello"
|
"github.com/filecoin-project/lotus/node/hello"
|
||||||
"github.com/ipfs/go-datastore"
|
|
||||||
"github.com/libp2p/go-libp2p"
|
"github.com/libp2p/go-libp2p"
|
||||||
"github.com/libp2p/go-libp2p-core/host"
|
|
||||||
inet "github.com/libp2p/go-libp2p-core/network"
|
inet "github.com/libp2p/go-libp2p-core/network"
|
||||||
"github.com/libp2p/go-libp2p-core/peer"
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
"golang.org/x/xerrors"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var resultCh chan bool
|
var resultCh chan bool
|
||||||
@ -27,32 +19,10 @@ var resultCh chan bool
|
|||||||
var helloCmd = &cli.Command{
|
var helloCmd = &cli.Command{
|
||||||
Name: "hello",
|
Name: "hello",
|
||||||
Description: "Get remote peer hello message by multiaddr",
|
Description: "Get remote peer hello message by multiaddr",
|
||||||
Flags: []cli.Flag{
|
ArgsUsage: "[peerMultiaddr|minerActorAddress]",
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "multiaddr",
|
|
||||||
Usage: "remote peer multiaddr",
|
|
||||||
Required: true,
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "genesis-path",
|
|
||||||
Usage: "genesis car file path",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
ctx := lcli.ReqContext(cctx)
|
ctx := lcli.ReqContext(cctx)
|
||||||
resultCh = make(chan bool, 1)
|
resultCh = make(chan bool, 1)
|
||||||
cf := cctx.String("genesis-path")
|
|
||||||
f, err := os.OpenFile(cf, os.O_RDONLY, 0664)
|
|
||||||
if err != nil {
|
|
||||||
return xerrors.Errorf("opening the car file: %w", err)
|
|
||||||
}
|
|
||||||
bs := blockstore.FromDatastore(datastore.NewMapDatastore())
|
|
||||||
cs := store.NewChainStore(bs, bs, datastore.NewMapDatastore(), filcns.Weight, nil)
|
|
||||||
ts, err := cs.Import(cctx.Context, f)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
pis, err := lcli.AddrInfoFromArg(ctx, cctx)
|
pis, err := lcli.AddrInfoFromArg(ctx, cctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -66,21 +36,6 @@ var helloCmd = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
h.SetStreamHandler(hello.ProtocolID, HandleStream)
|
h.SetStreamHandler(hello.ProtocolID, HandleStream)
|
||||||
weight, err := cs.Weight(ctx, ts)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
gen := ts.Blocks()[0]
|
|
||||||
hmsg := &hello.HelloMessage{
|
|
||||||
HeaviestTipSet: ts.Cids(),
|
|
||||||
HeaviestTipSetHeight: ts.Height(),
|
|
||||||
HeaviestTipSetWeight: weight,
|
|
||||||
GenesisHash: gen.Cid(),
|
|
||||||
}
|
|
||||||
err = SayHello(ctx, pis[0].ID, h, hmsg)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
ctx, done := context.WithTimeout(ctx, 5*time.Second)
|
ctx, done := context.WithTimeout(ctx, 5*time.Second)
|
||||||
defer done()
|
defer done()
|
||||||
select {
|
select {
|
||||||
@ -106,15 +61,3 @@ func HandleStream(s inet.Stream) {
|
|||||||
fmt.Println(string(data))
|
fmt.Println(string(data))
|
||||||
resultCh <- true
|
resultCh <- true
|
||||||
}
|
}
|
||||||
|
|
||||||
func SayHello(ctx context.Context, pid peer.ID, h host.Host, hmsg *hello.HelloMessage) error {
|
|
||||||
s, err := h.NewStream(ctx, pid, hello.ProtocolID)
|
|
||||||
if err != nil {
|
|
||||||
return xerrors.Errorf("error opening stream: %w", err)
|
|
||||||
}
|
|
||||||
if err := cborutil.WriteCborRPC(s, hmsg); err != nil {
|
|
||||||
return xerrors.Errorf("writing rpc to peer: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user