diff --git a/cli/net.go b/cli/net.go index 23691974f..b86d72c38 100644 --- a/cli/net.go +++ b/cli/net.go @@ -34,6 +34,7 @@ var NetCmd = &cli.Command{ NetPeers, NetPing, NetConnect, + NetDisconnect, NetListen, NetId, NetFindPeer, @@ -261,6 +262,37 @@ var NetListen = &cli.Command{ }, } +var NetDisconnect = &cli.Command{ + Name: "disconnect", + Usage: "Disconnect from a peer", + ArgsUsage: "[peerID]", + Action: func(cctx *cli.Context) error { + api, closer, err := GetAPI(cctx) + if err != nil { + return err + } + defer closer() + ctx := ReqContext(cctx) + + ids := cctx.Args().Slice() + for _, id := range ids { + pid, err := peer.Decode(id) + if err != nil { + fmt.Println("failure") + return err + } + fmt.Printf("disconnect %s: ", pid.Pretty()) + err = api.NetDisconnect(ctx, pid) + if err != nil { + fmt.Println("failure") + return err + } + fmt.Println("success") + } + return nil + }, +} + var NetConnect = &cli.Command{ Name: "connect", Usage: "Connect to a peer", diff --git a/documentation/en/cli-lotus-miner.md b/documentation/en/cli-lotus-miner.md index bf75b1065..2e72af4a8 100644 --- a/documentation/en/cli-lotus-miner.md +++ b/documentation/en/cli-lotus-miner.md @@ -1168,6 +1168,7 @@ COMMANDS: peers Print peers ping Ping peers connect Connect to a peer + disconnect Disconnect from a peer listen List listen addresses id Get node identity find-peer, findpeer Find the addresses of a given peerID @@ -1228,6 +1229,19 @@ OPTIONS: ``` +### lotus-miner net disconnect +``` +NAME: + lotus-miner net disconnect - Disconnect from a peer + +USAGE: + lotus-miner net disconnect [command options] [peerID] + +OPTIONS: + --help, -h show help (default: false) + +``` + ### lotus-miner net listen ``` NAME: diff --git a/documentation/en/cli-lotus.md b/documentation/en/cli-lotus.md index 223d7a401..83dcfb25d 100644 --- a/documentation/en/cli-lotus.md +++ b/documentation/en/cli-lotus.md @@ -2485,6 +2485,7 @@ COMMANDS: peers Print peers ping Ping peers connect Connect to a peer + disconnect Disconnect from a peer listen List listen addresses id Get node identity find-peer, findpeer Find the addresses of a given peerID @@ -2545,6 +2546,19 @@ OPTIONS: ``` +### lotus net disconnect +``` +NAME: + lotus net disconnect - Disconnect from a peer + +USAGE: + lotus net disconnect [command options] [peerID] + +OPTIONS: + --help, -h show help (default: false) + +``` + ### lotus net listen ``` NAME: