Skip to content

Commit d3f3291

Browse files
authored
Merge pull request #17 from KoalaSat/use-nostr-as-cache-system
Use nostr as cache system
2 parents 5239425 + c1edaba commit d3f3291

File tree

13 files changed

+258
-1
lines changed

13 files changed

+258
-1
lines changed

compose/docker-compose.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,16 @@ services:
143143
- redis
144144
network_mode: service:tor
145145

146+
strfry:
147+
build: ./strfry
148+
container_name: strfry${SUFFIX}
149+
restart: always
150+
volumes:
151+
- ${STRFRY_URLS}:/app/onion_urls.txt:ro
152+
- ${STRFRY_CONF}:/etc/strfry.conf:ro
153+
- ${STRFRY_DATA}/db:/app/strfry-db:rw
154+
network_mode: service:tor
155+
146156
# Example simple backup service (copy/paste to attached storage locations)
147157
# backup:
148158
# build: ./backup

compose/env-sample/clntn/robosats.env

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,7 @@ MINIMUM_TARGET_CONF = 24
174174
SLASHED_BOND_REWARD_SPLIT = 0.5
175175

176176
# Username for HTLCs escrows
177-
ESCROW_USERNAME = 'admin'
177+
ESCROW_USERNAME = 'admin'
178+
179+
#Social
180+
NOSTR_NSEC = 'nsec1vxhs2zc4kqe0dhz4z2gfrdyjsrwf8pg3neeqx6w4nl8djfzdp0dqwd6rxh'

compose/env-sample/lndtn/compose.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ POSTGRES_PASSWORD='example'
2828
NGINX_CONFD='./nginx/tn.conf.d'
2929
WELLKNOWN='./nginx/tn.well-known'
3030

31+
STRFRY_CONF='./env-sample/lndtn/strfry.conf'
32+
STRFRY_URLS='./strfry/tn.onion_urls.txt'
33+
STRFRY_DATA='/custom_path/testnet/strfry'
34+
3135
# Port and number of HTTP server workers for the robosats backend
3236
WEB_LOCAL_PORT=8001
3337
GUNICORN_WORKERS=2

compose/env-sample/lndtn/robosats.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,6 @@ SLASHED_BOND_REWARD_SPLIT = 0.5
178178

179179
# Username for HTLCs escrows
180180
ESCROW_USERNAME = 'admin'
181+
182+
#Social
183+
NOSTR_NSEC = 'nsec1vxhs2zc4kqe0dhz4z2gfrdyjsrwf8pg3neeqx6w4nl8djfzdp0dqwd6rxh'
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
##
2+
## Default strfry config
3+
##
4+
5+
# Directory that contains the strfry LMDB database (restart required)
6+
db = "/app/strfry-db/"
7+
8+
dbParams {
9+
# Maximum number of threads/processes that can simultaneously have LMDB transactions open (restart required)
10+
maxreaders = 256
11+
12+
# Size of mmap() to use when loading LMDB (default is 10TB, does *not* correspond to disk-space used) (restart required)
13+
mapsize = 10995116277760
14+
15+
# Disables read-ahead when accessing the LMDB mapping. Reduces IO activity when DB size is larger than RAM. (restart required)
16+
noReadAhead = false
17+
}
18+
19+
events {
20+
# Maximum size of normalised JSON, in bytes
21+
maxEventSize = 65536
22+
23+
# Events newer than this will be rejected
24+
rejectEventsNewerThanSeconds = 900
25+
26+
# Events older than this will be rejected
27+
rejectEventsOlderThanSeconds = 94608000
28+
29+
# Ephemeral events older than this will be rejected
30+
rejectEphemeralEventsOlderThanSeconds = 60
31+
32+
# Ephemeral events will be deleted from the DB when older than this
33+
ephemeralEventsLifetimeSeconds = 300
34+
35+
# Maximum number of tags allowed
36+
maxNumTags = 2000
37+
38+
# Maximum size for tag values, in bytes
39+
maxTagValSize = 1024
40+
}
41+
42+
relay {
43+
# Interface to listen on. Use 0.0.0.0 to listen on all interfaces (restart required)
44+
bind = "0.0.0.0"
45+
46+
# Port to open for the nostr websocket protocol (restart required)
47+
port = 7777
48+
49+
# Set OS-limit on maximum number of open files/sockets (if 0, don't attempt to set) (restart required)
50+
nofiles = 524288
51+
52+
# HTTP header that contains the client's real IP, before reverse proxying (ie x-real-ip) (MUST be all lower-case)
53+
realIpHeader = ""
54+
55+
info {
56+
# NIP-11: Name of this server. Short/descriptive (< 30 characters)
57+
name = "Robosats"
58+
59+
# NIP-11: Detailed information about relay, free-form
60+
description = "Federation cache system."
61+
62+
# NIP-11: Administrative nostr pubkey, for contact purposes
63+
pubkey = ""
64+
65+
# NIP-11: Alternative administrative contact (email, website, etc)
66+
contact = ""
67+
}
68+
69+
# Maximum accepted incoming websocket frame size (should be larger than max event) (restart required)
70+
maxWebsocketPayloadSize = 131072
71+
72+
# Websocket-level PING message frequency (should be less than any reverse proxy idle timeouts) (restart required)
73+
autoPingSeconds = 55
74+
75+
# If TCP keep-alive should be enabled (detect dropped connections to upstream reverse proxy)
76+
enableTcpKeepalive = false
77+
78+
# How much uninterrupted CPU time a REQ query should get during its DB scan
79+
queryTimesliceBudgetMicroseconds = 10000
80+
81+
# Maximum records that can be returned per filter
82+
maxFilterLimit = 500
83+
84+
# Maximum number of subscriptions (concurrent REQs) a connection can have open at any time
85+
maxSubsPerConnection = 3
86+
87+
writePolicy {
88+
# If non-empty, path to an executable script that implements the writePolicy plugin logic
89+
plugin = ""
90+
}
91+
92+
compression {
93+
# Use permessage-deflate compression if supported by client. Reduces bandwidth, but slight increase in CPU (restart required)
94+
enabled = true
95+
96+
# Maintain a sliding window buffer for each connection. Improves compression, but uses more memory (restart required)
97+
slidingWindow = false
98+
}
99+
100+
logging {
101+
# Dump all incoming messages
102+
dumpInAll = false
103+
104+
# Dump all incoming EVENT messages
105+
dumpInEvents = false
106+
107+
# Dump all incoming REQ/CLOSE messages
108+
dumpInReqs = false
109+
110+
# Log performance metrics for initial REQ database scans
111+
dbScanPerf = false
112+
113+
# Log reason for invalid event rejection? Can be disabled to silence excessive logging
114+
invalidEvents = true
115+
}
116+
117+
numThreads {
118+
# Ingester threads: route incoming requests, validate events/sigs (restart required)
119+
ingester = 3
120+
121+
# reqWorker threads: Handle initial DB scan for events (restart required)
122+
reqWorker = 3
123+
124+
# reqMonitor threads: Handle filtering of new events (restart required)
125+
reqMonitor = 3
126+
127+
# negentropy threads: Handle negentropy protocol messages (restart required)
128+
negentropy = 2
129+
}
130+
131+
negentropy {
132+
# Support negentropy protocol messages
133+
enabled = true
134+
135+
# Maximum records that sync will process before returning an error
136+
maxSyncEvents = 1000000
137+
}
138+
}

compose/nginx/mn.conf.d/local.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ server {
6666
limit_req zone=tenpersec burst=10;
6767
}
6868

69+
location /nostr {
70+
proxy_pass http://127.0.0.1:7777;
71+
proxy_http_version 1.1;
72+
proxy_set_header Upgrade $http_upgrade;
73+
proxy_set_header Connection "Upgrade";
74+
proxy_set_header Host $host;
75+
}
76+
6977
location = /favicon.ico { access_log off; log_not_found off; }
7078

7179
}

compose/nginx/tn.conf.d/local.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ server {
6464
proxy_set_header Host $host;
6565
}
6666

67+
location /nostr {
68+
proxy_pass http://127.0.0.1:7777;
69+
proxy_http_version 1.1;
70+
proxy_set_header Upgrade $http_upgrade;
71+
proxy_set_header Connection "Upgrade";
72+
proxy_set_header Host $host;
73+
}
74+
6775
location = /favicon.ico { access_log off; log_not_found off; }
6876

6977
}

compose/strfry/Dockerfile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
FROM ubuntu:jammy
2+
ENV TZ=Europe/London
3+
4+
RUN apt update && apt install -y --no-install-recommends \
5+
git g++ make pkg-config libtool ca-certificates \
6+
libssl-dev zlib1g-dev liblmdb-dev libflatbuffers-dev \
7+
libsecp256k1-dev libzstd-dev
8+
9+
# setup app
10+
RUN git clone https://github.com/KoalaSat/strfry /app
11+
12+
WORKDIR /app
13+
14+
RUN git submodule update --init
15+
RUN make setup-golpe
16+
RUN make clean
17+
RUN make -j4
18+
19+
RUN apt update && apt install -y --no-install-recommends \
20+
liblmdb0 libflatbuffers1 libsecp256k1-0 libb2-1 libzstd1 torsocks cron\
21+
&& rm -rf /var/lib/apt/lists/*
22+
23+
RUN echo "TorAddress 127.0.0.1" >> /etc/tor/torsocks.conf
24+
RUN echo "TorPort 9050" >> /etc/tor/torsocks.conf
25+
26+
# Setting up crontab
27+
COPY crontab /etc/cron.d/crontab
28+
RUN chmod 0644 /etc/cron.d/crontab
29+
RUN crontab /etc/cron.d/crontab
30+
31+
# Setting up entrypoints
32+
COPY sync.sh /etc/strfry/sync.sh
33+
COPY entrypoint.sh /etc/strfry/entrypoint.sh
34+
35+
RUN chmod +x /etc/strfry/entrypoint.sh
36+
RUN chmod +x /etc/strfry/sync.sh
37+
38+
#Setting up logs
39+
RUN touch /var/log/cron.log && chmod 0644 /var/log/cron.log
40+
41+
ENTRYPOINT ["/etc/strfry/entrypoint.sh"]

compose/strfry/crontab

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Edit this file to introduce tasks to be run by cron.
2+
#
3+
# Each task to run has to be defined through a single line
4+
# indicating with different fields when the task will be run
5+
# and what command to run for the task
6+
#
7+
# To define the time you can provide concrete values for
8+
# minute (m), hour (h), day of month (dom), month (mon),
9+
# and day of week (dow) or use '*' in these fields (for 'any').
10+
#
11+
# Notice that tasks will be started based on the cron's system
12+
# daemon's notion of time and timezones.
13+
#
14+
# Output of the crontab jobs (including errors) is sent through
15+
# email to the user the crontab file belongs to (unless redirected).
16+
#
17+
# For example, you can run a backup of all your user accounts
18+
# at 5 a.m every week with:
19+
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
20+
#
21+
# For more information see the manual pages of crontab(5) and cron(8)
22+
#
23+
# m h dom mon dow command
24+
*/1 * * * * torsocks /etc/strfry/sync.sh >> /var/log/cron.log 2>&1

compose/strfry/entrypoint.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
cron -f -l 8 & tail -f /var/log/cron.log & /app/strfry relay

0 commit comments

Comments
 (0)