Commit f9c10ece authored by Éloïs's avatar Éloïs
Browse files

[feat] create duniter launcher

parent 50df4023
[alias]
xtask = "run --package xtask --"
......@@ -46,14 +46,16 @@ app/**/*.d.ts
neon/lib/*.d.ts
test/**/*.d.ts
# files generated by neon tests
test2.bin.gz
# files generated by neon
neon/native/artifacts.json
# rust binaries
bin/duniter
neon/native/index.node
target
# files generated by rust tests
neon/native/tests/*.txt
neon/native/tests/wotb-*
test2.bin.gz
**/*.wot
......@@ -11,7 +11,7 @@ workflow:
- changes:
- .gitlab/**/*
- app/**/*
- bin/duniter
- bin/duniter_js
- neon/**/*
- releases/**/*
- rust-libs/**/*
......@@ -27,11 +27,13 @@ workflow:
tags:
- redshift
before_script:
- curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
- export PATH="$HOME/.cargo/bin:$PATH"
- export RUSTFLAGS="-D warnings"
- export NVM_DIR="$HOME/.nvm"
- . "$NVM_DIR/nvm.sh"
- nvm install 10
- nvm use 10
- export RUSTFLAGS="-D warnings"
.cached_nvm: &cached_nvm
......
......@@ -18,7 +18,7 @@ checksum_test() {
local correct_hash=$2
local db=$3
echo "Checking $table's checksum..."
bin/duniter --mdb ${db} dump table "$table" > "$DUMP_DIR/$table"
bin/duniter_js --mdb ${db} dump table "$table" > "$DUMP_DIR/$table"
result_hash=`sha1sum "$DUMP_DIR/$table" | grep -Po ".* " | grep -Po "[a-f0-9]+"`
# rm -f "$DUMP_DIR/$table"
if [ "$result_hash" == "$correct_hash" ]; then
......@@ -33,8 +33,8 @@ sync_data() {
local db=$1
local target=$2
local target_block=$3
local reset_data="bin/duniter --mdb ${db} reset all"
local sync="bin/duniter --mdb ${db} sync ${target} --nointeractive ${target_block}"
local reset_data="bin/duniter_js --mdb ${db} reset all"
local sync="bin/duniter_js --mdb ${db} sync ${target} --nointeractive ${target_block}"
echo "$reset_data"
${reset_data}
echo "$sync"
......
......@@ -33,6 +33,24 @@ dependencies = [
"winapi",
]
[[package]]
name = "anyhow"
version = "1.0.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b602bfe940d21c130f3895acd65221e8a61270debe89d628b9cb4e3ccb8569b"
[[package]]
name = "arrayref"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544"
[[package]]
name = "arrayvec"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8"
[[package]]
name = "atty"
version = "0.2.14"
......@@ -70,6 +88,12 @@ version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7"
[[package]]
name = "base64"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff"
[[package]]
name = "beef"
version = "0.4.4"
......@@ -92,6 +116,17 @@ version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]]
name = "blake2b_simd"
version = "0.5.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8fb2d74254a3a0b5cac33ac9f8ed0e44aa50378d9dbb2e5d83bd21ed1dc2c8a"
dependencies = [
"arrayref",
"arrayvec",
"constant_time_eq",
]
[[package]]
name = "block-buffer"
version = "0.7.3"
......@@ -173,6 +208,12 @@ dependencies = [
"vec_map",
]
[[package]]
name = "constant_time_eq"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc"
[[package]]
name = "crc32fast"
version = "1.2.0"
......@@ -241,6 +282,16 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "697c714f50560202b1f4e2e09cd50a421881c83e9025db75d15f276616f04f40"
[[package]]
name = "ctrlc"
version = "3.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0b676fa23f995faf587496dcd1c80fead847ed58d2da52ac1caca9a72790dd2"
dependencies = [
"nix",
"winapi",
]
[[package]]
name = "daemonize-me"
version = "0.3.1"
......@@ -261,6 +312,26 @@ dependencies = [
"generic-array",
]
[[package]]
name = "dirs"
version = "3.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "142995ed02755914747cc6ca76fc7e4583cd18578746716d0508ea6ed558b9ff"
dependencies = [
"dirs-sys",
]
[[package]]
name = "dirs-sys"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e93d7f5705de3e49895a2b5e0b8855a1c27f080192ae9c32a6432d50741a57a"
dependencies = [
"libc",
"redox_users",
"winapi",
]
[[package]]
name = "doc-comment"
version = "0.3.3"
......@@ -344,9 +415,15 @@ dependencies = [
[[package]]
name = "duniter-launcher"
version = "0.1.0"
version = "1.9.0-alpha1"
dependencies = [
"anyhow",
"ctrlc",
"daemonize-me",
"dirs",
"log",
"logwatcher",
"nix",
"rusty-hook",
"structopt",
]
......@@ -375,7 +452,7 @@ version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7315898eda74bf7c9e825f9afae1c9f16debb401fdb7d658fb851fb00a6260c"
dependencies = [
"base64",
"base64 0.11.0",
"bs58",
"byteorder",
"ring",
......@@ -391,7 +468,7 @@ version = "0.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "287b23c4281016278b47b80baf67186ce756dde738070cc7a41297da5e81dec1"
dependencies = [
"base64",
"base64 0.11.0",
"bs58",
"byteorder",
"cryptoxide",
......@@ -563,13 +640,19 @@ checksum = "99e85c08494b21a9054e7fe1374a732aeadaff3980b6990b94bfd3a70f690005"
[[package]]
name = "log"
version = "0.4.8"
version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7"
checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b"
dependencies = [
"cfg-if",
]
[[package]]
name = "logwatcher"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d0925aed5b12ed59857f438d25a910cf051dbcd4107907be1e7abf6c44ec903"
[[package]]
name = "maplit"
version = "1.0.2"
......@@ -881,6 +964,23 @@ dependencies = [
"num_cpus",
]
[[package]]
name = "redox_syscall"
version = "0.1.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce"
[[package]]
name = "redox_users"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d"
dependencies = [
"getrandom",
"redox_syscall",
"rust-argon2",
]
[[package]]
name = "regex"
version = "1.3.7"
......@@ -914,6 +1014,18 @@ dependencies = [
"winapi",
]
[[package]]
name = "rust-argon2"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9dab61250775933275e84053ac235621dfb739556d5c54a2f2e9313b7cf43a19"
dependencies = [
"base64 0.12.3",
"blake2b_simd",
"constant_time_eq",
"crossbeam-utils",
]
[[package]]
name = "rustc-demangle"
version = "0.1.16"
......
[package]
authors = ["elois <elois@duniter.org>"]
description = "Duniter launcher."
edition = "2018"
keywords = ["duniter", "launcher"]
license = "AGPL-3.0"
name = "duniter-launcher"
repository = "https://git.duniter.org/nodes/typescript/duniter"
version = "1.9.0-alpha1"
[[bin]]
bench = false
path = "rust-bins/duniter-launcher/src/main.rs"
name = "duniter"
[dependencies]
anyhow = "1.0.32"
ctrlc = "3.1.6"
daemonize-me = "0.3.1"
dirs = "3.0.1"
log = "0.4.11"
logwatcher = "0.1.1"
nix = "0.17.0"
structopt = "0.3.18"
[dev-dependencies]
rusty-hook = "0.11.2"
[workspace]
members = [
"neon/native",
"rust-bins/xtask",
"rust-libs/dubp-wot"
]
......
......@@ -13,12 +13,8 @@
import { ConfDTO } from "../lib/dto/ConfDTO";
import { Server } from "../../server";
import { Directory, RealFS } from "../lib/system/directory";
import { ExitCodes } from "../lib/common-libs/exit-codes";
const constants = require("../lib/constants");
const Tail = require("tail").Tail;
module.exports = {
duniter: {
cliOptions: [
......@@ -48,51 +44,6 @@ module.exports = {
},
cli: [
{
name: "start",
desc: "Starts Duniter as a daemon (background task).",
logs: false,
onConfiguredExecute: async (
server: Server,
conf: ConfDTO,
program: any,
params: any
) => {
await server.checkConfig();
const daemon = server.getDaemon("direct_start", "start");
await startDaemon(daemon);
},
},
{
name: "stop",
desc: "Stops Duniter daemon if it is running.",
logs: false,
onConfiguredExecute: async (
server: Server,
conf: ConfDTO,
program: any,
params: any
) => {
const daemon = server.getDaemon();
await stopDaemon(daemon);
},
},
{
name: "restart",
desc: "Stops Duniter daemon and restart it.",
logs: false,
onConfiguredExecute: async (
server: Server,
conf: ConfDTO,
program: any,
params: any
) => {
await server.checkConfig();
const daemon = server.getDaemon("direct_start", "restart");
await stopDaemon(daemon);
await startDaemon(daemon);
},
},
{
name: "status",
desc: "Get Duniter daemon status.",
......@@ -114,24 +65,6 @@ module.exports = {
}
},
},
{
name: "logs",
desc: "Follow duniter logs.",
logs: false,
onConfiguredExecute: async (
server: Server,
conf: ConfDTO,
program: any,
params: any
) => {
printTailAndWatchFile(
Directory.INSTANCE_HOMELOG_FILE,
constants.NB_INITIAL_LINES_TO_SHOW
);
// Never ending command
return new Promise((res) => null);
},
},
{
name: "direct_start",
desc: "Start Duniter node with direct output, non-daemonized.",
......@@ -142,6 +75,7 @@ module.exports = {
params: any,
startServices: any
) => {
process.title = program.mdb || "duniter_default";
const logger = server.logger;
logger.info(">> Server starting...");
......@@ -171,55 +105,3 @@ function ServerService(server: Server) {
server.stopService = () => Promise.resolve();
return server;
}
function startDaemon(daemon: any) {
return new Promise((resolve, reject) =>
daemon.start((err: any) => {
if (err) return reject(err);
resolve();
})
);
}
function stopDaemon(daemon: any) {
return new Promise((resolve, reject) =>
daemon.stop((err: any) => {
err && console.error(err);
if (err) return reject(err);
resolve();
})
);
}
async function printTailAndWatchFile(file: any, tailSize: number) {
const fs = RealFS();
if (await fs.fsExists(file)) {
const content = await fs.fsReadFile(file);
const lines = content.split("\n");
const from = Math.max(0, lines.length - tailSize);
const lastLines = lines.slice(from).join("\n");
console.log(lastLines);
}
watchFile(file);
}
function watchFile(file: any) {
const tail = new Tail(file);
// Specific errors handling
process.on("uncaughtException", (err: any) => {
if (err.code === "ENOENT") {
console.error("EXCEPTION: ", err.message);
setTimeout(() => watchFile(file), 1000); // Wait a second
}
});
// On new line
tail.on("line", function (data: any) {
console.log(data);
});
tail.on("error", function (error: any) {
console.error("ERROR: ", error);
});
}
......@@ -64,8 +64,8 @@ export const WS2PDependency = {
},
{ value: "--ws2p-prefered-rm <pubkey>", desc: "Remove prefered node." },
{
value: "--ws2p-prefered-only <pubkey>",
desc: "Only connect to prefered node.",
value: "--ws2p-prefered-only",
desc: "Only connect to prefered nodes.",
},
{
value: "--ws2p-privileged-add <pubkey>",
......@@ -73,7 +73,7 @@ export const WS2PDependency = {
},
{ value: "--ws2p-privileged-rm <pubkey>", desc: "Remove a privileged." },
{
value: "--ws2p-privileged-only <pubkey>",
value: "--ws2p-privileged-only",
desc: "Accept only connections from a privileged node.",
},
],
......
......@@ -10,14 +10,12 @@ Authors: elois
## In a post-it
```bash
nvm use 10
git clone git@git.duniter.org:nodes/typescript/duniter.git
cd duniter
npm install
bin/duniter start
cargo xtask build
./target/release/duniter start
```
## Step by step
### Prerequisites
......@@ -26,31 +24,35 @@ To develop on Duniter, there is currently the following requirement:
- A computer with GNU/Linux or Mac as operating system
- Build essential tools
- curl
- wget
- git (apt-get install git)
- Nvm
- Rust
And preferably an IDE that supports [Typescript] and [Rust] well.
#### Install Prerequisites
Nvm:
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
##### Rust
### Build the project
```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
```
#### Clone de repository
Them add `~/.cargo/bin` on your PATH.
git clone https://git.duniter.org/nodes/typescript/duniter
If you use `bash`:
#### Install and use the correct version of nodejs
```bash
echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> .bashrc
```
Check the required node version in the `package.json` file on line 5.
### Build the project
If, for example, version 10 is expected, install and select it with the following command:
#### Clone the repository
nvm install 10 && nvm use 10
```bash
git clone https://git.duniter.org/nodes/typescript/duniter
```
#### Build the project and play automated tests
......@@ -58,22 +60,27 @@ If, for example, version 10 is expected, install and select it with the followin
Command to compile :
npm install
```bash
cargo xtask build
```
The binary to run duniter-server is then found here: `target/release/duniter`
**WARNING**: playing automated tests takes a lot of resources on your machine and those for several minutes, don't do anything else at the same time!
Command to play automated tests:
npm test
```bash
cargo xtask test
```
If all the tests are successful, the command ends like this:
```bash
777 passing (40s)
19 pending
Done in 43.80s.
```
```bash
777 passing (40s)
19 pending
Done in 43.80s.
```
### Configure your IDE
......@@ -88,14 +95,16 @@ For the Rust part, I strongly recommend the following plugins:
- CodeLLDB (identifier: `vadimcn.vscode-lldb`)
- rust-analyzer (identifier: `matklad.rust-analyzer`)
The recommended ide configuration can be found in `doc/dev/vscode/settings.json`.
The recommended IDE configuration can be found in `doc/dev/vscode/settings.json`.
##### Debugger configuration
The recommended debugger configuration can be found in `doc/dev/.vscode/launch.json`.
For import it:
cp doc/dev/vscode/launch.json .vscode/launch.json
```bash
cp doc/dev/vscode/launch.json .vscode/launch.json
```
You can then adapt it according to your preferences for use :)
......
......@@ -15,7 +15,7 @@ To compile Duniter manually, there is currently the following requirement:
- Build essential tools
- curl
- tar or unzip or git (to download and extract source code)
- Nvm
- Rust
### Get source code
......@@ -60,44 +60,25 @@ Depend on your distribution:
TODO: If you know how to install build essential tools for other gnu/linux distributions or for mac, you can complete this documentation and submit a merge request.
#### Nvm
#### Rust
Nvm:
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
## Build the project
Go to the root of the folder where you extracted the source code (or possibly cloned from git).
### Install and use the correct version of nodejs
Check the required node version in the `package.json` file on line 5.
If, for example, version 10 is expected, install and select it with the following command:
nvm install 10 && nvm use 10
### Optionally add GUI
The graphical user interface (GUI) is optional because it is possible to do everything from the command line.
If you wish to have the GUI, you must add it (before compiling) with the following command:
npm add duniter-ui