Skip to content

Commit

Permalink
Add support for a helia container
Browse files Browse the repository at this point in the history
  • Loading branch information
dennis-tra committed Oct 4, 2023
1 parent 38446ef commit 2bb9b29
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
36 changes: 26 additions & 10 deletions cmd_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -330,15 +330,15 @@ 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:
panic(fmt.Sprintf("unknown measurement type: %s", mType))
}
}

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)
}

Expand Down

0 comments on commit 2bb9b29

Please sign in to comment.