Skip to content

Commit

Permalink
add cancel-retrieval-deal cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
nonsense committed Mar 24, 2021
1 parent a227039 commit a202f9d
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api/api_full.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@ type FullNode interface {
// which are stuck due to insufficient funds
ClientRetrieveTryRestartInsufficientFunds(ctx context.Context, paymentChannel address.Address) error //perm:write

// ClientCancelRetrievalDeal cancels an ongoing retrieval deal based on DealID
ClientCancelRetrievalDeal(ctx context.Context, dealid retrievalmarket.DealID) error //perm:write

// ClientUnimport removes references to the specified file from filestore
//ClientUnimport(path string)

Expand Down
6 changes: 6 additions & 0 deletions api/apistruct/struct.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions api/mocks/mock_full.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions cli/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ var clientCmd = &cli.Command{
WithCategory("util", clientListTransfers),
WithCategory("util", clientRestartTransfer),
WithCategory("util", clientCancelTransfer),
WithCategory("util", clientCancelRetrievalDeal),
},
}

Expand Down Expand Up @@ -1975,6 +1976,32 @@ var clientCancelTransfer = &cli.Command{
},
}

var clientCancelRetrievalDeal = &cli.Command{
Name: "cancel-retrieval-deal",
Usage: "Cancel a retrieval deal by DealID",
Flags: []cli.Flag{
&cli.Int64Flag{
Name: "dealid",
Usage: "specify retrieval deal by DealID",
Required: true,
},
},
Action: func(cctx *cli.Context) error {
api, closer, err := GetFullNodeAPI(cctx)
if err != nil {
return err
}
defer closer()
ctx := ReqContext(cctx)

if cctx.Int64("dealid") == 0 {
return errors.New("deal id cannot be 0")
}

return api.ClientCancelRetrievalDeal(ctx, retrievalmarket.DealID(cctx.Int64("dealid")))
},
}

var clientListTransfers = &cli.Command{
Name: "list-transfers",
Usage: "List ongoing data transfers for deals",
Expand Down
16 changes: 16 additions & 0 deletions documentation/en/api-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* [Client](#Client)
* [ClientCalcCommP](#ClientCalcCommP)
* [ClientCancelDataTransfer](#ClientCancelDataTransfer)
* [ClientCancelRetrievalDeal](#ClientCancelRetrievalDeal)
* [ClientDataTransferUpdates](#ClientDataTransferUpdates)
* [ClientDealPieceCID](#ClientDealPieceCID)
* [ClientDealSize](#ClientDealSize)
Expand Down Expand Up @@ -921,6 +922,21 @@ Inputs:

Response: `{}`

### ClientCancelRetrievalDeal
ClientCancelRetrievalDeal cancels an ongoing retrieval deal based on DealID


Perms: write

Inputs:
```json
[
5
]
```

Response: `{}`

### ClientDataTransferUpdates


Expand Down
23 changes: 23 additions & 0 deletions node/impl/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,29 @@ func (a *API) ClientListImports(ctx context.Context) ([]api.Import, error) {
return out, nil
}

func (a *API) ClientCancelRetrievalDeal(ctx context.Context, dealid retrievalmarket.DealID) error {
cerr := make(chan error)
go func() {
err := a.Retrieval.CancelDeal(dealid)

select {
case cerr <- err:
case <-ctx.Done():
}
}()

select {
case err := <-cerr:
if err != nil {
return xerrors.Errorf("canceling retrieval deal erred: %w", err)
}

return nil
case <-ctx.Done():
return xerrors.Errorf("canceling retrieval deal context timeout: %w", ctx.Err())
}
}

func (a *API) ClientRetrieve(ctx context.Context, order api.RetrievalOrder, ref *api.FileRef) error {
events := make(chan marketevents.RetrievalEvent)
go a.clientRetrieve(ctx, order, ref, events)
Expand Down

0 comments on commit a202f9d

Please sign in to comment.