From 2bb9b29b37698eb9d08826c10670c833922ad753 Mon Sep 17 00:00:00 2001 From: Dennis Trautwein Date: Wed, 4 Oct 2023 09:47:54 +0200 Subject: [PATCH] Add support for a helia container --- cmd_run.go | 36 ++++++++++++++++++++++++++---------- probe.go | 6 +++--- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/cmd_run.go b/cmd_run.go index 9769318..2b108c5 100644 --- a/cmd_run.go +++ b/cmd_run.go @@ -43,6 +43,12 @@ var RunCommand = &cli.Command{ EnvVars: []string{"TIROS_RUN_TIMES"}, Value: 3, }, + &cli.BoolFlag{ + Name: "lookup-providers", + Usage: "Whether to lookup website providers", + EnvVars: []string{"TIROS_RUN_LOOKUP_PROVIDERS"}, + Value: true, + }, &cli.BoolFlag{ Name: "dry-run", Usage: "Whether to skip DB interactions", @@ -79,21 +85,21 @@ var RunCommand = &cli.Command{ EnvVars: []string{"TIROS_RUN_DATABASE_SSL_MODE"}, }, &cli.StringFlag{ - Name: "kubo-host", - Usage: "port to reach the Kubo Gateway", - EnvVars: []string{"TIROS_RUN_KUBO_HOST"}, + Name: "ipfs-host", + Usage: "host at which to reach the IPFS Gateway", + EnvVars: []string{"TIROS_RUN_IPFS_HOST", "TIROS_RUN_KUBO_HOST" /* <- legacy */}, Value: "localhost", }, &cli.IntFlag{ Name: "kubo-api-port", - Usage: "port to reach the Kubo API", + Usage: "port to reach a Kubo-compatible RPC API", EnvVars: []string{"TIROS_RUN_KUBO_API_PORT"}, Value: 5001, }, &cli.IntFlag{ - Name: "kubo-gateway-port", - Usage: "port to reach the Kubo Gateway", - EnvVars: []string{"TIROS_RUN_KUBO_GATEWAY_PORT"}, + Name: "ipfs-gateway-port", + Usage: "port to reach the IPFS Gateway", + EnvVars: []string{"TIROS_RUN_IPFS_GATEWAY_PORT", "TIROS_RUN_KUBO_GATEWAY_PORT" /* <- legacy */}, Value: 8080, }, &cli.IntFlag{ @@ -146,7 +152,10 @@ func RunAction(c *cli.Context) error { } // Initialize kubo client - kubo := shell.NewShell(fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", c.Int("kubo-api-port"))) + var kubo *shell.Shell + if c.Int("kubo-api-port") != 0 { + kubo = shell.NewShell(fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", c.Int("kubo-api-port"))) + } // Initialize maxmind client mmClient, err := maxmind.NewClient() @@ -199,7 +208,12 @@ func RunAction(c *cli.Context) error { probeResults := make(chan *probeResult) go t.measureWebsites(c, websites, probeResults) - go t.findAllProviders(c, websites, providerResults) + + if c.Bool("lookup-providers") { + go t.findAllProviders(c, websites, providerResults) + } else { + close(providerResults) + } for { select { @@ -244,7 +258,9 @@ func RunAction(c *cli.Context) error { func (t *tiros) InitRun(c *cli.Context) (*models.Run, error) { version, sha, err := t.kubo.Version() if err != nil { - return nil, fmt.Errorf("kubo api offline: %w", err) + // return nil, fmt.Errorf("kubo api offline: %w", err) + version = "helia" + sha = "1234567" } dbRun, err := t.dbClient.InsertRun(c, fmt.Sprintf("%s-%s", version, sha)) diff --git a/probe.go b/probe.go index dedac12..f3ed50d 100644 --- a/probe.go +++ b/probe.go @@ -68,7 +68,7 @@ func (t *tiros) measureWebsites(c *cli.Context, websites []string, results chan< results <- pr if mType == models.MeasurementTypeKUBO { - if err = t.KuboGC(c.Context); err != nil { + if err = t.GarbageCollect(c.Context); err != nil { log.WithError(err).Warnln("error running kubo gc") continue } @@ -330,7 +330,7 @@ func (p *probe) close() { func websiteURL(c *cli.Context, website string, mType string) string { switch mType { case models.MeasurementTypeKUBO: - return fmt.Sprintf("http://%s:%d/ipns/%s", c.String("kubo-host"), c.Int("kubo-gateway-port"), website) + return fmt.Sprintf("http://%s:%d/ipns/%s", c.String("ipfs-host"), c.Int("ipfs-gateway-port"), website) case models.MeasurementTypeHTTP: return fmt.Sprintf("https://%s", website) default: @@ -338,7 +338,7 @@ func websiteURL(c *cli.Context, website string, mType string) string { } } -func (t *tiros) KuboGC(ctx context.Context) error { +func (t *tiros) GarbageCollect(ctx context.Context) error { return t.kubo.Request("repo/gc").Exec(ctx, nil) }