mirror of
https://github.com/Yonle/bostr.git
synced 2025-07-28 12:43:35 +02:00
32
README.md
32
README.md
@@ -16,18 +16,44 @@ This project solve the problem by **reducing** the number of connected relays, a
|
||||
|
||||
## Installation
|
||||
- [NodeJS](https://nodejs.org) (v16 or up)
|
||||
- libsqlite installed in your system
|
||||
- A fast internet connection
|
||||
|
||||
#### Bostr CLI
|
||||
Install bostr via `npm`:
|
||||
```
|
||||
npm install -g bostr
|
||||
```
|
||||
|
||||
or via git:
|
||||
|
||||
```
|
||||
npm install -g https://github.com/Yonle/bostr.git
|
||||
```
|
||||
|
||||
You will then need to make config with the following command:
|
||||
```
|
||||
bostr makeconf bostr_config.js
|
||||
```
|
||||
|
||||
Edit `bostr_config.js` (Could be modified) with your file editor and fill some required fields accordingly to your needs. You could run it for everyone or only for yourself.
|
||||
|
||||
### Running
|
||||
After you finished editing the config file, You could start bostr with the following command:
|
||||
```
|
||||
bostr start bostr_config.js
|
||||
```
|
||||
|
||||
#### Source code
|
||||
|
||||
```
|
||||
git clone -b stable https://github.com/Yonle/bostr
|
||||
cd bostr
|
||||
npm i
|
||||
```
|
||||
|
||||
Rename `config.js.example` as `config.js`, Start editing the file and fill some required fields accordingly to your needs. You could either run it for everyone or only for yourself.
|
||||
Rename `config.js.example` as `config.js`, Start editing the file and fill some required fields accordingly to your needs. You could run it for everyone or only for yourself.
|
||||
|
||||
## Running
|
||||
### Running
|
||||
```
|
||||
node index.js
|
||||
```
|
||||
|
80
bostr_cli.js
Executable file
80
bostr_cli.js
Executable file
@@ -0,0 +1,80 @@
|
||||
#!/usr/bin/env node
|
||||
const { version } = require("./package.json");
|
||||
const fs = require("fs");
|
||||
const cluster = require("cluster");
|
||||
const argv = process.argv.slice(2);
|
||||
|
||||
if (cluster.isPrimary) console.log(`Bostr ${version}\n`);
|
||||
|
||||
function showHelp() {
|
||||
console.log(
|
||||
"Usage: bostr [command] (argv)\n" +
|
||||
"Available command:\n" +
|
||||
" makeconf [conffile] - Make config file\n" +
|
||||
" start [conffile] - Run bostr with specified config\n" +
|
||||
" check [conffile] - Check config file\n" +
|
||||
" help - Show this help text\n\n" +
|
||||
"Software is licensed under BSD-3-Clause\n" +
|
||||
"https://github.com/Yonle/bostr"
|
||||
);
|
||||
}
|
||||
|
||||
function readPath(p) {
|
||||
return p.startsWith("/") ? p : process.cwd() + "/" + p;
|
||||
}
|
||||
|
||||
switch (argv[0]) {
|
||||
case "makeconf":
|
||||
if (!argv[1]) return console.log("Usage: bostr makeconf [conffile]");
|
||||
if (fs.existsSync(argv[1])) {
|
||||
console.error("The specified config already exists.");
|
||||
return process.exit(8);
|
||||
}
|
||||
|
||||
fs.copyFileSync(__dirname + "/config.js.example", argv[1]);
|
||||
console.log(`Succesfully copied example config file into ${argv[1]}`);
|
||||
console.log(`Edit ${argv[1]} with your editor and start with the following command:`);
|
||||
console.log(` $ bostr start ${argv[1]}\n`);
|
||||
break;
|
||||
case "check": {
|
||||
if (!argv[1]) return console.log("Usage: bostr check [conffile]");
|
||||
if (!fs.existsSync(argv[1])) {
|
||||
console.error("Config not exists.");
|
||||
return process.exit(254);
|
||||
}
|
||||
|
||||
const masterConf = Object.keys(require("./config.js.example"));
|
||||
const currentConf = Object.keys(require(readPath(argv[1])));
|
||||
const unknown = currentConf.filter(i => !masterConf.includes(i))
|
||||
const missing = masterConf.filter(i => !currentConf.includes(i))
|
||||
|
||||
if (unknown.length) console.log("Unknown Field:\n- ", unknown.join("\n- "));
|
||||
if (missing.length) {
|
||||
console.log("Missing Field:\n- ", missing.join("\n- "));
|
||||
console.log("\nPlease check your config and recheck again.");
|
||||
return process.exit(1);
|
||||
} else {
|
||||
console.log("\nNo config changes needed.");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "start":
|
||||
if (!argv[1]) return console.log("Usage: bostr start [conffile]");
|
||||
if (!fs.existsSync(argv[1])) {
|
||||
console.error("Config not exists.");
|
||||
return process.exit(254);
|
||||
}
|
||||
|
||||
process.env.BOSTR_CONFIG_PATH = readPath(argv[1]);
|
||||
require("./index.js");
|
||||
break;
|
||||
default:
|
||||
if (argv[0] && (argv[0] !== "help")) {
|
||||
console.error("Unrecognized command:", argv[0]);
|
||||
return process.exit(100)
|
||||
}
|
||||
|
||||
showHelp();
|
||||
process.exit(1);
|
||||
break;
|
||||
}
|
@@ -6,7 +6,7 @@ const { validateEvent, nip19, matchFilters, mergeFilters, getFilterLimit } = req
|
||||
const auth = require("./auth.js");
|
||||
const nip42 = require("./nip42.js");
|
||||
|
||||
let { relays, approved_publishers, log_about_relays, authorized_keys, private_keys, reconnect_time, wait_eose, pause_on_limit, max_eose_score, broadcast_ratelimit, upstream_ratelimit_expiration, max_client_subs } = require("./config");
|
||||
let { relays, approved_publishers, log_about_relays, authorized_keys, private_keys, reconnect_time, wait_eose, pause_on_limit, max_eose_score, broadcast_ratelimit, upstream_ratelimit_expiration, max_client_subs } = require(process.env.BOSTR_CONFIG_PATH || "./config");
|
||||
|
||||
log_about_relays = process.env.LOG_ABOUT_RELAYS || log_about_relays;
|
||||
authorized_keys = authorized_keys?.map(i => i.startsWith("npub") ? nip19.decode(i).data : i);
|
||||
|
@@ -126,7 +126,7 @@ module.exports = {
|
||||
// Some nostr client may read the following for compatibility check.
|
||||
// You may change the supported_nips to match with what your relays supported.
|
||||
"supported_nips": [1,2,9,11,12,15,16,20,22,33,40,42,50],
|
||||
"version": require("./package.json").version
|
||||
// "icon_url": ""
|
||||
},
|
||||
|
||||
// Path to favicon file.
|
||||
|
4
http.js
4
http.js
@@ -1,7 +1,6 @@
|
||||
"use strict";
|
||||
const { version } = require("./package.json");
|
||||
const WebSocket = require("ws");
|
||||
const config = require("./config");
|
||||
const http = require("http");
|
||||
const http2 = require("http2");
|
||||
const fs = require("fs");
|
||||
@@ -13,6 +12,9 @@ const log = _ => console.log(process.pid, curD(), "-", _);
|
||||
|
||||
// Server
|
||||
let server = null;
|
||||
let config = require(process.env.BOSTR_CONFIG_PATH || "./config");
|
||||
|
||||
config.server_meta.version = version;
|
||||
|
||||
if (
|
||||
fs.existsSync(config.https?.privKey) &&
|
||||
|
7
index.js
7
index.js
@@ -1,13 +1,9 @@
|
||||
const config = require("./config");
|
||||
const config = require(process.env.BOSTR_CONFIG_PATH || "./config");
|
||||
const cluster = require("cluster");
|
||||
const fs = require("fs");
|
||||
const os = require("os");
|
||||
|
||||
if (!process.env.NO_CLUSTERS && cluster.isPrimary) {
|
||||
try {
|
||||
fs.rmSync(".temporary.db");
|
||||
} catch {}
|
||||
|
||||
const numClusters = process.env.CLUSTERS || config.clusters || (os.availableParallelism ? os.availableParallelism() : (os.cpus().length || 2))
|
||||
|
||||
console.log(`Primary ${process.pid} is running. Will fork ${numClusters} clusters.`);
|
||||
@@ -25,5 +21,4 @@ if (!process.env.NO_CLUSTERS && cluster.isPrimary) {
|
||||
return true;
|
||||
}
|
||||
|
||||
console.log(process.pid, "Worker spawned");
|
||||
require("./http.js");
|
||||
|
@@ -7,6 +7,9 @@
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "node index.js"
|
||||
},
|
||||
"bin": {
|
||||
"bostr": "bostr_cli.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@github.com/Yonle/bostr.git"
|
||||
|
Reference in New Issue
Block a user