Make all config values configurable

And use a standard scheme for variable/key naming
This commit is contained in:
Râu Cao 2025-06-01 19:57:04 +04:00
parent 8df7c00a14
commit 5f661d7304
Signed by: raucao
GPG Key ID: 37036C356E56CC51
5 changed files with 65 additions and 56 deletions

View File

@ -4,8 +4,16 @@ node.default["strfry"]["download_url"] = nil
node.default["strfry"]["checksum"] = nil
node.default["strfry"]["user"] = "strfry"
node.default["strfry"]["group"] = "strfry"
node.default["strfry"]["db_path"] = "/var/lib/strfry"
node.default["strfry"]["bind_ip"] = "0.0.0.0"
node.default["strfry"]["real_ip_header"] = ""
node.default["strfry"]["info"] = {}
node.default["strfry"]["policy_path"] = ""
node.default["strfry"]["config"] = {
db: "/var/lib/strfry"
# db_params: {},
# events: {},
# relay: {
# info: {},
# writePolicy: {},
# compression: {},
# logging: {},
# num_threads: {},
# negentropy: {}
# }
}

View File

@ -35,3 +35,11 @@ suites:
verifier:
inspec_tests:
- test/integration/default
attributes:
strfry:
config:
relay:
bind: 0.0.0.0
port: 7778
info:
name: "Test relay"

View File

@ -59,7 +59,7 @@ user node["strfry"]["user"] do
shell "/bin/bash"
end
directory node["strfry"]["db_path"] do
directory node["strfry"]["config"]["db"] do
owner node["strfry"]["user"]
group node["strfry"]["group"]
mode "0755"
@ -70,15 +70,7 @@ template "/etc/strfry.conf" do
mode "0644"
owner node["strfry"]["user"]
group node["strfry"]["group"]
variables config: {
db_path: node["strfry"]["db_path"],
bind: node["strfry"]["bind_ip"],
real_ip_header: node["strfry"]["real_ip_header"],
port: node["strfry"]["port"],
nofiles: node["strfry"]["nofiles"],
info: node["strfry"]["info"],
policy_path: node["strfry"]["policy_path"]
}
variables config: node["strfry"]["config"]
notifies :restart, "service[strfry]", :delayed
end

View File

@ -1,138 +1,138 @@
# Directory that contains the strfry LMDB database (restart required)
db = "<%= @config[:db_path] %>/"
db = "<%= @config.dig(:db) || "" %>/"
dbParams {
# Maximum number of threads/processes that can simultaneously have LMDB transactions open (restart required)
maxreaders = 256
maxreaders = <%= @config.dig(:db_params, :maxreaders) || "256" %>
# Size of mmap() to use when loading LMDB (default is 10TB, does *not* correspond to disk-space used) (restart required)
mapsize = 10995116277760
mapsize = <%= @config.dig(:db_params, :mapsize) || "10995116277760" %>
# Disables read-ahead when accessing the LMDB mapping. Reduces IO activity when DB size is larger than RAM. (restart required)
noReadAhead = false
noReadAhead = <%= @config.dig(:db_params, :no_read_ahead) || "false" %>
}
events {
# Maximum size of normalised JSON, in bytes
maxEventSize = 65536
maxEventSize = <%= @config.dig(:events, :max_event_size) || "65536" %>
# Events newer than this will be rejected
rejectEventsNewerThanSeconds = 900
rejectEventsNewerThanSeconds = <%= @config.dig(:events, :reject_events_newer_than_seconds) || "900" %>
# Events older than this will be rejected
rejectEventsOlderThanSeconds = 94608000
rejectEventsOlderThanSeconds = <%= @config.dig(:events, :reject_events_older_than_seconds) || "94608000" %>
# Ephemeral events older than this will be rejected
rejectEphemeralEventsOlderThanSeconds = 60
rejectEphemeralEventsOlderThanSeconds = <%= @config.dig(:events, :reject_ephemeral_events_older_than_seconds) || "60" %>
# Ephemeral events will be deleted from the DB when older than this
ephemeralEventsLifetimeSeconds = 300
ephemeralEventsLifetimeSeconds = <%= @config.dig(:events, :ephemeral_events_lifetime_seconds) || "300" %>
# Maximum number of tags allowed
maxNumTags = 2000
maxNumTags = <%= @config.dig(:events, :max_num_tags) || "2000" %>
# Maximum size for tag values, in bytes
maxTagValSize = 1024
maxTagValSize = <%= @config.dig(:events, :max_tag_val_size) || "1024" %>
}
relay {
# Interface to listen on. Use 0.0.0.0 to listen on all interfaces (restart required)
bind = "<%= @config[:bind] || "127.0.0.1" %>"
bind = "<%= @config.dig(:relay, :bind) || "127.0.0.1" %>"
# Port to open for the nostr websocket protocol (restart required)
port = <%= @config[:port] || "7777" %>
port = <%= @config.dig(:relay, :port) || "7777" %>
# Set OS-limit on maximum number of open files/sockets (if 0, don't attempt to set) (restart required)
nofiles = <%= @config[:nofiles] || "524288" %>
nofiles = <%= @config.dig(:relay, :nofiles) || "524288" %>
# HTTP header that contains the client's real IP, before reverse proxying (ie x-real-ip) (MUST be all lower-case)
realIpHeader = "<%= @config[:real_ip_header] %>"
realIpHeader = "<%= @config.dig(:relay, :real_ip_header) || "" %>"
# NIP-11
info {
# Name of this server. Short/descriptive (< 30 characters)
name = "<%= @config[:info][:name] || "strfry default" %>"
name = "<%= @config.dig(:relay, :info, :name) || "strfry default" %>"
# Detailed information about relay, free-form
description = "<%= @config[:info][:description] || "This is a strfry instance." %>"
description = "<%= @config.dig(:relay, :info, :description) || "This is a strfry instance." %>"
# Administrative nostr pubkey, for contact purposes
pubkey = "<%= @config[:info][:pubkey] || "" %>"
pubkey = "<%= @config.dig(:relay, :info, :pubkey) || "" %>"
# Alternative administrative contact (email, website, etc)
contact = "<%= @config[:info][:contact] || "" %>"
contact = "<%= @config.dig(:relay, :info, :contact) || "" %>"
# URL pointing to an image to be used as an icon for the relay
icon = "<%= @config[:info][:icon] || "" %>"
icon = "<%= @config.dig(:relay, :info, :icon) || "" %>"
}
# Maximum accepted incoming websocket frame size (should be larger than max event) (restart required)
maxWebsocketPayloadSize = 131072
maxWebsocketPayloadSize = <%= @config.dig(:relay, :max_websocket_payload_size) || "131072" %>
# Websocket-level PING message frequency (should be less than any reverse proxy idle timeouts) (restart required)
autoPingSeconds = 55
autoPingSeconds = <%= @config.dig(:relay, :auto_ping_seconds) || "55" %>
# If TCP keep-alive should be enabled (detect dropped connections to upstream reverse proxy)
enableTcpKeepalive = false
enableTcpKeepalive = <%= @config.dig(:relay, :enable_tcp_keepalive) || "false" %>
# How much uninterrupted CPU time a REQ query should get during its DB scan
queryTimesliceBudgetMicroseconds = 10000
queryTimesliceBudgetMicroseconds = <%= @config.dig(:relay, :query_timeslice_budget_microseconds) || "10000" %>
# Maximum records that can be returned per filter
maxFilterLimit = 500
maxFilterLimit = <%= @config.dig(:relay, :max_filter_limit) || "500" %>
# Maximum number of subscriptions (concurrent REQs) a connection can have open at any time
maxSubsPerConnection = 20
maxSubsPerConnection = <%= @config.dig(:relay, :max_subs_per_connection) || "20" %>
writePolicy {
# If non-empty, path to an executable script that implements the writePolicy plugin logic
plugin = "<%= @config[:policy_path] %>"
plugin = "<%= @config.dig(:relay, :write_policy, :plugin) || "" %>"
}
compression {
# Use permessage-deflate compression if supported by client. Reduces bandwidth, but slight increase in CPU (restart required)
enabled = true
enabled = <%= @config.dig(:relay, :compression, :enabled) || "true" %>
# Maintain a sliding window buffer for each connection. Improves compression, but uses more memory (restart required)
slidingWindow = true
slidingWindow = <%= @config.dig(:relay, :compression, :sliding_window) || "true" %>
}
logging {
# Dump all incoming messages
dumpInAll = true
dumpInAll = <%= @config.dig(:relay, :logging, :dump_in_all) || "true" %>
# Dump all incoming EVENT messages
dumpInEvents = false
dumpInEvents = <%= @config.dig(:relay, :logging, :dump_in_events) || "false" %>
# Dump all incoming REQ/CLOSE messages
dumpInReqs = false
dumpInReqs = <%= @config.dig(:relay, :logging, :dump_in_reqs) || "false" %>
# Log performance metrics for initial REQ database scans
dbScanPerf = false
dbScanPerf = <%= @config.dig(:relay, :logging, :db_scan_perf) || "false" %>
# Log reason for invalid event rejection? Can be disabled to silence excessive logging
invalidEvents = true
invalidEvents = <%= @config.dig(:relay, :logging, :invalid_events) || "true" %>
}
numThreads {
# Ingester threads: route incoming requests, validate events/sigs (restart required)
ingester = 3
ingester = <%= @config.dig(:relay, :num_threads, :ingester) || "3" %>
# reqWorker threads: Handle initial DB scan for events (restart required)
reqWorker = 3
reqWorker = <%= @config.dig(:relay, :num_threads, :req_worker) || "3" %>
# reqMonitor threads: Handle filtering of new events (restart required)
reqMonitor = 3
reqMonitor = <%= @config.dig(:relay, :num_threads, :req_monitor) || "3" %>
# negentropy threads: Handle negentropy protocol messages (restart required)
negentropy = 2
negentropy = <%= @config.dig(:relay, :num_threads, :negentropy) || "2" %>
}
negentropy {
# Support negentropy protocol messages
enabled = true
enabled = <%= @config.dig(:relay, :negentropy, :enabled) || "true" %>
# Maximum records that sync will process before returning an error
maxSyncEvents = 1000000
maxSyncEvents = <%= @config.dig(:relay, :negentropy, :max_sync_events) || "1000000" %>
}
}

View File

@ -18,13 +18,14 @@ end
describe file('/etc/strfry.conf') do
it { should exist }
its('content') { should match(/name\s*=\s*"Test relay"/m) }
end
describe file('/var/lib/strfry') do
it { should be_directory }
end
describe port(7777) do
describe port(7778) do
it { should be_listening }
its('addresses') { should include '0.0.0.0' }
end