react app testing

stable
Marcus 2021-02-15 09:30:56 -05:00
parent 219ec7f88e
commit c41f8d429c
18 changed files with 10321 additions and 43 deletions

View File

@ -78,6 +78,10 @@ class STPSocket extends EventEmitter {
return this.tcpSocket.readyState === 'open'
}
get secured() {
return this.readyState;
}
constructor(tcpSocket, identity) {
super();
this.tcpSocket = tcpSocket;
@ -112,7 +116,6 @@ class STPSocket extends EventEmitter {
switch(obj.cmd) {
case 'KEY': {
if(this.readyState === 0) {
log.info('registering external key');
this.externalKey = new NodeRSA();
this.externalKey.importKey(obj.data.key, 'pkcs8-public-pem');
this.tcpSocket.write(new AckPacket().toBuffer());
@ -123,7 +126,6 @@ class STPSocket extends EventEmitter {
case 'ACK': {
if(this.readyState === 1) {
this.readyState = 2;
log.success('internal key acknowledged');
this.emit('ready');
}
break;

View File

@ -7,7 +7,7 @@
"ports": {
"relay": 5600,
"http": 5700,
"service": 6000
"service": 5000
},
"addresses": {
"relay": "valnet.xyz"
@ -22,6 +22,7 @@
},
"dependencies": {
"express": "^4.17.1",
"express-ws": "^4.0.0",
"font-ascii": "^1.2.1",
"gradient-string": "^1.2.0",
"human-readable-ids": "^1.0.4",

View File

@ -20,7 +20,7 @@ stp.createServer({
identity: identity,
port: config.ports.relay
}, socket => {
log.debug('loopback ' + socket.loopback)
log.info('secured connection from ' + socket.remoteAddress);
clients.push(socket);
});
@ -33,7 +33,7 @@ function connectNetwork(t = 1000) {
ip: config.addresses.relay
});
client.on('ready', () => {
log.success('connectd!');
log.success('connectd to relay!');
t = 500;
})
client.on('error', e => {
@ -41,7 +41,8 @@ function connectNetwork(t = 1000) {
client.on('close', e => {
t *= 2;
setTimeout(connectNetwork.bind(global, t), t);
log.debug('retrying connection... ' + (t/1000) + 's')
log.warn('disconnected from relay');
log.warn('retrying connection... ' + (t/1000) + 's')
});
}
connectNetwork();
@ -52,29 +53,6 @@ const app = express();
app.get('/', (req, res) => {
res.end(`
<style>
html {
background: black;
color: white;
}
td:not(:last-child), th:not(:last-child) {
border-right: 1px solid white;
}
td, th {
padding-left: 8px;
}
th {
border-bottom: 3px solid white;
}
table {
border-spacing: 0px;
font-family: sans-serif;
font-size: 13px;
}
tr:nth-child(2n) {
background: #111;
}
</style>
<table style="min-width: 300px">
<tr>
<th>Id</th>
@ -92,6 +70,24 @@ app.get('/', (req, res) => {
`);
});
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
next();
})
app.get('/clients', (req, res) => {
res.json({
clients: clients.map((client, index) => {
return {
id: index,
address: client.remoteAddress,
loopback: client.loopback,
identity: client.identity.publicKey,
connected: client.secured
}
})
})
})
// app.post
app.listen(config.ports.http).on('error', e => {

View File

@ -1,4 +1,4 @@
(() => {
(async () => {
const log = require('signale').scope('service');
const { execSync, spawn } = require('child_process');
const branch = execSync('git rev-parse --abbrev-ref HEAD').toString().trim();
@ -72,7 +72,7 @@ setInterval(function update() {
function logp(message, type = 'info') {
log[type](message);
appendLogs('service', message)
appendLogs('service', message + '\n')
}
function appendLogs(source, data, type = 'output') {
@ -86,29 +86,48 @@ function appendLogs(source, data, type = 'output') {
app.get('/', (req, res) => {
logs.find({
timestamp: { $gt: Date.now() - 1000000 }
}, {}, (err, docs) => {
// timestamp: { $gt: Date.now() - 1000000 }
}, {}).sort({
timestamp: 1
}).exec((err, docs) => {
if(err) {
res.end(err.toString());
return;
}
docs.sort(function(a, b) {
return a.timestamp > b.timestamp;
});
// ${new Date(logItem.timestamp).toLocaleString().padStart(40)}:
res.end(`
<table style="width: 100%">
<html>
<head>
<meta charset="UTF-16">
</head>
<body>
<style>
table {
border-spacing: 0px;
font-size: 13px;
}
tr {
vertical-align: top;
}
</style>
<pre>
${docs.map(logItem => logItem.message).join('').replace(/\u001B\[.*?[A-Za-z]/g, '')}
</pre>
<!--
<table>
${docs.map(logItem => `
<tr>
<td><pre>${logItem.timestamp}</pre></td>
<td><pre>${logItem.source}</pre></td>
<td><pre>${logItem.type}</pre></td>
<td><pre>${new Date(logItem.timestamp).toLocaleDateString()}</pre></td>
<td><pre>${new Date(logItem.timestamp).toLocaleTimeString()}</pre></td>
<td><pre>${logItem.message}</pre></td>
</tr>
`).join('')}
</table>
-->
</body>
</html>
`);
})
});
@ -118,5 +137,4 @@ app.listen(config.ports.service);
})();

23
valnet-webapp/.gitignore vendored 100644
View File

@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*

View File

@ -0,0 +1,70 @@
# Getting Started with Create React App
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## Available Scripts
In the project directory, you can run:
### `yarn start`
Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
The page will reload if you make edits.\
You will also see any lint errors in the console.
### `yarn test`
Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
### `yarn build`
Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
### `yarn eject`
**Note: this is a one-way operation. Once you `eject`, you cant go back!**
If you arent satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point youre on your own.
You dont have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldnt feel obligated to use this feature. However we understand that this tool wouldnt be useful if you couldnt customize it when you are ready for it.
## Learn More
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
To learn React, check out the [React documentation](https://reactjs.org/).
### Code Splitting
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
### Analyzing the Bundle Size
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
### Making a Progressive Web App
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
### Advanced Configuration
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
### Deployment
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
### `yarn build` fails to minify
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)

View File

@ -0,0 +1,38 @@
{
"name": "valnet-webapp",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.2",
"web-vitals": "^1.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}

View File

@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Valnet Portal</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>

View File

@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}

View File

@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:

View File

@ -0,0 +1,45 @@
import React from 'react';
import styles from './style.module.css';
import { apiRoot } from '../lib/constants.js';
class ActiveConnections extends React.Component {
state = {
connections: []
}
constructor(props) {
super(props);
this.refreshData();
}
async refreshData() {
const req = await fetch(`${apiRoot}/clients`);
const res = await req.json();
console.log(res);
}
render() {
return (
<div>
<div>active connections!</div>
{this.state.connections.map(connection => {
return (<div>
{connection.toLocaleString()};
</div>)
})}
<br />
<button onClick={() => this.addConnection.bind(this)()}>
Add Connection
</button>
</div>
);
}
addConnection() {
this.state.connections.push(new Date());
this.forceUpdate();
}
}
export default ActiveConnections;

View File

@ -0,0 +1,3 @@
.red {
color: red;
}

View File

@ -0,0 +1,13 @@
import React from 'react';
import ActiveConnections from './ActiveConnections/index';
import './app.css';
function App() {
return (
<>
<ActiveConnections />
</>
);
}
export default App;

View File

@ -0,0 +1,47 @@
@media (prefers-color-scheme: dark) {
html {
--b1: #001;
--b2: #112;
--b3: #223;
--b4: #334;
--t1: #EEF;
--t2: #DDE;
--t3: #CCD;
}
}
@media (prefers-color-scheme: light) {
html {
--b1: #EEF;
--b2: #DDE;
--b3: #CCD;
--b4: #BBC;
--t1: #001;
--t2: #112;
--t3: #223;
}
}
html {
background: var(--b1);
color: var(--t1);
}
td:not(:last-child), th:not(:last-child) {
border-right: 1px solid var(--t3);
}
td, th {
padding-left: 8px;
}
th {
border-bottom: 3px solid var(--t3);
}
table {
border-spacing: 0px;
font-family: sans-serif;
font-size: 13px;
}
tr:nth-child(2n) {
background: #111;
}

View File

@ -0,0 +1,11 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);

View File

@ -0,0 +1 @@
export const apiRoot = '//127.0.0.1:5700';

File diff suppressed because it is too large Load Diff

View File

@ -77,6 +77,10 @@ assert-plus@1.0.0, assert-plus@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/assert-plus/-/assert-plus-1.0.0.tgz#f12e0f3c5d77b0b1cdd9146942e4e96c1e4dd525"
async-limiter@~1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/async-limiter/-/async-limiter-1.0.1.tgz#dd379e94f0db8310b08291f9d64c3209766617fd"
async@0.2.10:
version "0.2.10"
resolved "https://registry.yarnpkg.com/async/-/async-0.2.10.tgz#b6bbe0b0674b9d719708ca38de8c237cb526c3d1"
@ -450,6 +454,12 @@ etag@~1.8.1:
version "1.8.1"
resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887"
express-ws@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/express-ws/-/express-ws-4.0.0.tgz#dabd8dc974516418902a41fe6e30ed949b4d36c4"
dependencies:
ws "^5.2.0"
express@^4.17.1:
version "4.17.1"
resolved "https://registry.yarnpkg.com/express/-/express-4.17.1.tgz#4491fc38605cf51f8629d39c2b5d026f98a4c134"
@ -1512,6 +1522,12 @@ wrap-ansi@^7.0.0:
string-width "^4.1.0"
strip-ansi "^6.0.0"
ws@^5.2.0:
version "5.2.2"
resolved "https://registry.yarnpkg.com/ws/-/ws-5.2.2.tgz#dffef14866b8e8dc9133582514d1befaf96e980f"
dependencies:
async-limiter "~1.0.0"
xml2js@~0.1.14:
version "0.1.14"
resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.1.14.tgz#5274e67f5a64c5f92974cd85139e0332adc6b90c"