diff --git a/heyfil.go b/heyfil.go index ff7d86d..6380237 100644 --- a/heyfil.go +++ b/heyfil.go @@ -38,9 +38,14 @@ func newHeyFil(o ...Option) (*heyFil, error) { if err != nil { return nil, err } + c := jsonrpc.NewClient(opts.api) + if opts.apiToken != "" { + c = jsonrpc.NewClientWithOpts(opts.api, &jsonrpc.RPCClientOpts{CustomHeaders: map[string]string{"Authorization": "Bearer " + opts.apiToken}}) + + } hf := &heyFil{ options: opts, - c: jsonrpc.NewClient(opts.api), + c: c, targets: make(map[string]*Target), toCheck: make(chan *Target, 100), checked: make(chan *Target, 100), diff --git a/main.go b/main.go index 579632d..69bdebb 100644 --- a/main.go +++ b/main.go @@ -13,12 +13,14 @@ func main() { httpIndexerEndpoint := flag.String("httpIndexerEndpoint", "https://cid.contact", "The HTTP IPNI endpoint to which announcements are made.") maxConcurrentChecks := flag.Int("maxConcurrentChecks", 10, "The maximum number of concurrent checks.") storePath := flag.String("storePath", "", "The directory to use for storing the discovered SP information.") + token := flag.String("token", "", "A bearer token to pass for auth to the filecoin api endpoint.") flag.Parse() hf, err := newHeyFil( WithHttpIndexerEndpoint(*httpIndexerEndpoint), WithMaxConcurrentChecks(*maxConcurrentChecks), WithStorePath(*storePath), + WithFileCoinAPIToken(*token), ) if err != nil { panic(err) diff --git a/options.go b/options.go index 4e93d3f..88af9bd 100644 --- a/options.go +++ b/options.go @@ -14,6 +14,7 @@ type ( Option func(*options) error options struct { api string + apiToken string h host.Host topic string headProtocolPattern *regexp.Regexp @@ -36,6 +37,7 @@ type ( func newOptions(o ...Option) (*options, error) { opts := &options{ api: `https://api.node.glif.io`, + apiToken: ``, marketDealsS3Snapshot: `https://marketdeals.s3.amazonaws.com/StateMarketDeals.json.zst`, marketDealsFilTools: `https://filecoin.tools/api/deals/list`, httpIndexerEndpoint: `https://cid.contact`, @@ -74,6 +76,13 @@ func WithFileCoinAPI(url string) Option { } } +func WithFileCoinAPIToken(token string) Option { + return func(o *options) error { + o.apiToken = token + return nil + } +} + // WithHost specifies the libp2p host. // If unset, a new host with random identity is instantiated. func WithHost(h host.Host) Option {