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

Filtering compatible node versions #259

Merged
merged 1 commit into from
Jun 8, 2020
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
1 change: 1 addition & 0 deletions clients/webassembly/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ Cargo.lock
bin/
pkg/
wasm-pack.log
node_modules
2 changes: 1 addition & 1 deletion clients/webassembly/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "nym-client-wasm"
authors = ["Dave Hrycyszyn <futurechimp@users.noreply.github.com>", "Jedrzej Stuczynski <andrew@nymtech.net>"]
version = "0.7.4"
version = "0.7.5"
edition = "2018"
keywords = ["nym", "sphinx", "wasm", "webassembly", "privacy", "client"]
license = "Apache-2.0"
Expand Down
4 changes: 2 additions & 2 deletions clients/webassembly/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ First, make sure you've got all the [Rust wasm toolchain](https://rustwasm.githu

Whenever you change any Rust in the `src` directory, run `wasm-pack build --scope nymproject` to update the built wasm artefact in the `pkg` directory.

For now, when you compile `nym-client-wasm` using `wasm-pack build --scope nymproject` you will need to manually copy the file `client.js` into the `pkg` and add it to `package.json`. Once [these](https://github.com/rustwasm/wasm-pack/issues/840) [issues](https://github.com/rustwasm/rfcs/pull/8#issuecomment-564725214) get closed, this annoying extra step will go away.
For now, when you compile `nym-client-wasm` using `wasm-pack build --scope nymproject` you will need to manually copy the file `client.js` into the `pkg` and `package.json` with entries from `package.json` on the main path. Once [these](https://github.com/rustwasm/wasm-pack/issues/840) [issues](https://github.com/rustwasm/rfcs/pull/8#issuecomment-564725214) get closed, this annoying extra step will go away.

To be clear, this is not something that most JS developers need to worry about, this is only for Nym devs. The packages on NPM have all files in place. Just install and enjoy!

Expand All @@ -37,6 +37,6 @@ To be clear, this is not something that most JS developers need to worry about,
If you're a Nym platform developer who's made changes to the Rust (or JS) files and wants to re-publish the package to NPM, here's how you do it:

1. `wasm-pack build --scope nymproject` builds the wasm binaries into the `pkg` directory (not in source control)
2. copy `client.js` into the `pkg` folder and add it to the `package.json` manifest
2. copy `client.js` into the `pkg` folder and update `package.json` manifest with the provided one
3. bump version numbers as necessary for SemVer
4. `wasm-pack publish --access=public` will publish your changed package to NPM
14 changes: 13 additions & 1 deletion clients/webassembly/client.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as wasm from ".";

import { version } from './package.json';
import { major, minor, parse } from "semver";
/**
* A Nym identity, consisting of a public/private keypair and a Nym
* gateway address.
Expand Down Expand Up @@ -49,6 +50,15 @@ export class Client {
return this.authToken !== null
}

/**
* Checks if given node is compatible with this client
*/
isNodeVersionCompatible(node) {
const clientVersion = parse(version);
const mixVersion = parse(node.version);
return major(clientVersion) === major(mixVersion) && minor(clientVersion) === minor(mixVersion)
}

/**
* Update the Nym network topology.
*
Expand All @@ -57,6 +67,8 @@ export class Client {
async updateTopology() {
let response = await http('get', this.topologyEndpoint);
let topology = JSON.parse(response); // make sure it's a valid json
topology.mixNodes = topology.mixNodes.filter(this.isNodeVersionCompatible)
topology.gatewayNodes = topology.gatewayNodes.filter(this.isNodeVersionCompatible)
this.topology = topology;
this.onUpdatedTopology();
return topology;
Expand Down
2 changes: 1 addition & 1 deletion clients/webassembly/js-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
"webpack-dev-server": "^3.11.0"
},
"dependencies": {
"@nymproject/nym-client-wasm": "^0.7.4"
"@nymproject/nym-client-wasm": "^0.7.5"
}
}
11 changes: 11 additions & 0 deletions clients/webassembly/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions clients/webassembly/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"files": [
"client.js"
],
"dependencies": {
"semver": "^7.3.2"
}
}