Files
nym/clients/webassembly/react-example/src/App.js
T
Jędrzej Stuczyński 2fa5c3c3b7 Release/v0.9.0 (#453)
* Feature/wasm update (#341)

* Split text and binary client apis

* Very initial attempt at new serialization

* Defined ser+de for Recipient and ReplySURB

* Response errors

* builds with changes

* Working WS API + moved to separate crate

* updated python examples

* Fixed parsing bug

* Updated go examples

* Updated rust examples

* formatting

* Removed unused imports

* dependency updates

* Further dependency changes

* nymsphinx exposingn framing only if not in wasm32

* Cargo lock changes before develop merge

* Pending work

* Actually sending and receiving websocket from rust!

* more WIP

* Initial wasm client + establishing shared key with gateway!

* Splitting and sending a message!

* WIP

* WIP

* Initial wasm-ification of the gateway client

* Passing reconstruction result to js callback!

* Initial WASM cleaning pass

* Dependency pruning

* Moved processing loop to received_processor + at least ack unwrappingn

* Post merge fix

* Kinda updated react example

* Old print statement removed

* Removed yarn.lock

* Fixed building issue for other clients

* Fixed travis test command

* Updated wasm publishing instructions

* Feature/instant sending (#359)

* Ability to set client in vpn mode

* Connection handler for mixnode

* Initial vpn mode for mixes

* Updated SphinxCodec to contain more metadata

* Renaming

* Removed handle from mixnet client and introduced forwarder

* Mixnode using new forwarder

* Mixnode common module containing shared packet processing

* ibid. incorporated inside mixnode

* New processing for gateway

* Type cleanup

* Wasm fix

* Fixed client config

* Fixed mixnode runtime issues

* Formatting

* Client re-using secret on 'normal' packets

* Using the same key for acks

* WIP

* vpn key manager cleanup

* wasm fix

* VPN_KEY_REUSE_LIMIT moved to config

* Moved AckDelayQueue to separate common crate

* Key cache invalidator

* Updated dashmap used in gateway

* Old typo

* Additional comment

* Cargo fmt

* Fixed tests

* Sphinx update

* cache ttl as config option

* Cargo fmt

* Feature/network monitor (#369)

* WIP commit

* Further into errors (WIP)

* WIP commit, more stuff compiling, but now we switch to sneaky Jedrzej trick

* Websocket connections starting to work

* WIP

* Constructing the socket stream in one go

* Nicer connections. Getting topology now works.

* Fixing startup message

* Injecting directory uri

* Injecting good mixndodes

* Deleting old healthcheck

* Starting to wrap gateway client

* Splitting out good topology contstruction

* Starting to breathe finally

* Fixed layer assignment error

* Starting gateway client in a better spot

* Cleanup

* Renamed construct() to new()

* Injected channels, removed websockets

* Added a MixnetListener to deal with returned packet traffic

* Simplification

* Renaming and commenting a few things

* Renamed temp variables

* Fixed variable names

* Made errors a bit more explicit on message reconstruction

* Added the mixmining route / object to the directory server client

* Recipient is always "me", a bit easier to understand what's going on

* Subbing in test nodes works

* Using QA directory

* Noting which directory server we're using at monitor start

* Adding Debug to MixStatus so we can print it more easily

* Prettification of startup messages

* Notifying directory of successful packet receipt

* All nodes now being tested

* Now able to do timer-based test runs and detect the last node tested

* Renamed mixnet_listener to notifier

* Moved message chunking into its own home

* Starting to pull out packet sends

* Basic functionality working!

* Enabled timer runs forever

* License notices

* Depdendency cleanup

* Import cleanup

* Moved to implicit tokio runtime

* Removed some unnecessary data clones

* Fixed monitor doing two runs at startup rather than one

* dalek version updates

* This should have been split but got carried away

* Initial ipv6 support

* Don't test outdated nodes

* Added network monitor to default workspace members

* Actually sending reports

* Batch-sending mix status

* Cargo fmt

* Minor cleanup

* Malformed Cargo.lock

* Post-merge fixes

* Defined constant in main.rs for enabling detailed reporting

* Updated package versions of the system

* Checking version compatibility on startup

Co-authored-by: Dave Hrycyszyn <futurechimp@users.noreply.github.com>

* Added sphinx socks to default workspace members (#358)

* Feature/version in config (#376)

* Added version field to config files

* Removed built dependency

* Missing non-removed call to built

* Corrected version on client-core (#377)

* Feature/remove validator (#380)

* Replacing Rust validator sketch with Cosmos-based code.

* Removing old build instructions

* go fmt on generated code

* Removing build files for github and pi

* Starting transplant surgery

* Directory now running in validator, sans metrics

* Updating go sum

* A partly-working directory startup integrated into the nymcli app.

* Removing the Swagger docs header from nymcli, it can live in server.go

* Working swagger docs.

* Updating test title on Swagger docs

* Directory server now integrated into validator (primitive but working)

* Noted location of mixmining reports database.

* Bumped golang version

* Removing validator cargo files.

* Moving directory API init method into the nymd module

* Ditching a test which is causing tooling problems - presence will go away soon anyway

* Removing the validator and merging develop

* Update README.md

* Update README.md

* Feature/upgrade command (#381)

* Exposed version parsing from version checker

* Ability to upgrade mixnode from 0.8.X to 0.9.0

* Ability to upgrade gateway from 0.8.X to 0.9.0

* Ability to upgrade native client from 0.8.X to 0.9.0

* Ability to upgrade socks5 client from 0.8.X to 0.9.0

* Typo

* Minor renaming

* Preventing upgrade if current is not a release version

* Additional upgrade restrictions

* Corrected version bound

* Feature/mix ed25519 identity (#388)

* Introduced identity keypair to mixnode

* Updated upgrade 0.9.0 mix upgrade instructions

* Printing failed upgrade notice when it failed

* Moved printing upgrade start notice to beginning of function

* Feature/double init prevention (#386)

* Updated NymConfig trait making id always obligatory. Also added extra default method implementations

* Preventing init on mixnodes that were initialised before

* Quotes before mix id

* Preventing init on gateways that were initialised before

* Preventing init on native clients that were initialised before

* Preventing init on socks5 clients that were initialised before

* Feature/duration cleanup (#391)

* Mixnode using Duration for time intervals + human readable config fields for them

* Removed old comment

* Native client using Duration for time intervals + human readable config fields for them

* Socks5 client using Duration for time intervals + human readable config fields for them

* Gateway using Duration for time intervals + human readable config fields for them

* Config compatibility with 0.8.0 debug values

* Fixed previous merge issue

* Moving subsidiary functions down below main so we can see where thing start

* Feature/fix dependabot alerts (#393)

* Fixing a dependabot alert

* Fixing npm audit failures in js example for webassembly client

* Fixed some more npm audit problems

* Explicitly handling base58 key recovery errors (#396)

* Fix compiler warnings for unneeded mut (#398)

* moved new_v4_with_node to test only section (#392)

* moved new_v4_with_node to test only section

* cargo fmt

* Feature/directory server transition (#401)

* Initial changes to validator client API

* Updated models

* GatewayRegistrationInfo constructor

* Change validator topology to convert into NymTopology without failure

* Mixnode registering and unregistering presence

* Directory -> Validator renamings + adjustments

* Updated upgrade command for mixnode

* Extracted metrics part of directory client into separate library

* Removed no longer needed traits

* Integrated new metrics client into mixnode

* Introduced the same set of changes to the gateway

* Getting active topology in client core via validator client

* Updated clients to get correct topology

* Introduced mix mining endpoints to validator client

* Network monitor using validator client

* Removed directory client

* Updated wasm client

* Temporarily disabled the test

* Checking ok status for validator client response

* Updated upgrade command for clients

* Allowing using old presence directory as new validator endpoint for mixnodes and gateways

* Fixed tests in non-default crates

* Feature/validator api update (#402)

* Updated validator API routes

* missing comment

* Feature/wasm client fix (#399)

* Disabling wasm optimization for the moment, it isn't working on my machine

* Updating the React example back to a working state, 0.8.1 npm package is published.

* Merging develop into bugfix

* Upgrading react-scripts to fix a major vulnerability

* Using metrics interval received from server (#403)

* Using metrics interval received from server

* Test fix

* Feature/error on noninit (#404)

* More graceful shutdown in case of uninitialised client/node

* Performing version check on binary `run`

* Feature/no run config flag (#405)

* Removed `--config` parameter in `run` commands

* Removed old tests that were doing disk IO

* Renamed directory arguments to validator (#408)

* Feature/max retry (#409)

* Maximum number of allowed reconnection attempts

* Requiring initial internode connection to be successful

* Decreased logging level for failing to establish initial connection

* Feature/controlled reinit (#410)

* Allowing init with existing id but keeps existing keys

* Removed unused imports

* Removed debug print statement (#411)

* Updated upgrade commands to set new default validator (#413)

* Feature/network monitor file topology (#412)

* Network monitor loading 'good' topology from files instead

* Update .gitignore

* Passing address of validator as an argument

* Made detailed report const flag into an argument

* Flag to start network requester in open proxy mode (#418)

* Renamed 'sphinx-socks' to 'network-requester' (#417)

* Added option to set incentives address during mix and gateway init (#419)

* Updated validator topology (#420)

* Bugfix/upgrade fix (#421)

* Added default for incentives address when deserializing

* Ability to optionally pass incentives address during upgrade

* Feature/socks improvements (#423)

* Changed AvailableReader from Future to Stream

* comment formatting

* WIP

* Maximum number of bytes read per poll

* More detailed socks5 printing

* Split up socks5 service provider runner

* Fixed closing proxy too soon on one side

* Additional log information

* Printing connection id in log target

* Adjusted some constants

* Target field in log

* Removed dead code

* Decreased logging level

* Explicitly seperated 'Send' and 'Connect' request + data buffering

* Temporarily commented out test that fails due to not understanding limitations of tokio test io builder

* Fixed socks5 tests

* Starting cover traffic stream under correct condition (#422)

* Fixed bunch of clippy warnings (#427)

* Updated default sending rates (#430)

* Feature/explorer (#431)

* Initial commit of the new dashboard code.

* Periodically grabbing topology json

* Pulling file saving out into its own module

* Ignoring downloaded topology file

* Moved everything public into a public folder

* Refreshing the mixmining report

* Mounting static files from /public

* Including mixminiming report grabber

* Leaving the route in place to pick up later. It's not used right now.

* Removing json download from git

* Ignoring topology download

* Moving recurrent jobs in to a jobs module

* Adding websocket dependencies

* Starting to get client/server websocket functionality running.

* Fixing unused imports

* Separating client and server functionality a bit more cleanly

* WIP to sketch out the ws client and server a bit more

* Initial metrics broadcaster

* Import fixup

* Spawning rocket in tokio task

* Removed outdated comment

* removed the js file

Co-authored-by: Dave <futurechimp@users.noreply.github.com>

* Bugfix/metrics fixes (#434)

* Updated dashboard html file

* Changed explorer to listen on the same port as old dashboard

* Using correct field names in js file

* Sending correct key in metrics

* Added nym prefix to binary names (#436)

* Passing validator base url as an argument (#439)

* Spawning rocket as a blocking task (#440)

* Update main.js (#441)

* Update main.js

* Changed websocket port to 1648

* Changing default validator location to make it clear we're testnet (#437)

* Changing default validator location to make it clear we're on a testnet here.

* Updated validator url

* Updated metrics url

Co-authored-by: jstuczyn <jedrzej.stuczynski@gmail.com>

* Adding keybase to allowed.list.sample (#442)

* Updated nym-run gateway id (#445)

* Adjusted 'fastmode' settings (#444)

* Added validators to dashboard + validator and block count (#443)

* Slightly friendlier upgrade argument description (#446)

* Slightly friendlier upgrade argument description

* Added right format examples

* Explorer public folder being relative to the binary (#447)

* Explorer public folder being relative to the binary

* Qualifying the public mounting path

Co-authored-by: Dave <futurechimp@users.noreply.github.com>

* Extra argument to specify metrics websocket + long attribute (#448)

* Extra argument to specify metrics websocket + long attribute

* Default testnet values

* Fixed the URL of the websocket (#449)

* Removed hardcoded 'good gateways' in favour of pseusorandom choice from the active set (#450)

* Adding graceful de-registration to service

* Removed incentives form url (#451)

* Updated version numbers

* Updated generate changelog script

* Updated changelog

* wasm examples fixes

Co-authored-by: Dave Hrycyszyn <futurechimp@users.noreply.github.com>
Co-authored-by: Ethan Frey <ethanfrey@users.noreply.github.com>
2020-11-13 12:44:58 +00:00

201 lines
6.9 KiB
JavaScript

import React from 'react';
import {
Button,
Card,
CardHeader,
CardBody,
FormGroup,
Form,
Input,
InputGroup,
Row,
Col,
Container,
Table
} from 'reactstrap';
class App extends React.Component {
constructor() {
super();
this.handleChangeReceiver = this.handleChangeReceiver.bind(this);
this.handleChangeMessage = this.handleChangeMessage.bind(this);
this.receivedMessage = this.receivedMessage.bind(this);
this.state = {
nymClient: null,
sender: "",
receiver: "",
message: "Hello mixnet!",
transfers: [],
}
}
componentDidMount() {
this.loadWasm();
}
handleChangeReceiver(e) {
this.setState({ receiver: e.target.value });
}
handleChangeMessage(e) {
this.setState({ message: e.target.value });
}
loadWasm = async () => {
try {
const wasm = await import('@nymproject/nym-client-wasm');
this.setState({ wasm });
// Set up identity and client
let validator = "http://testnet-validator1.nymtech.net:8081";
let _nymClient = new wasm.NymClient(validator);
_nymClient.set_on_message(this.receivedMessage);
// Start the Nym client. Connects to a Nym gateway via websocket.
_nymClient = await _nymClient.initial_setup();
this.setState({ nymClient: _nymClient });
let _sender = _nymClient.self_address();
this.setState({ sender: _sender });
} catch (err) {
console.error(`Unexpected error in loadWasm. [Message: ${err.message}]`);
}
}
async sendmessage(message, receiver) {
let timestamp = new Date().toISOString().substr(11, 12);
this.setState({
nymClient: await this.state.nymClient.send_message(message, receiver),
transfers: this.state.transfers.concat({ time: timestamp, direction: "sent", message: message, replySURB: "N/A" })
})
}
receivedMessage(message) {
let timestamp = new Date().toISOString().substr(11, 12);
this.setState({
transfers: this.state.transfers.concat({ time: timestamp, direction: "received", message: message.message, replySURB: "" + (message.replySURB != null) })
})
}
renderTableData() {
return this.state.transfers.map((transfers, index) => {
const { time, direction, message, replySURB } = transfers //destructuring
return (
<tr key={index} >
{direction === "sent" ?
<>
<td className="text-primary">{time}</td>
<td className="text-primary">{direction}</td>
<td className="text-primary">{message}</td>
<td className="text-primary">{replySURB}</td>
</>
:
<>
<td className="text-success">{time}</td>
<td className="text-success">{direction}</td>
<td className="text-success">{message}</td>
<td className="text-success">{replySURB}</td>
</>
}
</tr>
)
})
}
render() {
return (
<>
<div className="main-content">
<div className="header bg-gradient-info py-7 py-lg-8">
<Container>
<div className="header-body text-center mb-7">
<Row className="justify-content-center">
<Col lg="5" md="6">
<h1 className="text-white">NYM</h1>
<p className="text-lead text-light">
Example react peaps implementation
</p>
</Col>
</Row>
</div>
</Container>
</div>
{/* Page content */}
<Container className="mt--8 pb-5">
<Row className="justify-content-center">
<Col lg="6" md="8">
<Card className="bg-secondary shadow border-0">
<CardHeader className="bg-transparent pb-1">
<div className="text-center mt-2 mb-4">
Test NYM by sending a private message
</div>
</CardHeader>
<CardBody className="px-lg-5 py-lg-5">
<Form role="form">
<FormGroup>
<InputGroup className="input-group-alternative mb-3">
<Input
readOnly
value={this.state.sender}
type="text"
/>
</InputGroup>
</FormGroup>
<FormGroup>
<InputGroup className="input-group-alternative mb-3">
<Input
placeholder="Receiver"
type="text"
onChange={this.handleChangeReceiver}
/>
</InputGroup>
</FormGroup>
<FormGroup>
<InputGroup className="input-group-alternative mb-3">
<Input
placeholder={this.state.message}
type="text"
onChange={this.handleChangeMessage}
/>
</InputGroup>
</FormGroup>
<div className="text-center">
<Button
className="mt-4"
color="primary"
type="button"
onClick={() => this.sendmessage(this.state.message, this.state.receiver)}
>
Send private message
</Button>
</div>
</Form>
</CardBody>
</Card>
</Col>
<Col lg="6" md="8">
<Card className="bg-secondary shadow border-0">
<CardHeader className="bg-transparent pb-1">
<div className="text-center mt-2 mb-4">
Message history
</div>
</CardHeader>
<CardBody className="px-lg-5 py-lg-5">
<Table className="align-items-center" responsive>
<thead className="thead-light">
<tr>
<th scope="col">Time</th>
<th scope="col">In/Out</th>
<th scope="col">Message</th>
<th scope="col">ReplySURB</th>
<th scope="col" />
</tr>
</thead>
<tbody>
{this.renderTableData()}
</tbody>
</Table>
</CardBody>
</Card>
</Col>
</Row>
</Container>
</div>
</>
);
}
}
export default App;