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

reprovider: add config option to set reprovide interval #3101

Merged
merged 2 commits into from
Aug 20, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 14 additions & 1 deletion core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,20 @@ func (n *IpfsNode) startOnlineServices(ctx context.Context, routingOption Routin
}

n.Reprovider = rp.NewReprovider(n.Routing, n.Blockstore)
go n.Reprovider.ProvideEvery(ctx, kReprovideFrequency)

if cfg.Reprovider.Interval != "0" {
interval := kReprovideFrequency
if cfg.Reprovider.Interval != "" {
dur, err := time.ParseDuration(cfg.Reprovider.Interval)
if err != nil {
return err
}

interval = dur
}

go n.Reprovider.ProvideEvery(ctx, interval)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • i wonder if this will have serious adverse effects by triggering or not triggering a whole large codepath.
  • I think this may be more resistant to error and code modification if we always do go n.Reprovider.ProvideEvery(ctx, interval) instead of guarding it in an if clause. The func can treats 0 (or a negative number) as "oh, do nothing? ok and it either waits or exits". Your code becomes:
interval := kReprovideFrequency
if cfg.Reprovider.Interval != "" {
  dur, err := time.ParseDuration(cfg.Reprovider.Interval)
  if err != nil {
    return err
  }
  interval = dur
}
go n.Reprovider.ProvideEvery(ctx, interval)

And you always guard in n.Reprovider.ProvideEvery which should happen already.

}

// setup local discovery
if do != nil {
Expand Down
11 changes: 11 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ a running daemon do not read the config file at runtime.
- [`Identity`](#identity)
- [`Ipns`](#ipns)
- [`Mounts`](#mounts)
- [`ReproviderInterval`](#reproviderinterval)
- [`SupernodeRouting`](#supernoderouting)
- [`Swarm`](#swarm)
- [`Tour`](#tour)
Expand Down Expand Up @@ -192,6 +193,16 @@ Mountpoint for `/ipns/`.
- `FuseAllowOther`
Sets the FUSE allow other option on the mountpoint.

## `ReproviderInterval`
Sets the time between rounds of reproviding local content to the routing
system. If unset, it defaults to 12 hours. If set to the value `"0"` it will
disable content reproviding.

Note: disabling content reproviding will result in other nodes on the network
not being able to discover that you have the objects that you have. If you want
to have this disabled and keep the network aware of what you have, you must
manually announce your content periodically.

## `SupernodeRouting`
Deprecated.

Expand Down
2 changes: 2 additions & 0 deletions repo/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ type Config struct {
SupernodeRouting SupernodeClientConfig // local node's routing servers (if SupernodeRouting enabled)
API API // local node's API settings
Swarm SwarmConfig

Reprovider Reprovider
}

const (
Expand Down
3 changes: 3 additions & 0 deletions repo/config/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ func Init(out io.Writer, nBitsForKeypair int) (*Config, error) {
"Access-Control-Allow-Headers": []string{"X-Requested-With"},
},
},
Reprovider: Reprovider{
Interval: "12h",
},
}

return conf, nil
Expand Down
5 changes: 5 additions & 0 deletions repo/config/reprovider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package config

type Reprovider struct {
Interval string // Time period to reprovide locally stored objects to the network
}