Skip to content

Commit 4b48184

Browse files
authored
Merge branch 'cameri:main' into main
2 parents 057634f + b172235 commit 4b48184

44 files changed

Lines changed: 5577 additions & 12739 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env.example

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# --- REQUIRED ---
2+
SECRET=change_me_to_something_long_and_random # Generate: openssl rand -hex 128
3+
4+
# --- POSTGRESQL ---
5+
DB_HOST=localhost
6+
DB_PORT=5432
7+
DB_NAME=nostr_ts_relay
8+
DB_USER=nostr_ts_relay
9+
DB_PASSWORD=nostr_ts_relay
10+
# Alternatively, use a URI:
11+
# DB_URI=postgresql://nostr_ts_relay:nostr_ts_relay@localhost:5432/nostr_ts_relay
12+
13+
# --- DB POOL TUNING (Optional) ---
14+
# DB_MIN_POOL_SIZE=0
15+
# DB_MAX_POOL_SIZE=3
16+
# DB_ACQUIRE_CONNECTION_TIMEOUT=60000
17+
18+
# --- REDIS (Required for Rate Limiting) ---
19+
REDIS_HOST=localhost
20+
REDIS_PORT=6379
21+
# REDIS_USER=default
22+
# REDIS_PASSWORD=
23+
# Alternatively, use a URI:
24+
# REDIS_URI=redis://localhost:6379
25+
26+
# --- SERVER CONFIG ---
27+
RELAY_PORT=8008
28+
WORKER_COUNT=2 # Defaults to CPU count. Use 1 or 2 for local testing.
29+
# NOSTR_CONFIG_DIR=.nostr # Where settings.yaml lives
30+
31+
# --- DEBUGGING ---
32+
# Useful namespaces: maintenance-worker, database-client:*, cache-client, etc.
33+
# DEBUG=maintenance-worker
34+
35+
# --- RELAY PRIVATE KEY (Optional) ---
36+
# RELAY_PRIVATE_KEY=your_hex_private_key
37+
38+
# --- PAYMENTS (Only if enabled in settings.yaml) ---
39+
# ZEBEDEE_API_KEY=
40+
# NODELESS_API_KEY=
41+
# NODELESS_WEBHOOK_SECRET=
42+
# OPENNODE_API_KEY=
43+
# LNBITS_API_KEY=
44+
45+
# --- READ REPLICAS (Optional) ---
46+
# READ_REPLICA_ENABLED=false
47+
# READ_REPLICAS=2
48+
# RR0_DB_HOST=localhost
49+
# RR0_DB_PORT=5432
50+
# RR0_DB_NAME=nostr_ts_relay
51+
# RR0_DB_USER=your_psql_username
52+
# RR0_DB_PASSWORD=your_psql_password
53+
# RR0_DB_MIN_POOL_SIZE=0
54+
# RR0_DB_MAX_POOL_SIZE=3
55+
# RR0_DB_ACQUIRE_CONNECTION_TIMEOUT=60000
56+
# RR1_DB_HOST=localhost
57+
# RR1_DB_PORT=5432
58+
# RR1_DB_NAME=nostr_ts_relay
59+
# RR1_DB_USER=your_psql_username
60+
# RR1_DB_PASSWORD=your_psql_password
61+
# RR1_DB_MIN_POOL_SIZE=0
62+
# RR1_DB_MAX_POOL_SIZE=3
63+
# RR1_DB_ACQUIRE_CONNECTION_TIMEOUT=60000
64+
65+
# --- TOR (Optional) ---
66+
# TOR_HOST=localhost
67+
# TOR_CONTROL_PORT=9051
68+
# TOR_PASSWORD=
69+
# HIDDEN_SERVICE_PORT=80

.github/workflows/checks.yml

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,12 @@ jobs:
7777
- name: Run coverage for unit tests
7878
run: npm run cover:unit
7979
if: ${{ always() }}
80-
- uses: actions/upload-artifact@v3
80+
- uses: actions/upload-artifact@v4
8181
name: Upload coverage report for unit tests
8282
if: ${{ always() }}
8383
with:
84-
path: .coverage/*/lcov.info
84+
name: unit-coverage-lcov
85+
path: .coverage/unit/lcov.info
8586
- name: Coveralls
8687
uses: coverallsapp/github-action@master
8788
if: ${{ always() }}
@@ -122,29 +123,12 @@ jobs:
122123
flag-name: Integration
123124
parallel: true
124125
github-token: ${{ secrets.GITHUB_TOKEN }}
125-
- uses: actions/upload-artifact@v3
126+
- uses: actions/upload-artifact@v4
126127
name: Upload coverage report for integration tests
127128
if: ${{ always() }}
128129
with:
129-
path: .coverage/*/lcov.info
130-
sonarcloud:
131-
name: Sonarcloud
132-
needs: [test-units-and-cover, test-integrations-and-cover]
133-
runs-on: ubuntu-latest
134-
steps:
135-
- name: Checkout
136-
uses: actions/checkout@v3
137-
with:
138-
fetch-depth: 0
139-
- uses: actions/download-artifact@v3
140-
name: Download unit & integration coverage reports
141-
with:
142-
path: .coverage
143-
- name: SonarCloud Scan
144-
uses: sonarsource/sonarcloud-github-action@master
145-
env:
146-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
147-
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
130+
name: integration-coverage-lcov
131+
path: .coverage/integration/lcov.info
148132
post-tests:
149133
name: Post Tests
150134
needs: [test-units-and-cover, test-integrations-and-cover]

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ node_modules/
2525
.dccache
2626
.DS_Store
2727

28+
# Local Setup
29+
redis.conf
30+
users.acl
31+
postgresql.local.conf
32+
2833
# generate output
2934
dist
3035

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v18.8.0
1+
v24.14.1

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:18-alpine3.16 AS build
1+
FROM node:24-alpine AS build
22

33
WORKDIR /build
44

@@ -10,7 +10,7 @@ COPY . .
1010

1111
RUN npm run build
1212

13-
FROM node:18-alpine3.16
13+
FROM node:24-alpine
1414

1515
LABEL org.opencontainers.image.title="Nostream"
1616
LABEL org.opencontainers.image.source=https://github.com/cameri/nostream

Dockerfile.railwayapp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## Author Saransh Sharma @cynsar foundation
2-
FROM node:18-alpine3.16 as build
2+
FROM node:24-alpine as build
33

44
ARG PORT
55
ARG PGHOST
@@ -29,7 +29,7 @@ COPY . .
2929

3030
RUN npm run build
3131

32-
FROM node:18-alpine3.16
32+
FROM node:24-alpine
3333

3434
ARG PORT
3535
ARG PGHOST

Dockerfile.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:18-alpine3.16
1+
FROM node:24-alpine
22

33
WORKDIR /code
44

README.md

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ NIPs with a relay-specific implementation are listed here.
6767
### Standalone setup
6868
- PostgreSQL 14.0
6969
- Redis
70-
- Node v18
70+
- Node v24
7171
- Typescript
7272

7373
### Docker setups
@@ -210,6 +210,16 @@ Start:
210210
./scripts/start_with_tor
211211
```
212212
213+
**Windows / WSL2 users:** Docker bind-mounts can cause PostgreSQL permission errors on Windows. Use the dedicated override file instead:
214+
```
215+
docker compose -f docker-compose.yml -f docker-compose.windows.yml up --build
216+
```
217+
Or add this to your `.env` file so you don't have to type it every time:
218+
```
219+
COMPOSE_FILE=docker-compose.yml:docker-compose.windows.yml
220+
```
221+
> **Note:** If you previously ran Nostream on Linux/Mac and are switching to Windows, your existing data lives at `.nostr/data/` on the host. You'll need to copy it into the Docker named volume manually or it won't be visible to the new setup.
222+
213223
Stop the server with:
214224
```
215225
./scripts/stop
@@ -220,6 +230,29 @@ Print the Tor hostname:
220230
./scripts/print_tor_hostname
221231
```
222232
233+
### Importing events from JSON Lines
234+
235+
You can import NIP-01 events from a `.jsonl` file directly into the relay database.
236+
237+
Basic import:
238+
```
239+
npm run import -- ./events.jsonl
240+
```
241+
242+
Set a custom batch size (default: `1000`):
243+
```
244+
npm run import -- ./events.jsonl --batch-size 500
245+
```
246+
247+
The importer:
248+
249+
- Processes the file line-by-line to keep memory usage bounded.
250+
- Validates NIP-01 schema, event id hash, and Schnorr signature before insertion.
251+
- Inserts in database transactions per batch.
252+
- Skips duplicates without failing the whole import.
253+
- Prints progress in the format:
254+
`[Processed: 50,000 | Inserted: 45,000 | Skipped: 5,000 | Errors: 0]`
255+
223256
### Running as a Service
224257
225258
By default this server will run continuously until you stop it with Ctrl+C or until the system restarts.
@@ -263,6 +296,60 @@ The logs can be viewed with:
263296
journalctl -u nostream
264297
```
265298
299+
## Troubleshooting
300+
301+
### Linux: Docker DNS resolution failures (`EAI_AGAIN`)
302+
303+
On some Linux environments (especially rolling-release distros or setups using
304+
`systemd-resolved`), `docker compose` builds can fail with DNS errors such as:
305+
306+
- `getaddrinfo EAI_AGAIN registry.npmjs.org`
307+
- `Temporary failure in name resolution`
308+
309+
To fix this, configure Docker daemon DNS in `/etc/docker/daemon.json`.
310+
311+
1. Create or update `/etc/docker/daemon.json`:
312+
313+
```
314+
sudo mkdir -p /etc/docker
315+
sudo nano /etc/docker/daemon.json
316+
```
317+
318+
Add or update the file with:
319+
320+
```
321+
{
322+
"dns": ["1.1.1.1", "8.8.8.8"]
323+
}
324+
```
325+
326+
If this file already exists, merge the `dns` key into the existing JSON
327+
instead of replacing the entire file.
328+
329+
If your environment does not allow public resolvers, replace `1.1.1.1` and
330+
`8.8.8.8` with DNS servers approved by your network.
331+
332+
2. Restart Docker:
333+
334+
```
335+
sudo systemctl restart docker
336+
```
337+
338+
3. Verify DNS works inside containers:
339+
340+
```
341+
docker run --rm busybox nslookup registry.npmjs.org
342+
```
343+
344+
4. Retry starting nostream:
345+
346+
```
347+
./scripts/start
348+
```
349+
350+
Note: avoid `127.0.0.53` in Docker DNS settings because it points to the host's
351+
local resolver stub and is often unreachable from containers.
352+
266353
## Quick Start (Standalone)
267354
268355
Set the following environment variables:
@@ -372,7 +459,7 @@ Clone repository and enter directory:
372459
373460
Start:
374461
```
375-
./scripts/start_local
462+
./scripts/start
376463
```
377464
378465
This will run in the foreground of the terminal until you stop it with Ctrl+C.

docker-compose.windows.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# docker-compose.windows.yml
2+
#
3+
# Windows / WSL2 override for Nostream.
4+
#
5+
# On Windows (including WSL2), Docker bind-mounts to host paths can cause
6+
# PostgreSQL permission errors. This override replaces the bind-mount for
7+
# PostgreSQL data with a named Docker volume, which is managed entirely
8+
# by the Docker engine and avoids those issues.
9+
#
10+
# Usage:
11+
# docker compose -f docker-compose.yml -f docker-compose.windows.yml up --build
12+
#
13+
# Or set COMPOSE_FILE in your .env:
14+
# COMPOSE_FILE=docker-compose.yml:docker-compose.windows.yml
15+
#
16+
# WARNING: If you previously ran Nostream with the default docker-compose.yml
17+
# your data is in .nostr/data/ on the host. Before switching to this file,
18+
# migrate your data or it will not be accessible from the named volume.
19+
20+
services:
21+
nostream-db:
22+
volumes:
23+
- nostream-db-data:/var/lib/postgresql/data
24+
- ${PWD}/.nostr/db-logs:/var/log/postgresql
25+
- ${PWD}/postgresql.conf:/postgresql.conf
26+
27+
volumes:
28+
nostream-db-data:

0 commit comments

Comments
 (0)