Skip to content

Commit

Permalink
refactor: clean up unused vars etc
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkmc committed Aug 24, 2022
1 parent 150b0ea commit 6c15199
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 85 deletions.
7 changes: 6 additions & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ type Boost interface {
BoostDagstoreGC(ctx context.Context) ([]DagstoreShardResult, error) //perm:admin
BoostDagstorePiecesContainingMultihash(ctx context.Context, mh multihash.Multihash) ([]cid.Cid, error) //perm:read
BoostDagstoreListShards(ctx context.Context) ([]DagstoreShardInfo, error) //perm:read
BoostGetBlock(ctx context.Context, c cid.Cid) ([]byte, error) //perm:read

// MethodGroup: Blockstore
BlockstoreGet(ctx context.Context, c cid.Cid) ([]byte, error) //perm:read
BlockstoreHas(ctx context.Context, c cid.Cid) (bool, error) //perm:read
BlockstoreGetSize(ctx context.Context, c cid.Cid) (int, error) //perm:read

// RuntimeSubsystems returns the subsystems that are enabled
// in this instance.
RuntimeSubsystems(ctx context.Context) (lapi.MinerSubsystems, error) //perm:read
Expand Down
52 changes: 39 additions & 13 deletions api/proxy_gen.go

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

Binary file modified build/openrpc/boost.json.gz
Binary file not shown.
44 changes: 15 additions & 29 deletions cmd/booster-bitswap/remoteblockstore/remoteblockstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"

blocks "github.com/ipfs/go-block-format"
format "github.com/ipfs/go-ipld-format"
logging "github.com/ipfs/go-log/v2"

"github.com/ipfs/go-cid"
Expand All @@ -14,23 +13,15 @@ import (

var log = logging.Logger("remote-blockstore")

var ErrBlockNotFound = errors.New("block not found")
var ErrNotFound = errors.New("not found")

var _ blockstore.Blockstore = (*RemoteBlockstore)(nil)

// ErrNoPieceSelected means that the piece selection function rejected all of the given pieces.
var ErrNoPieceSelected = errors.New("no piece selected")

// PieceSelectorF helps select a piece to fetch a cid from if the given cid is present in multiple pieces.
// It should return `ErrNoPieceSelected` if none of the given piece is selected.
type PieceSelectorF func(c cid.Cid, pieceCids []cid.Cid) (cid.Cid, error)

type RemoteBlockstoreAPI interface {
BoostGetBlock(ctx context.Context, c cid.Cid) ([]byte, error)
BlockstoreGet(ctx context.Context, c cid.Cid) ([]byte, error)
BlockstoreHas(ctx context.Context, c cid.Cid) (bool, error)
BlockstoreGetSize(ctx context.Context, c cid.Cid) (int, error)
}

// RemoteBlockstore is a read only blockstore over all cids across all pieces on a provider.
// RemoteBlockstore is a read-only blockstore over all cids across all pieces on a provider.
type RemoteBlockstore struct {
api RemoteBlockstoreAPI
}
Expand All @@ -42,32 +33,27 @@ func NewRemoteBlockstore(api RemoteBlockstoreAPI) blockstore.Blockstore {
}

func (ro *RemoteBlockstore) Get(ctx context.Context, c cid.Cid) (b blocks.Block, err error) {
log.Debugw("processing request for block", "cid", c)
data, err := ro.api.BoostGetBlock(ctx, c)
log.Debugw("boost api response for get block", "cid", c, "error", err)
log.Debugw("Get", "cid", c)
data, err := ro.api.BlockstoreGet(ctx, c)
log.Debugw("Get response", "cid", c, "error", err)
if err != nil {
return nil, err
}
return blocks.NewBlockWithCid(data, c)
}

func (ro *RemoteBlockstore) Has(ctx context.Context, c cid.Cid) (bool, error) {
_, err := ro.api.BoostGetBlock(ctx, c)
if err != nil {
if format.IsNotFound(err) {
return false, nil
}
return false, err
}
return true, nil
log.Debugw("Has", "cid", c)
has, err := ro.api.BlockstoreHas(ctx, c)
log.Debugw("Has response", "cid", c, "has", has, "error", err)
return has, err
}

func (ro *RemoteBlockstore) GetSize(ctx context.Context, c cid.Cid) (int, error) {
data, err := ro.api.BoostGetBlock(ctx, c)
if err != nil {
return 0, err
}
return len(data), nil
log.Debugw("GetSize", "cid", c)
size, err := ro.api.BlockstoreGetSize(ctx, c)
log.Debugw("GetSize response", "cid", c, "size", size, "error", err)
return size, err
}

// --- UNSUPPORTED BLOCKSTORE METHODS -------
Expand Down
28 changes: 3 additions & 25 deletions cmd/booster-bitswap/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"context"
"errors"
"fmt"
"net/http"
_ "net/http/pprof"
Expand All @@ -14,7 +13,6 @@ import (
"github.com/filecoin-project/boost/cmd/booster-bitswap/remoteblockstore"
"github.com/filecoin-project/go-jsonrpc"
lcli "github.com/filecoin-project/lotus/cli"
"github.com/filecoin-project/lotus/storage/sealer"
"github.com/urfave/cli/v2"
)

Expand All @@ -37,16 +35,6 @@ var runCmd = &cli.Command{
Usage: "the endpoint for the boost API",
Required: true,
},
&cli.StringFlag{
Name: "api-fullnode",
Usage: "the endpoint for the full node API",
Required: true,
},
&cli.StringFlag{
Name: "api-sealer",
Usage: "the endpoint for the sealer API",
Required: true,
},
},
Action: func(cctx *cli.Context) error {
if cctx.Bool("pprof") {
Expand All @@ -69,11 +57,11 @@ var runCmd = &cli.Command{

remoteStore := remoteblockstore.NewRemoteBlockstore(bapi)
// Create the server API
server := NewBitswapServer(cctx.String("base-path"), cctx.Int("port"), remoteStore)
port := cctx.Int("port")
server := NewBitswapServer(port, remoteStore)

// Start the server
log.Infof("Starting booster-http node on port %d with base path '%s'",
cctx.Int("port"), cctx.String("base-path"))
log.Infof("Starting booster-bitswap node on port %d", port)
err = server.Start(ctx)
if err != nil {
return err
Expand All @@ -96,16 +84,6 @@ var runCmd = &cli.Command{
},
}

func storageAuthWithURL(apiInfo string) (sealer.StorageAuth, error) {
s := strings.Split(apiInfo, ":")
if len(s) != 2 {
return nil, errors.New("unexpected format of `apiInfo`")
}
headers := http.Header{}
headers.Add("Authorization", "Bearer "+s[0])
return sealer.StorageAuth(headers), nil
}

func getBoostAPI(ctx context.Context, ai string) (api.Boost, jsonrpc.ClientCloser, error) {
ai = strings.TrimPrefix(strings.TrimSpace(ai), "BOOST_API_INFO=")
info := cliutil.ParseApiInfo(ai)
Expand Down
8 changes: 2 additions & 6 deletions cmd/booster-bitswap/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"crypto/rand"
"errors"
"fmt"

bsnetwork "github.com/ipfs/go-bitswap/network"
Expand All @@ -19,8 +18,6 @@ import (
"github.com/libp2p/go-libp2p/p2p/transport/tcp"
)

var ErrNotFound = errors.New("not found")

type BitswapServer struct {
port int
remoteStore blockstore.Blockstore
Expand All @@ -30,7 +27,7 @@ type BitswapServer struct {
server *server.Server
}

func NewBitswapServer(path string, port int, remoteStore blockstore.Blockstore) *BitswapServer {
func NewBitswapServer(port int, remoteStore blockstore.Blockstore) *BitswapServer {
return &BitswapServer{port: port, remoteStore: remoteStore}
}

Expand Down Expand Up @@ -65,8 +62,7 @@ func (s *BitswapServer) Start(ctx context.Context) error {
s.server = server.New(ctx, net, s.remoteStore, bsopts...)
net.Start(s.server)

fmt.Printf("bitswap server running on SP, addrs: %s, peerID: %s\n", host.Addrs(), host.ID())
log.Infow("bitswap server running on SP", "multiaddrs", host.Addrs(), "peerId", host.ID())
log.Infow("bitswap server running", "multiaddrs", host.Addrs(), "peerId", host.ID())
return nil
}

Expand Down
63 changes: 55 additions & 8 deletions documentation/en/api-v1-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
* [Auth](#auth)
* [AuthNew](#authnew)
* [AuthVerify](#authverify)
* [Blockstore](#blockstore)
* [BlockstoreGet](#blockstoreget)
* [BlockstoreGetSize](#blockstoregetsize)
* [BlockstoreHas](#blockstorehas)
* [Boost](#boost)
* [BoostDagstoreDestroyShard](#boostdagstoredestroyshard)
* [BoostDagstoreGC](#boostdagstoregc)
Expand Down Expand Up @@ -137,6 +141,57 @@ Response:
]
```

## Blockstore


### BlockstoreGet
There are not yet any comments for this method.

Perms: read

Inputs:
```json
[
{
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
}
]
```

Response: `"Ynl0ZSBhcnJheQ=="`

### BlockstoreGetSize


Perms: read

Inputs:
```json
[
{
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
}
]
```

Response: `123`

### BlockstoreHas


Perms: read

Inputs:
```json
[
{
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
}
]
```

Response: `true`

## Boost


Expand Down Expand Up @@ -1303,11 +1358,7 @@ Inputs:
Response:
```json
{
"Dynamic": true,
"Memory": 9,
"MemoryFraction": 12.3,
"MinMemory": 9,
"MaxMemory": 9,
"Streams": 123,
"StreamsInbound": 123,
"StreamsOutbound": 123,
Expand Down Expand Up @@ -1473,11 +1524,7 @@ Inputs:
[
"string value",
{
"Dynamic": true,
"Memory": 9,
"MemoryFraction": 12.3,
"MinMemory": 9,
"MaxMemory": 9,
"Streams": 123,
"StreamsInbound": 123,
"StreamsOutbound": 123,
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ require (
github.com/libp2p/go-eventbus v0.2.1
github.com/libp2p/go-libp2p v0.21.0
github.com/libp2p/go-libp2p-core v0.19.1
github.com/libp2p/go-libp2p-crypto v0.1.0
github.com/libp2p/go-libp2p-gostream v0.4.1-0.20220720161416-e1952aede109
github.com/libp2p/go-libp2p-http v0.2.1
github.com/libp2p/go-libp2p-kad-dht v0.17.0
Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,6 @@ github.com/libp2p/go-libp2p-core v0.19.1 h1:zaZQQCeCrFMtxFa1wHy6AhsVynyNmZAvwgWq
github.com/libp2p/go-libp2p-core v0.19.1/go.mod h1:2uLhmmqDiFY+dw+70KkBLeKvvsJHGWUINRDdeV1ip7k=
github.com/libp2p/go-libp2p-crypto v0.0.1/go.mod h1:yJkNyDmO341d5wwXxDUGO0LykUVT72ImHNUqh5D/dBE=
github.com/libp2p/go-libp2p-crypto v0.0.2/go.mod h1:eETI5OUfBnvARGOHrJz2eWNyTUxEGZnBxMcbUjfIj4I=
github.com/libp2p/go-libp2p-crypto v0.1.0 h1:k9MFy+o2zGDNGsaoZl0MA3iZ75qXxr9OOoAZF+sD5OQ=
github.com/libp2p/go-libp2p-crypto v0.1.0/go.mod h1:sPUokVISZiy+nNuTTH/TY+leRSxnFj/2GLjtOTW90hI=
github.com/libp2p/go-libp2p-daemon v0.2.2/go.mod h1:kyrpsLB2JeNYR2rvXSVWyY0iZuRIMhqzWR3im9BV6NQ=
github.com/libp2p/go-libp2p-discovery v0.0.5/go.mod h1:YtF20GUxjgoKZ4zmXj8j3Nb2TUSBHFlOCetzYdbZL5I=
Expand Down
Loading

0 comments on commit 6c15199

Please sign in to comment.