-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Miner Data Transfer Restart Cmd #4387
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package main | |
|
||
import ( | ||
"bufio" | ||
"errors" | ||
"fmt" | ||
"io" | ||
"os" | ||
|
@@ -13,8 +14,10 @@ import ( | |
|
||
tm "github.com/buger/goterm" | ||
"github.com/docker/go-units" | ||
datatransfer "github.com/filecoin-project/go-data-transfer" | ||
"github.com/ipfs/go-cid" | ||
"github.com/ipfs/go-cidutil/cidenc" | ||
"github.com/libp2p/go-libp2p-core/peer" | ||
"github.com/multiformats/go-multibase" | ||
"github.com/urfave/cli/v2" | ||
"golang.org/x/xerrors" | ||
|
@@ -569,6 +572,67 @@ var dataTransfersCmd = &cli.Command{ | |
Usage: "Manage data transfers", | ||
Subcommands: []*cli.Command{ | ||
transfersListCmd, | ||
minerRestartTransfer, | ||
}, | ||
} | ||
|
||
var minerRestartTransfer = &cli.Command{ | ||
Name: "restart-transfer", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this can just be "restart" rather than "restart-transfer" cause the miner command will already be under the "data-transfers" namespace |
||
Usage: "Force restart a stalled data transfer", | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "peerid", | ||
Usage: "narrow to transfer with specific peer", | ||
}, | ||
&cli.BoolFlag{ | ||
Name: "initiator", | ||
Usage: "specify only transfers where peer is/is not initiator", | ||
Value: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Initiator on this side should default to false 99% of the time the miner is NOT the initiator of the request (even when sending data) |
||
}, | ||
}, | ||
Action: func(cctx *cli.Context) error { | ||
if !cctx.Args().Present() { | ||
return cli.ShowCommandHelp(cctx, cctx.Command.Name) | ||
} | ||
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) | ||
if err != nil { | ||
return err | ||
} | ||
defer closer() | ||
ctx := lcli.ReqContext(cctx) | ||
|
||
transferUint, err := strconv.ParseUint(cctx.Args().First(), 10, 64) | ||
if err != nil { | ||
return fmt.Errorf("Error reading transfer ID: %w", err) | ||
} | ||
transferID := datatransfer.TransferID(transferUint) | ||
initiator := cctx.Bool("initiator") | ||
var other peer.ID | ||
if pidstr := cctx.String("peerid"); pidstr != "" { | ||
p, err := peer.Decode(pidstr) | ||
if err != nil { | ||
return err | ||
} | ||
other = p | ||
} else { | ||
channels, err := nodeApi.MarketListDataTransfers(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
found := false | ||
for _, channel := range channels { | ||
if channel.IsInitiator == initiator && channel.TransferID == transferID { | ||
other = channel.OtherPeer | ||
found = true | ||
break | ||
} | ||
} | ||
if !found { | ||
return errors.New("unable to find matching data transfer") | ||
} | ||
} | ||
|
||
return nodeApi.MinerRestartDataTransfer(ctx, transferID, other, initiator) | ||
}, | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably be prefixed with
Markets
and be next toMarketDataTransferUpdates
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree