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

P2P updater #473

Closed
wants to merge 4 commits into from
Closed
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"nodecast-js": "^1.0.1",
"opensubtitles-api": "^3.1.0",
"peerflix": "^0.35.0",
"webtorrent": "0.97.2",
Copy link
Member

Choose a reason for hiding this comment

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

better use 0.x.x or ^0.97.2

"q": "2.0.3",
"read-torrent": "1.3.0",
"readdirp": "*",
Expand Down
1 change: 0 additions & 1 deletion src/app/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,5 @@ var

// Torrent engines
peerflix = require('peerflix'),

// NodeJS
child = require('child_process');
1 change: 1 addition & 0 deletions src/app/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ Settings.tmpLocation = path.join(os.tmpDir(), Settings.projectName);
Settings.databaseLocation = path.join(data_path, 'data');
Settings.deleteTmpOnClose = true;
Settings.automaticUpdating = true;
Settings.UpdateSeed = true;
Copy link
Member

Choose a reason for hiding this comment

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

either Settings.update = {seed: true}, or Settings.seedUpdate

Copy link
Author

Choose a reason for hiding this comment

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

Settings.seedUpdate is a parameter on setting container ,
People can disable seeding if they are on the last version

Copy link
Member

Choose a reason for hiding this comment

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

it's just a name nitpick 'seedUpdate' isn't really clear to me.

Copy link
Member

Choose a reason for hiding this comment

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

how windowsy of you

Copy link
Member

Choose a reason for hiding this comment

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

naming convention is bad, you should use seedUpdate or redistributeUpdater, but don't start with an uppercase :)

Settings.events = true;
Settings.minimizeToTray = false;
Settings.bigPicture = false;
Expand Down
8 changes: 6 additions & 2 deletions src/app/templates/settings-container.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -556,8 +556,12 @@
<label class="settings-label" for="cb5"><%= i18n.__("Activate automatic updating") %></label>
</span>
<span>
<input class="settings-checkbox" name="events" id="cb6" type="checkbox" <%=(Settings.events? "checked='checked'":"")%>>
<label class="settings-label" for="cb6"><%= i18n.__("Celebrate various events") %></label>
<input class="settings-checkbox" name="UpdateSeed" id="cb6" type="checkbox" <%=(Settings.UpdateSeed? "checked='checked'":"")%>>
<label class="settings-label" for="cb6"><%= i18n.__("Activate Update Seeding") %></label>
Copy link
Member

Choose a reason for hiding this comment

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

It's personnal and doesn't really impair the merge of this, but I don't like the string. For starter, you don't need the word "activate" in it, the checkbox says that already.
How about:

  • "Seed update files to other users"
  • "Redistribute the update packages"

</span>
<span>
<input class="settings-checkbox" name="events" id="cb7" type="checkbox" <%=(Settings.events? "checked='checked'":"")%>>
<label class="settings-label" for="cb7"><%= i18n.__("Celebrate various events") %></label>
</span>
<span>
<input class="settings-checkbox" name="minimizeToTray" id="minimizeToTray" type="checkbox" <%=(Settings.minimizeToTray? "checked='checked'":"")%>>
Expand Down
43 changes: 34 additions & 9 deletions src/app/updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

var CHANNELS = ['stable', 'beta', 'nightly'],
FILENAME = 'package.nw.new',
WebTorrent = require('webtorrent'),
client = new WebTorrent({dht: true,maxConns: '5'}),
Copy link
Member

Choose a reason for hiding this comment

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

Is the maxConns needed? It fallsback to 55, why forcing a lower number?

VERIFY_PUBKEY = Settings.updateKey;

function forcedBind(func, thisVar) {
Expand All @@ -19,7 +21,7 @@
var self = this;

this.options = _.defaults(options || {}, {
endpoint: AdvSettings.get('updateEndpoint').url + 'update3.json' + '?version=' + App.settings.version + '&nwversion=' + process.versions['node-webkit'],
endpoint: AdvSettings.get('updateEndpoint').url + 'p2pudpate.json' + '?version=' + App.settings.version + '&nwversion=' + process.versions['node-webkit'],
channel: 'beta'
});

Expand Down Expand Up @@ -77,21 +79,44 @@
self.updateData = updateData;
return true;
}
if (App.settings.UpdateSeed) {
client.add(updateData.UpdateUrl, { path: os.tmpdir() }, function (torrent) {
torrent.on('error', function (err) {
win.debug('ERROR' + err.message);
});
torrent.on('done', function () {
win.debug('Seeding the Current Update!');
Copy link
Member

Choose a reason for hiding this comment

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

Once 'done', it doesn't seed, according to my tests. You need to explicitly set it with the .seed() api call (I think?)

Copy link
Member

Choose a reason for hiding this comment

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

so it looks like seed() is to create a new torrent, i'm not sure how seed control works...

});
});
}

win.debug('Not updating because we are running the latest version');
return false;
});
};

Updater.prototype.download = function (source, output) {


Updater.prototype.download = function (source, outputDir) {
var defer = Q.defer();
var downloadStream = request(source);
win.debug('Downloading update... Please allow a few minutes');
downloadStream.pipe(fs.createWriteStream(output));
downloadStream.on('complete', function () {
win.debug('Update downloaded!');
defer.resolve(output);
client.on('error', function (err) {
win.debug('ERROR: ' + err.message);
defer.reject(err);
});

client.add(source, {
path: outputDir
}, function (torrent) {
win.debug('Downloading update... Please allow a few minutes');
torrent.on('error', function (err) {
win.debug('ERROR' + err.message);
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't it be win.warn('Downloading update failed:', error) ? Make it visible but not a 'breaking' error, and also comprehensible.

defer.reject(err);
});
torrent.on('done', function () {
win.debug('Update downloaded!');
defer.resolve(path.join(outputDir, torrent.name));
Copy link
Member

Choose a reason for hiding this comment

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

torrent.name contains the extension of the file in this case? Because there's a risk it's a directory

Copy link
Member

Choose a reason for hiding this comment

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

we create the update torrent.

});
});

return defer.promise;
};

Expand Down