diff --git a/cmd/booster-http/http_test.go b/cmd/booster-http/http_test.go index efe4c151c..54e7b7feb 100644 --- a/cmd/booster-http/http_test.go +++ b/cmd/booster-http/http_test.go @@ -52,10 +52,8 @@ func TestHttpGzipResponse(t *testing.T) { defer f.Close() //Create CID - var cids []cid.Cid cid, err := cid.Parse("bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi") require.NoError(t, err) - cids = append(cids, cid) // Crate pieceInfo deal := piecestore.DealInfo{ @@ -73,12 +71,11 @@ func TestHttpGzipResponse(t *testing.T) { mockHttpServer.EXPECT().UnsealSectorAt(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(f, nil) mockHttpServer.EXPECT().IsUnsealed(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(true, nil) - mockHttpServer.EXPECT().PiecesContainingMultihash(gomock.Any(), gomock.Any()).AnyTimes().Return(cids, nil) mockHttpServer.EXPECT().GetPieceInfo(gomock.Any()).AnyTimes().Return(&pieceInfo, nil) //Create a client and make request with Encoding header client := new(http.Client) - request, err := http.NewRequest("GET", "http://localhost:7777/piece?payloadCid=bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi&format=piece", nil) + request, err := http.NewRequest("GET", "http://localhost:7777/piece/bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi", nil) require.NoError(t, err) request.Header.Add("Accept-Encoding", "gzip") @@ -103,61 +100,6 @@ func TestHttpGzipResponse(t *testing.T) { require.NoError(t, err) } -func TestHttpResponseRedirects(t *testing.T) { - - // Create a new mock Http server with custom functions - ctrl := gomock.NewController(t) - mockHttpServer := mocks_booster_http.NewMockHttpServerApi(ctrl) - httpServer := NewHttpServer("", 7777, false, mockHttpServer) - httpServer.Start(context.Background()) - - // Create mock unsealed file for piece/car - f, _ := os.Open(testFile) - defer f.Close() - - //Create CID - var cids []cid.Cid - cid, err := cid.Parse("bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi") - require.NoError(t, err) - cids = append(cids, cid) - - // Crate pieceInfo - deal := piecestore.DealInfo{ - DealID: 1234567, - SectorID: 0, - Offset: 1233, - Length: 123, - } - var deals []piecestore.DealInfo - - pieceInfo := piecestore.PieceInfo{ - PieceCID: cid, - Deals: append(deals, deal), - } - - mockHttpServer.EXPECT().UnsealSectorAt(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(f, nil) - mockHttpServer.EXPECT().IsUnsealed(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(true, nil) - mockHttpServer.EXPECT().PiecesContainingMultihash(gomock.Any(), gomock.Any()).AnyTimes().Return(cids, nil) - mockHttpServer.EXPECT().GetPieceInfo(gomock.Any()).AnyTimes().Return(&pieceInfo, nil) - - // Create a client with check against redirects - client := &http.Client{ - CheckRedirect: func(req *http.Request, via []*http.Request) error { - return http.ErrUseLastResponse - }, - } - request, err := http.NewRequest("GET", "http://localhost:7777/piece?payloadCid=bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi&format=piece", nil) - require.NoError(t, err) - - response, err := client.Do(request) - require.NoError(t, err) - require.Equal(t, 200, response.StatusCode) - - // Stop the server - err = httpServer.Stop() - require.NoError(t, err) -} - func TestHttpInfo(t *testing.T) { var v apiVersion diff --git a/cmd/booster-http/mocks/mock_booster_http.go b/cmd/booster-http/mocks/mock_booster_http.go index 46f224ed5..7b3e914b1 100644 --- a/cmd/booster-http/mocks/mock_booster_http.go +++ b/cmd/booster-http/mocks/mock_booster_http.go @@ -13,7 +13,6 @@ import ( abi "github.com/filecoin-project/go-state-types/abi" gomock "github.com/golang/mock/gomock" cid "github.com/ipfs/go-cid" - multihash "github.com/multiformats/go-multihash" ) // MockHttpServerApi is a mock of HttpServerApi interface. @@ -39,21 +38,6 @@ func (m *MockHttpServerApi) EXPECT() *MockHttpServerApiMockRecorder { return m.recorder } -// GetMaxPieceOffset mocks base method. -func (m *MockHttpServerApi) GetMaxPieceOffset(pieceCid cid.Cid) (uint64, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetMaxPieceOffset", pieceCid) - ret0, _ := ret[0].(uint64) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetMaxPieceOffset indicates an expected call of GetMaxPieceOffset. -func (mr *MockHttpServerApiMockRecorder) GetMaxPieceOffset(pieceCid interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMaxPieceOffset", reflect.TypeOf((*MockHttpServerApi)(nil).GetMaxPieceOffset), pieceCid) -} - // GetPieceInfo mocks base method. func (m *MockHttpServerApi) GetPieceInfo(pieceCID cid.Cid) (*piecestore.PieceInfo, error) { m.ctrl.T.Helper() @@ -84,21 +68,6 @@ func (mr *MockHttpServerApiMockRecorder) IsUnsealed(ctx, sectorID, offset, lengt return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsUnsealed", reflect.TypeOf((*MockHttpServerApi)(nil).IsUnsealed), ctx, sectorID, offset, length) } -// PiecesContainingMultihash mocks base method. -func (m *MockHttpServerApi) PiecesContainingMultihash(ctx context.Context, mh multihash.Multihash) ([]cid.Cid, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "PiecesContainingMultihash", ctx, mh) - ret0, _ := ret[0].([]cid.Cid) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// PiecesContainingMultihash indicates an expected call of PiecesContainingMultihash. -func (mr *MockHttpServerApiMockRecorder) PiecesContainingMultihash(ctx, mh interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PiecesContainingMultihash", reflect.TypeOf((*MockHttpServerApi)(nil).PiecesContainingMultihash), ctx, mh) -} - // UnsealSectorAt mocks base method. func (m *MockHttpServerApi) UnsealSectorAt(ctx context.Context, sectorID abi.SectorNumber, pieceOffset, length abi.UnpaddedPieceSize) (mount.Reader, error) { m.ctrl.T.Helper() diff --git a/cmd/booster-http/run.go b/cmd/booster-http/run.go index f9f336cd9..91b3d9500 100644 --- a/cmd/booster-http/run.go +++ b/cmd/booster-http/run.go @@ -29,7 +29,6 @@ import ( "github.com/filecoin-project/lotus/storage/paths" "github.com/filecoin-project/lotus/storage/sealer" "github.com/ipfs/go-cid" - "github.com/multiformats/go-multihash" "github.com/urfave/cli/v2" ) @@ -227,14 +226,6 @@ type serverApi struct { var _ HttpServerApi = (*serverApi)(nil) -func (s serverApi) PiecesContainingMultihash(ctx context.Context, mh multihash.Multihash) ([]cid.Cid, error) { - return s.bapi.BoostDagstorePiecesContainingMultihash(ctx, mh) -} - -func (s serverApi) GetMaxPieceOffset(pieceCid cid.Cid) (uint64, error) { - return s.bapi.PiecesGetMaxOffset(s.ctx, pieceCid) -} - func (s serverApi) GetPieceInfo(pieceCID cid.Cid) (*piecestore.PieceInfo, error) { return s.bapi.PiecesGetPieceInfo(s.ctx, pieceCID) } diff --git a/cmd/booster-http/server.go b/cmd/booster-http/server.go index ca7b69d44..5271a3265 100644 --- a/cmd/booster-http/server.go +++ b/cmd/booster-http/server.go @@ -1,7 +1,6 @@ package main import ( - "bufio" "context" "encoding/json" "errors" @@ -9,7 +8,6 @@ import ( "io" "net" "net/http" - "net/url" "strings" "time" @@ -24,10 +22,6 @@ import ( "github.com/hashicorp/go-multierror" "github.com/ipfs/go-cid" "github.com/ipfs/go-datastore" - "github.com/ipld/go-car/v2" - "github.com/ipld/go-car/v2/index" - "github.com/multiformats/go-multihash" - "github.com/multiformats/go-varint" "go.opencensus.io/stats" ) @@ -40,10 +34,6 @@ var ErrNotFound = errors.New("not found") // non-zero last modified time. var lastModified = time.UnixMilli(1) -const carSuffix = ".car" -const pieceCidParam = "pieceCid" -const payloadCidParam = "payloadCid" - type apiVersion struct { Version string `json:"Version"` } @@ -60,8 +50,6 @@ type HttpServer struct { } type HttpServerApi interface { - PiecesContainingMultihash(ctx context.Context, mh multihash.Multihash) ([]cid.Cid, error) - GetMaxPieceOffset(pieceCid cid.Cid) (uint64, error) GetPieceInfo(pieceCID cid.Cid) (*piecestore.PieceInfo, error) IsUnsealed(ctx context.Context, sectorID abi.SectorNumber, offset abi.UnpaddedPieceSize, length abi.UnpaddedPieceSize) (bool, error) UnsealSectorAt(ctx context.Context, sectorID abi.SectorNumber, pieceOffset abi.UnpaddedPieceSize, length abi.UnpaddedPieceSize) (mount.Reader, error) @@ -72,7 +60,7 @@ func NewHttpServer(path string, port int, allowIndexing bool, api HttpServerApi) } func (s *HttpServer) pieceBasePath() string { - return s.path + "/piece" + return s.path + "/piece/" } func (s *HttpServer) Start(ctx context.Context) { @@ -80,7 +68,7 @@ func (s *HttpServer) Start(ctx context.Context) { listenAddr := fmt.Sprintf(":%d", s.port) handler := http.NewServeMux() - handler.HandleFunc(s.pieceBasePath(), s.handlePieceRequest) + handler.HandleFunc(s.pieceBasePath(), s.handleByPieceCid) handler.HandleFunc("/", s.handleIndex) handler.HandleFunc("/index.html", s.handleIndex) handler.HandleFunc("/info", s.handleInfo) @@ -116,36 +104,11 @@ const idxPage = `