Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Better self-service commands for DHT providing #10677

Merged
merged 17 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 3 additions & 30 deletions core/commands/bitswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ var BitswapCmd = &cmds.Command{
},

Subcommands: map[string]*cmds.Command{
"stat": bitswapStatCmd,
"wantlist": showWantlistCmd,
"ledger": ledgerCmd,
"reprovide": reprovideCmd,
"stat": bitswapStatCmd,
"wantlist": showWantlistCmd,
"ledger": ledgerCmd,
},
}

Expand Down Expand Up @@ -200,29 +199,3 @@ prints the ledger associated with a given peer.
}),
},
}

var reprovideCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Trigger reprovider.",
ShortDescription: `
Trigger reprovider to announce our data to network.
`,
},
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
nd, err := cmdenv.GetNode(env)
if err != nil {
return err
}

if !nd.IsOnline {
return ErrNotOnline
}

err = nd.Provider.Reprovide(req.Context)
if err != nil {
return err
}

return nil
},
}
2 changes: 1 addition & 1 deletion core/commands/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func TestCommands(t *testing.T) {
"/add",
"/bitswap",
"/bitswap/ledger",
"/bitswap/reprovide",
"/bitswap/stat",
"/bitswap/wantlist",
"/block",
Expand Down Expand Up @@ -72,6 +71,7 @@ func TestCommands(t *testing.T) {
"/routing/findpeer",
"/routing/findprovs",
"/routing/provide",
"/routing/reprovide",
"/diag",
"/diag/cmds",
"/diag/cmds/clear",
Expand Down
28 changes: 28 additions & 0 deletions core/commands/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"get": getValueRoutingCmd,
"put": putValueRoutingCmd,
"provide": provideRefRoutingCmd,
"reprovide": reprovideRoutingCmd,
},
}

Expand Down Expand Up @@ -235,6 +236,33 @@
Type: routing.QueryEvent{},
}

var reprovideRoutingCmd = &cmds.Command{
Status: cmds.Experimental,
Helptext: cmds.HelpText{
Tagline: "Trigger reprovider.",
ShortDescription: `
Trigger reprovider to announce our data to network.
`,
},
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
nd, err := cmdenv.GetNode(env)
if err != nil {
return err
}

Check warning on line 251 in core/commands/routing.go

View check run for this annotation

Codecov / codecov/patch

core/commands/routing.go#L247-L251

Added lines #L247 - L251 were not covered by tests

if !nd.IsOnline {
return ErrNotOnline
}

Check warning on line 255 in core/commands/routing.go

View check run for this annotation

Codecov / codecov/patch

core/commands/routing.go#L253-L255

Added lines #L253 - L255 were not covered by tests

err = nd.Provider.Reprovide(req.Context)
if err != nil {
return err
}

Check warning on line 260 in core/commands/routing.go

View check run for this annotation

Codecov / codecov/patch

core/commands/routing.go#L257-L260

Added lines #L257 - L260 were not covered by tests

return nil

Check warning on line 262 in core/commands/routing.go

View check run for this annotation

Codecov / codecov/patch

core/commands/routing.go#L262

Added line #L262 was not covered by tests
},
}

func provideKeys(ctx context.Context, r routing.Routing, cids []cid.Cid) error {
for _, c := range cids {
err := r.Provide(ctx, c, true)
Expand Down
9 changes: 8 additions & 1 deletion core/commands/stat_provide.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@
fmt.Fprintf(wtr, "TotalProvides:\t%s\n", humanNumber(s.TotalProvides))
fmt.Fprintf(wtr, "AvgProvideDuration:\t%s\n", humanDuration(s.AvgProvideDuration))
fmt.Fprintf(wtr, "LastReprovideDuration:\t%s\n", humanDuration(s.LastReprovideDuration))
fmt.Fprintf(wtr, "LastReprovideBatchSize:\t%s\n", humanNumber(s.LastReprovideBatchSize))
if !s.LastRun.IsZero() {
guillaumemichel marked this conversation as resolved.
Show resolved Hide resolved
fmt.Fprintf(wtr, "LastRun:\t%s\n", humanTime(s.LastRun))
fmt.Fprintf(wtr, "NextRun:\t%s\n", humanTime(s.NextRun))
}

Check warning on line 59 in core/commands/stat_provide.go

View check run for this annotation

Codecov / codecov/patch

core/commands/stat_provide.go#L56-L59

Added lines #L56 - L59 were not covered by tests
return nil
}),
},
Expand All @@ -64,6 +67,10 @@
return val.Truncate(time.Microsecond).String()
}

func humanTime(val time.Time) string {
return val.Format("2006-01-02 15:04:05")

Check warning on line 71 in core/commands/stat_provide.go

View check run for this annotation

Codecov / codecov/patch

core/commands/stat_provide.go#L70-L71

Added lines #L70 - L71 were not covered by tests
}

func humanNumber[T constraints.Float | constraints.Integer](n T) string {
nf := float64(n)
str := humanSI(nf, 0)
Expand Down
10 changes: 10 additions & 0 deletions docs/changelogs/v0.34.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,23 @@

- [Overview](#overview)
- [🔦 Highlights](#-highlights)
- [Reprovide command moved to routing](#reprovide-command-moved-to-routing)
- [LastRun and NextRun in `stats reprovide`](#lastrun-and-nextrun-in-stats-reprovide)
- [📝 Changelog](#-changelog)
- [👨‍👩‍👧‍👦 Contributors](#-contributors)

### Overview

### 🔦 Highlights

### Reprovide command moved to routing

Moved the `bitswap reprovide` command to `routing reprovide`.

### LastRun and NextRun in `stats reprovide`

The `stats reprovide` command now shows additional stats, indicating the last and the next run of `routing provide` and `routing reprovide`.

### 📝 Changelog

### 👨‍👩‍👧‍👦 Contributors
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,5 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/blake3 v1.3.0 // indirect
)

replace github.com/ipfs/boxo => github.com/gsergey418alt/boxo v0.0.0-20250130100910-c664359ed14f
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:Fecb
github.com/grpc-ecosystem/grpc-gateway v1.5.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 h1:asbCHRVmodnJTuQ3qamDwqVOIjwqUPTYmYuemVOx+Ys=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0/go.mod h1:ggCgvZ2r7uOoQjOyu2Y1NhHmEPPzzuhWgcza5M1Ji1I=
github.com/gsergey418alt/boxo v0.0.0-20250130100910-c664359ed14f h1:LhjTi4cSNmD/c2mM2LwjmRi+ZHGCfJVl1LCa/0UBFZc=
github.com/gsergey418alt/boxo v0.0.0-20250130100910-c664359ed14f/go.mod h1:qEIRrGNr0bitDedTCzyzBHxzNWqYmyuHgK8LG9Q83EM=
github.com/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfmKFJ6tItnhQ67kU=
github.com/gxed/hashland/murmur3 v0.0.1/go.mod h1:KjXop02n4/ckmZSnY2+HKcLud/tcmvhST0bie/0lS48=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
Expand Down Expand Up @@ -368,8 +370,6 @@ github.com/ipfs-shipyard/nopfs/ipfs v0.25.0 h1:OqNqsGZPX8zh3eFMO8Lf8EHRRnSGBMqcd
github.com/ipfs-shipyard/nopfs/ipfs v0.25.0/go.mod h1:BxhUdtBgOXg1B+gAPEplkg/GpyTZY+kCMSfsJvvydqU=
github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs=
github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0=
github.com/ipfs/boxo v0.27.2 h1:sGo4KdwBaMjdBjH08lqPJyt27Z4CO6sugne3ryX513s=
github.com/ipfs/boxo v0.27.2/go.mod h1:qEIRrGNr0bitDedTCzyzBHxzNWqYmyuHgK8LG9Q83EM=
github.com/ipfs/go-bitfield v1.1.0 h1:fh7FIo8bSwaJEh6DdTWbCeZ1eqOaOkKFI74SCnsWbGA=
github.com/ipfs/go-bitfield v1.1.0/go.mod h1:paqf1wjq/D2BBmzfTVFlJQ9IlFOZpg422HL0HqsGWHU=
github.com/ipfs/go-bitswap v0.11.0 h1:j1WVvhDX1yhG32NTC9xfxnqycqYIlhzEzLXG/cU1HyQ=
Expand Down
2 changes: 1 addition & 1 deletion test/cli/delegated_routing_v1_http_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestRoutingV1Proxy(t *testing.T) {

cidStr := nodes[0].IPFSAddStr(testutils.RandomStr(1000))
// Reprovide as initialProviderDelay still ongoing
res := nodes[0].IPFS("bitswap", "reprovide")
res := nodes[0].IPFS("routing", "reprovide")
require.NoError(t, res.Err)
res = nodes[1].IPFS("routing", "findprovs", cidStr)
assert.Equal(t, nodes[0].PeerID().String(), res.Stdout.Trimmed())
Expand Down
2 changes: 1 addition & 1 deletion test/cli/delegated_routing_v1_http_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestRoutingV1Server(t *testing.T) {
cidStr := nodes[2].IPFSAddStr(text)
_ = nodes[3].IPFSAddStr(text)
// Reprovide as initialProviderDelay still ongoing
res := nodes[3].IPFS("bitswap", "reprovide")
res := nodes[3].IPFS("routing", "reprovide")
require.NoError(t, res.Err)

cid, err := cid.Decode(cidStr)
Expand Down
12 changes: 6 additions & 6 deletions test/cli/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestProvider(t *testing.T) {

cid := nodes[0].IPFSAddStr(time.Now().String())
// Reprovide as initialProviderDelay still ongoing
res := nodes[0].IPFS("bitswap", "reprovide")
res := nodes[0].IPFS("routing", "reprovide")
require.NoError(t, res.Err)
expectProviders(t, cid, nodes[0].PeerID().String(), nodes[1:]...)
})
Expand Down Expand Up @@ -72,7 +72,7 @@ func TestProvider(t *testing.T) {

expectNoProviders(t, cid, nodes[1:]...)

nodes[0].IPFS("bitswap", "reprovide")
nodes[0].IPFS("routing", "reprovide")

expectProviders(t, cid, nodes[0].PeerID().String(), nodes[1:]...)
})
Expand All @@ -89,7 +89,7 @@ func TestProvider(t *testing.T) {

expectNoProviders(t, cid, nodes[1:]...)

nodes[0].IPFS("bitswap", "reprovide")
nodes[0].IPFS("routing", "reprovide")

expectProviders(t, cid, nodes[0].PeerID().String(), nodes[1:]...)
})
Expand All @@ -113,7 +113,7 @@ func TestProvider(t *testing.T) {
expectNoProviders(t, cidBar, nodes[1:]...)
expectNoProviders(t, cidBarDir, nodes[1:]...)

nodes[0].IPFS("bitswap", "reprovide")
nodes[0].IPFS("routing", "reprovide")

expectNoProviders(t, cidFoo, nodes[1:]...)
expectProviders(t, cidBar, nodes[0].PeerID().String(), nodes[1:]...)
Expand Down Expand Up @@ -141,7 +141,7 @@ func TestProvider(t *testing.T) {
expectNoProviders(t, cidBar, nodes[1:]...)
expectNoProviders(t, cidBarDir, nodes[1:]...)

nodes[0].IPFS("bitswap", "reprovide")
nodes[0].IPFS("routing", "reprovide")

expectNoProviders(t, cidFoo, nodes[1:]...)
expectNoProviders(t, cidBar, nodes[1:]...)
Expand All @@ -161,7 +161,7 @@ func TestProvider(t *testing.T) {

expectNoProviders(t, cid, nodes[1:]...)

nodes[0].IPFS("bitswap", "reprovide")
nodes[0].IPFS("routing", "reprovide")

expectProviders(t, cid, nodes[0].PeerID().String(), nodes[1:]...)
})
Expand Down
2 changes: 1 addition & 1 deletion test/cli/routing_dht_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func testRoutingDHT(t *testing.T, enablePubsub bool) {
t.Parallel()
hash := nodes[3].IPFSAddStr("some stuff")
// Reprovide as initialProviderDelay still ongoing
res := nodes[3].IPFS("bitswap", "reprovide")
res := nodes[3].IPFS("routing", "reprovide")
require.NoError(t, res.Err)
res = nodes[4].IPFS("routing", "findprovs", hash)
assert.Equal(t, nodes[3].PeerID().String(), res.Stdout.Trimmed())
Expand Down
Loading