feat(bouncer): Tell upstream relays the client IP address if needed.

Signed-off-by: Yonle <yonle@lecturify.net>
This commit is contained in:
Yonle
2024-02-28 22:43:03 +07:00
parent bbdba8b1c9
commit 67f16ff247
2 changed files with 10 additions and 2 deletions

View File

@@ -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, blocked_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");
let { relays, approved_publishers, blocked_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, forward_ip_address_to_upstream } = 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);
@@ -211,9 +211,14 @@ function bc(msg, ws) {
// WS - Sessions
function newConn(addr, client, reconn_t = 0) {
if (client.readyState !== 1) return;
let additionalReqHeaders = {};
if (forward_ip_address_to_upstream)
additionalReqHeaders["x-forwarded-for"] = client.ip;
const relay = new WebSocket(addr, {
headers: {
"User-Agent": `Bostr ${version}; The nostr relay bouncer; https://github.com/Yonle/bostr`
"User-Agent": `Bostr ${version}; The nostr relay bouncer; https://github.com/Yonle/bostr`,
...additionalReqHeaders
},
noDelay: true,
allowSynchronousEvents: true

View File

@@ -139,6 +139,9 @@ module.exports = {
// Path to favicon file.
favicon: "",
// Forward client IP address to upstream relays with x-forwarded-for
forward_ip_address_to_upstream: true,
// Nostr relays to bounce [Required]
relays: [
"wss://example1.com",