Skip to content

Commit

Permalink
don't be as aggressive about using :3000 / :3001 on client request (#254
Browse files Browse the repository at this point in the history
)

* don't be as aggressive about using :3000 / :3001 on client request
  • Loading branch information
willscott authored Mar 10, 2022
1 parent ff29a11 commit 5ff04b6
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 16 deletions.
4 changes: 1 addition & 3 deletions api/v0/admin/client/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (
)

const (
adminPort = 3002

importResource = "/import"
ingestResource = "/ingest"
)
Expand All @@ -33,7 +31,7 @@ type Client struct {

// New creates a new admin HTTP client.
func New(baseURL string, options ...httpclient.Option) (*Client, error) {
u, c, err := httpclient.New(baseURL, "", adminPort, options...)
u, c, err := httpclient.New(baseURL, "", options...)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions api/v0/finder/client/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
)

const (
finderPort = 3000
finderPath = "/multihash"
providersPath = "/providers"
)
Expand All @@ -29,7 +28,7 @@ type Client struct {

// New creates a new finder HTTP client.
func New(baseURL string, options ...httpclient.Option) (*Client, error) {
u, c, err := httpclient.New(baseURL, "", finderPort, options...)
u, c, err := httpclient.New(baseURL, "", options...)
if err != nil {
return nil, err
}
Expand Down
8 changes: 2 additions & 6 deletions api/v0/httpclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@ package httpclient

import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"strings"

"github.com/filecoin-project/storetheindex/api/v0"
v0 "github.com/filecoin-project/storetheindex/api/v0"
)

// New creates a base URL and a new http.Client. The default port is only used
// if baseURL does not contain a port.
func New(baseURL, resource string, defaultPort int, options ...Option) (*url.URL, *http.Client, error) {
func New(baseURL, resource string, options ...Option) (*url.URL, *http.Client, error) {
if !strings.HasPrefix(baseURL, "http://") && !strings.HasPrefix(baseURL, "https://") {
baseURL = "http://" + baseURL
}
Expand All @@ -27,9 +26,6 @@ func New(baseURL, resource string, defaultPort int, options ...Option) (*url.URL
return nil, nil, errors.New("url missing scheme")
}
u.Path = resource
if u.Port() == "" {
u.Host += fmt.Sprintf(":%d", defaultPort)
}

var cfg clientConfig
if err := cfg.apply(options...); err != nil {
Expand Down
3 changes: 1 addition & 2 deletions api/v0/ingest/client/http/ingest.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
)

const (
ingestPort = 3001
announcePath = "/ingest/announce"
registerPath = "/register"
indexContentPath = "/ingest/content"
Expand All @@ -33,7 +32,7 @@ type Client struct {

// New creates a new ingest http Client
func New(baseURL string, options ...httpclient.Option) (*Client, error) {
u, c, err := httpclient.New(baseURL, "", ingestPort, options...)
u, c, err := httpclient.New(baseURL, "", options...)
if err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions command/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var indexerHostFlag = altsrc.NewStringFlag(&cli.StringFlag{
Name: "indexer",
Usage: "Host or host:port of indexer to use",
EnvVars: []string{"INDEXER"},
Aliases: []string{"i"},
Required: false,
Value: "localhost",
})
Expand Down
6 changes: 3 additions & 3 deletions e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func TestEndToEndWithReferenceProvider(t *testing.T) {
}

// Allow provider advertisements, regardless of default policy.
e.run(indexer, "admin", "allow", "--peer", providerID)
e.run(indexer, "admin", "allow", "-i", "localhost:3002", "--peer", providerID)

// Import a car file into the provider. This will cause the provider to
// publish an advertisement that the indexer will read. The indexer will
Expand All @@ -243,7 +243,7 @@ func TestEndToEndWithReferenceProvider(t *testing.T) {
"2DrjgbFdhNiSJghFWcQbzw6E8y4jU1Z7ZsWo3dJbYxwGTNFmAj",
"2DrjgbFY1BnkgZwA3oL7ijiDn7sJMf4bhhQNTtDqgZP826vGzv",
} {
findOutput := e.run(provider, "find", "-i", "localhost", "-mh", mh)
findOutput := e.run(provider, "find", "-i", "localhost:3000", "-mh", mh)
t.Logf("import output:\n%s\n", findOutput)

if bytes.Contains(findOutput, []byte("not found")) {
Expand Down Expand Up @@ -272,7 +272,7 @@ func TestEndToEndWithReferenceProvider(t *testing.T) {
"2DrjgbFdhNiSJghFWcQbzw6E8y4jU1Z7ZsWo3dJbYxwGTNFmAj",
"2DrjgbFY1BnkgZwA3oL7ijiDn7sJMf4bhhQNTtDqgZP826vGzv",
} {
findOutput := e.run(provider, "find", "-i", "localhost", "-mh", mh)
findOutput := e.run(provider, "find", "-i", "localhost:3000", "-mh", mh)
t.Logf("import output:\n%s\n", findOutput)

if !bytes.Contains(findOutput, []byte("not found")) {
Expand Down

0 comments on commit 5ff04b6

Please sign in to comment.