2021-10-02 02:02:49 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
import net from 'net';
|
|
|
|
|
|
|
|
import l from 'log';
|
|
|
|
|
|
|
|
import settings from '../../settings.mjs';
|
|
|
|
import sleep from '../../lib/async/sleep.mjs';
|
2021-10-02 23:34:55 +00:00
|
|
|
import Connection from '../../lib/transport/Connection.mjs';
|
2021-10-02 02:02:49 +00:00
|
|
|
import { encrypt, decrypt } from '../../lib/crypto/secretbox.mjs';
|
|
|
|
|
|
|
|
export default async function() {
|
|
|
|
const test_key = "H7xKSxvJFoZoNjCKAfxn4E3qUzY3Y/4bjY+qIzxg+78=";
|
|
|
|
|
|
|
|
const test_data = "hello, world";
|
|
|
|
l.notice(`TEST_DATA`, test_data);
|
|
|
|
const encrypted = encrypt(test_key, test_data);
|
|
|
|
l.notice(`ENCRYPTED`, encrypted);
|
|
|
|
const decrypted = decrypt(test_key, encrypted);
|
|
|
|
l.notice(`DECRYPTED`, decrypted);
|
|
|
|
|
2021-10-02 23:34:55 +00:00
|
|
|
const socket = await Connection.Create(test_key, "::1", settings.cli.port);
|
2021-10-02 02:02:49 +00:00
|
|
|
|
2021-10-02 23:34:55 +00:00
|
|
|
socket.on("message", (event, msg) => {
|
|
|
|
l.notice(`<<< ${event}: ${JSON.stringify(msg)}`);
|
2021-10-02 02:02:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
for(let i = 0; i < 100; i++) {
|
|
|
|
await sleep(1000);
|
|
|
|
l.notice(`>>> hello world ${i}`);
|
2021-10-02 23:34:55 +00:00
|
|
|
socket.send(`test-client`, `hello world ${i}\n`);
|
2021-10-02 02:02:49 +00:00
|
|
|
}
|
|
|
|
}
|