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

Persist DHT nodes #1431

Open
wants to merge 9 commits into
base: master
from
Open

Conversation

@bookmoons
Copy link

bookmoons commented Jul 14, 2018

Persists DHT nodes to disk every 15 minutes.
Loads persisted nodes on construction.
Enabled by default.

Default save file is dht.json, under crossplatform app data folder provided by app-data-folder.

Adds option dhtState to configure:

  • false disables
  • true enables with default path
  • String specifies path to custom save file

Closes #72.

Persists DHT nodes to disk every 15 minutes.
Loads persisted nodes on construction.
Enabled by default.

Default save file is dht.json,
under crossplatform app data folder provided by app-data-folder.

Adds option dhtState to configure:
* false disables
* true enables with default path
* String specifies path to custom save file
@welcome

This comment has been minimized.

Copy link

welcome bot commented Jul 14, 2018

🙌 Thanks for opening this pull request! You're awesome.

@bookmoons

This comment has been minimized.

Copy link
Author

bookmoons commented Jul 14, 2018

Hi guys. Aiming to implement #72 here, persisting DHT nodes. All local tests succeed.

It uses app-data-folder to get a good crossplatform default location for variable app data.

Loading is unfortunately synchronous. Making the DHT initialization async breaks the client for some reason unclear to me. Usage expects to call methods immediately, but they start failing if DHT loading is not finished. Even with that ready event delayed until everything is ready. If there's an easy way to fix that I can update.

@bookmoons

This comment has been minimized.

Copy link
Author

bookmoons commented Jul 14, 2018

I'm proposing a new option dhtState here. Default is true, which enables persistence with the default path. A string enables with a custom path. False disables.

@DiegoRBaquero

This comment has been minimized.

Copy link
Member

DiegoRBaquero commented Jul 24, 2018

I like this, but we need some tests. Would you add them?

bookmoons added 6 commits Jul 30, 2018
Increases cleanliness of index.js.
Uses loopback for the test DHT server, a local address provided
by the network-address module for the client. This is the pattern
used in other tests.
Saved node data and the bootstrap list use different formats.
Converts to the bootstrap format.
Prior logic disabled DHT state load with any bootstrap value,
including a false to disable. Changes to allowing DHT state load
if bootstrap is explicitly disabled with a falsy value.
@bookmoons

This comment has been minimized.

Copy link
Author

bookmoons commented Jul 30, 2018

Thanks for looking it over. I've added 2 tests, 1 for saving, 1 for loading. They're in persist-dht-nodes.js. They test with temp files. All tests are passing, including the new ones.

Started splitting things out into lib/dhtpersist.js and ended up not needing it. I left it in; think it makes index.js cleaner.

I added an API method saveDhtstate, to make it possible to get at it in the test. Not sure if that's a good idea. It starts here:
https://github.com/webtorrent/webtorrent/pull/1431/files#diff-168726dbe96b3ce427e7fedce31bb0bcR439

@@ -19,6 +20,7 @@ var randombytes = require('randombytes')
var speedometer = require('speedometer')
var zeroFill = require('zero-fill')

var dhtPersist = require('./lib/dhtpersist') // browser exclude

This comment has been minimized.

Copy link
@KayleePop

KayleePop Aug 3, 2018

Contributor

It says browser exclude, but it's not actually excluded in the browser field of package.json?

like this

"browser": {
  "./lib/dhtpersist": false
}

This comment has been minimized.

Copy link
@bookmoons

bookmoons Aug 6, 2018

Author

Misunderstood what that was about. I was thinking it was some control message to the bundler. I've updated.

docs/api.md Outdated
peerId: String|Buffer, // Wire protocol peer ID (default=randomly generated)
tracker: Boolean|Object, // Enable trackers (default=true), or options object for Tracker
dht: Boolean|Object, // Enable DHT (default=true), or options object for DHT
dhtState: Boolean|String, // Persist DHT nodes (default=true), or save file path

This comment has been minimized.

Copy link
@KayleePop

KayleePop Aug 3, 2018

Contributor

I think this would be clearer as two separate variables. A boolean for whether to persist the state, and a file path for persisting the state

Maybe named (doesn't matter)

{
  persistDht: Boolean,
  persistDhtPath: String
}

This comment has been minimized.

Copy link
@bookmoons

bookmoons Aug 6, 2018

Author

I've updated to split them that way.

bookmoons added 2 commits Aug 6, 2018
Splits from single option dhtState into 2 options:
* persistDht - Boolean. Flag to enable.
* persistDhtPath - String. Optional custom path for save file.
@bookmoons

This comment has been minimized.

Copy link
Author

bookmoons commented Aug 6, 2018

Thanks for the review. Didn't even show up in my activity list. Will have to find a better way to watch for that. I've addressed both of them.

@bookmoons

This comment has been minimized.

Copy link
Author

bookmoons commented Aug 6, 2018

I guess one of the automated builds failed. It looks like it failed on npm install. Is it possible that was a temporary network error?

@DiegoRBaquero

This comment has been minimized.

Copy link
Member

DiegoRBaquero commented Aug 24, 2018

I don't like 3 new dependencies, any way these could be integrated as libs?

Also, should we enable this by default? @feross ?

@bookmoons

This comment has been minimized.

Copy link
Author

bookmoons commented Aug 27, 2018

I don't like 3 new dependencies, any way these could be integrated as libs?

I'm dug into something else for a while here, but will look at this when I have a chance.

@stale

This comment has been minimized.

Copy link

stale bot commented Nov 25, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the stale label Nov 25, 2018
@stale stale bot closed this Dec 2, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Mar 2, 2019
@webtorrent webtorrent unlocked this conversation Sep 6, 2019
@feross feross added the enhancement label Sep 6, 2019
@feross feross reopened this Sep 6, 2019
@stale stale bot removed the stale label Sep 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked issues

Successfully merging this pull request may close these issues.

4 participants
You can’t perform that action at this time.