From bfa086c6cf322055f0f662ef6ab8ee8d567750b1 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 9 Oct 2024 14:10:43 +0200 Subject: [PATCH] provide basic local relay function --- develoment-utils/local-relay/.gitignore | 1 + develoment-utils/local-relay/config.toml | 217 ++++++++++++++++++ develoment-utils/local-relay/deno.jsonc | 14 ++ .../local-relay/seed-data/seed-data.ts | 40 ++++ .../local-relay/seed-data/seed-db/nostr.db | Bin 0 -> 118784 bytes .../seed-data/send-seed-data-to-relay.ts | 11 + 6 files changed, 283 insertions(+) create mode 100644 develoment-utils/local-relay/.gitignore create mode 100644 develoment-utils/local-relay/config.toml create mode 100644 develoment-utils/local-relay/deno.jsonc create mode 100644 develoment-utils/local-relay/seed-data/seed-data.ts create mode 100644 develoment-utils/local-relay/seed-data/seed-db/nostr.db create mode 100644 develoment-utils/local-relay/seed-data/send-seed-data-to-relay.ts diff --git a/develoment-utils/local-relay/.gitignore b/develoment-utils/local-relay/.gitignore new file mode 100644 index 0000000..9f4c740 --- /dev/null +++ b/develoment-utils/local-relay/.gitignore @@ -0,0 +1 @@ +db/ \ No newline at end of file diff --git a/develoment-utils/local-relay/config.toml b/develoment-utils/local-relay/config.toml new file mode 100644 index 0000000..2b17415 --- /dev/null +++ b/develoment-utils/local-relay/config.toml @@ -0,0 +1,217 @@ +# Nostr-rs-relay configuration + +[info] +# The advertised URL for the Nostr websocket. +relay_url = "wss://nostr.example.com/" + +# Relay information for clients. Put your unique server name here. +name = "nostr-rs-relay" + +# Description +description = "A newly created nostr-rs-relay.\n\nCustomize this with your own info." + +# Administrative contact pubkey +#pubkey = "0c2d168a4ae8ca58c9f1ab237b5df682599c6c7ab74307ea8b05684b60405d41" + +# Administrative contact URI +#contact = "mailto:contact@example.com" + +# Favicon location. Relative to the current directory. Assumes an +# ICO format. +#favicon = "favicon.ico" + +[diagnostics] +# Enable tokio tracing (for use with tokio-console) +#tracing = false + +[database] +# Database engine (sqlite/postgres). Defaults to sqlite. +# Support for postgres is currently experimental. +#engine = "sqlite" + +# Directory for SQLite files. Defaults to the current directory. Can +# also be specified (and overriden) with the "--db dirname" command +# line option. +#data_directory = "." + +# Use an in-memory database instead of 'nostr.db'. +# Requires sqlite engine. +# Caution; this will not survive a process restart! +#in_memory = false + +# Database connection pool settings for subscribers: + +# Minimum number of SQLite reader connections +#min_conn = 4 + +# Maximum number of SQLite reader connections. Recommend setting this +# to approx the number of cores. +#max_conn = 8 + +# Database connection string. Required for postgres; not used for +# sqlite. +#connection = "postgresql://postgres:nostr@localhost:7500/nostr" + + +[grpc] +# gRPC interfaces for externalized decisions and other extensions to +# functionality. +# +# Events can be authorized through an external service, by providing +# the URL below. In the event the server is not accessible, events +# will be permitted. The protobuf3 schema used is available in +# `proto/nauthz.proto`. +# event_admission_server = "http://[::1]:50051" + +[network] +# Bind to this network address +address = "0.0.0.0" + +# Listen on this port +port = 8080 + +# If present, read this HTTP header for logging client IP addresses. +# Examples for common proxies, cloudflare: +#remote_ip_header = "x-forwarded-for" +#remote_ip_header = "cf-connecting-ip" + +# Websocket ping interval in seconds, defaults to 5 minutes +#ping_interval = 300 + +[options] +# Reject events that have timestamps greater than this many seconds in +# the future. Recommended to reject anything greater than 30 minutes +# from the current time, but the default is to allow any date. +reject_future_seconds = 1800 + +[limits] +# Limit events created per second, averaged over one minute. Must be +# an integer. If not set (or set to 0), there is no limit. Note: +# this is for the server as a whole, not per-connection. +# +# Limiting event creation is highly recommended if your relay is +# public! +# +#messages_per_sec = 5 + +# Limit client subscriptions created, averaged over one minute. Must +# be an integer. If not set (or set to 0), defaults to unlimited. +# Strongly recommended to set this to a low value such as 10 to ensure +# fair service. +#subscriptions_per_min = 0 + +# UNIMPLEMENTED... +# Limit how many concurrent database connections a client can have. +# This prevents a single client from starting too many expensive +# database queries. Must be an integer. If not set (or set to 0), +# defaults to unlimited (subject to subscription limits). +#db_conns_per_client = 0 + +# Limit blocking threads used for database connections. Defaults to 16. +#max_blocking_threads = 16 + +# Limit the maximum size of an EVENT message. Defaults to 128 KB. +# Set to 0 for unlimited. +#max_event_bytes = 131072 + +# Maximum WebSocket message in bytes. Defaults to 128 KB. +#max_ws_message_bytes = 131072 + +# Maximum WebSocket frame size in bytes. Defaults to 128 KB. +#max_ws_frame_bytes = 131072 + +# Broadcast buffer size, in number of events. This prevents slow +# readers from consuming memory. +#broadcast_buffer = 16384 + +# Event persistence buffer size, in number of events. This provides +# backpressure to senders if writes are slow. +#event_persist_buffer = 4096 + +# Event kind blacklist. Events with these kinds will be discarded. +#event_kind_blacklist = [ +# 70202, +#] + +# Event kind allowlist. Events other than these kinds will be discarded. +#event_kind_allowlist = [ +# 0, 1, 2, 3, 7, 40, 41, 42, 43, 44, 30023, +#] + +[authorization] +# Pubkey addresses in this array are whitelisted for event publishing. +# Only valid events by these authors will be accepted, if the variable +# is set. +#pubkey_whitelist = [ +# "35d26e4690cbe1a898af61cc3515661eb5fa763b57bd0b42e45099c8b32fd50f", +# "887645fef0ce0c3c1218d2f5d8e6132a19304cdc57cd20281d082f38cfea0072", +#] +# Enable NIP-42 authentication +#nip42_auth = false +# Send DMs events (kind 4) only to their authenticated recipients +#nip42_dms = false + +[verified_users] +# NIP-05 verification of users. Can be "enabled" to require NIP-05 +# metadata for event authors, "passive" to perform validation but +# never block publishing, or "disabled" to do nothing. +#mode = "disabled" + +# Domain names that will be prevented from publishing events. +#domain_blacklist = ["wellorder.net"] + +# Domain names that are allowed to publish events. If defined, only +# events NIP-05 verified authors at these domains are persisted. +#domain_whitelist = ["example.com"] + +# Consider an pubkey "verified" if we have a successful validation +# from the NIP-05 domain within this amount of time. Note, if the +# domain provides a successful response that omits the account, +# verification is immediately revoked. +#verify_expiration = "1 week" + +# How long to wait between verification attempts for a specific author. +#verify_update_frequency = "24 hours" + +# How many consecutive failed checks before we give up on verifying +# this author. +#max_consecutive_failures = 20 + +[pay_to_relay] +# Enable pay to relay +#enabled = false + +# The cost to be admitted to relay +#admission_cost = 4200 + +# The cost in sats per post +#cost_per_event = 0 + +# Url of lnbits api +#node_url = "" + +# LNBits api secret +#api_secret = "" + +# Terms of service +#terms_message = """ +#This service (and supporting services) are provided "as is", without warranty of any kind, express or implied. +# +#By using this service, you agree: +#* Not to engage in spam or abuse the relay service +#* Not to disseminate illegal content +#* That requests to delete content cannot be guaranteed +#* To use the service in compliance with all applicable laws +#* To grant necessary rights to your content for unlimited time +#* To be of legal age and have capacity to use this service +#* That the service may be terminated at any time without notice +#* That the content you publish may be removed at any time without notice +#* To have your IP address collected to detect abuse or misuse +#* To cooperate with the relay to combat abuse or misuse +#* You may be exposed to content that you might find triggering or distasteful +#* The relay operator is not liable for content produced by users of the relay +#""" + +# Whether or not new sign ups should be allowed +#sign_ups = false +#secret_key = "" \ No newline at end of file diff --git a/develoment-utils/local-relay/deno.jsonc b/develoment-utils/local-relay/deno.jsonc new file mode 100644 index 0000000..166e6ff --- /dev/null +++ b/develoment-utils/local-relay/deno.jsonc @@ -0,0 +1,14 @@ +{ + "tasks": { + "pull": "docker pull scsibug/nostr-rs-relay:latest", + + // run the server without any content on port 7000 + "run": "deno task pull; docker run -it -p 7000:8080 --name my-relay scsibug/nostr-rs-relay:latest", + + // run the server with seed data on port 7000 + "run-with-seed": "deno task pull; cp -r ./seed-data/seed-db ./seed-data/db; docker run -it -p 7000:8080 --mount src=$(pwd)/config.toml,target=/usr/src/app/config.toml,type=bind --mount src=$(pwd)/seed-data/db,target=/usr/src/app/db,type=bind --name my-relay scsibug/nostr-rs-relay:latest", + + // generates a new seed db from the events writte in seed-data.ts. + "build-seed-from-event-list": "deno task run; deno run --allow-net send-seed-data-to-relay.ts; sleep 3; docker cp my-relay:/usr/src/app/db/nostr.db $(pwd)/seed-data/seed-db/nostr.db" + } +} diff --git a/develoment-utils/local-relay/seed-data/seed-data.ts b/develoment-utils/local-relay/seed-data/seed-data.ts new file mode 100644 index 0000000..9701ff6 --- /dev/null +++ b/develoment-utils/local-relay/seed-data/seed-data.ts @@ -0,0 +1,40 @@ +export const events = [ + { + content: "Small community, happy to host folks, contact us on trustroots.", + created_at: 1723391984, + id: "da0de42156741aa176dfd4b42d34b26cf5442fbbe88ade2acbcf8b98d86485d3", + kind: 30398, + pubkey: "f5bc71692fc08ea52c0d1c8bcfb87579584106b5feb4ea542b1b8a95612f257b", + sig: "37a6c57a37961059d322cf3fb4e0e6efd9b3512a7d48e807ecb55ed0787b8c509c2cb4a6b23dabbf2088ae83e6495931370432d449f2d81451a1d9e15de98d1d", + tags: [ + ["e", "ef07341941193dd05324dc7d420d8dad8f755150a2df9cf449d405e59fb3ca69"], + ["p", "915843820a0744224b1cc80907db3e39989577d76a4561de76d4d24c3fe60f86"], + [ + "d", + "915843820a0744224b1cc80907db3e39989577d76a4561de76d4d24c3fe60f86:ef07341941193dd05324dc7d420d8dad8f755150a2df9cf449d405e59fb3ca69", + ], + ["original_created_at", "1723314980"], + ["L", "open-location-code"], + ["l", "9F4J4CCH+65", "open-location-code"], + ], + }, + { + content: "Beautiful community garden", + created_at: 1723314772, + id: "9254eb6b245b9e0bb10d6eb87696156568457d354784f59242be9e01a30632e2", + kind: 30398, + pubkey: "f5bc71692fc08ea52c0d1c8bcfb87579584106b5feb4ea542b1b8a95612f257b", + sig: "cf48f480045c66cd27445bc12f86c033ba9c080e7bd559d03d1f3f9c53f60db1d2363d34ef1158364263cfca8fc45adcb6acb48a61a6a77e8f26bdd038ac4ba4", + tags: [ + ["e", "3bb9aeadfca045149ec05ad0ef2956c5df49cae253e97e79f33e7710b65a3e95"], + ["p", "c5f7ec409bd40fbb63934306ccf3d56d319a559f2c193d8f5368ff2bca252804"], + [ + "d", + "c5f7ec409bd40fbb63934306ccf3d56d319a559f2c193d8f5368ff2bca252804:3bb9aeadfca045149ec05ad0ef2956c5df49cae253e97e79f33e7710b65a3e95", + ], + ["original_created_at", "1723285703"], + ["L", "open-location-code"], + ["l", "9F4MFCF8+RP", "open-location-code"], + ], + }, +]; diff --git a/develoment-utils/local-relay/seed-data/seed-db/nostr.db b/develoment-utils/local-relay/seed-data/seed-db/nostr.db new file mode 100644 index 0000000000000000000000000000000000000000..12aa56341c93d57a8c59e139a3cc680afdc7f66d GIT binary patch literal 118784 zcmeI5eQX@Zb-?d~x+7OQo^4t_+f14@WkWoR6!-IXR{>g6kQeOKypLl=@iOV$(5CY{7gLKv`vPAs~H1g7sw z0A+P*?$RJs-(g$Van}SFePfbvn9Mf|IGcjrE@bg@#m9b*az$#C>ZN=g@I~tiXa;D zKA-5n^3E`J-C|0fo|ao{Ozz0ZVjMU^%9A711xP|Y8f!a?hEsIYNRVa*n))Whx|4%cdpnNZz1(v&N;W=n1` z4?Lv2DR;CSmV6SFFQ<*PWkVN}2}DMv-jc&+^5hyb3<>JEeB_531Jx*RO9xE;vm*$G6Lc)^)&2tY~ zJvq-)#@y_wx!L(5FPSec7NZg=U%54%Q^(?42ZXb>$QiJaBdDGUT@*@g>vPIM5v~?W zC;8Y-JqdcI#PCdc4MxKFo@$35%|Cui*j=*Qop5Ou&~A6P4s_Qq($`%_aoAGof{jAKX*VxD8PfiqwUsVLWY9N#9ha;4FIQ_Vd5xWi803Ljf|v5q z#S=#_Asv84V57_ApxR=MdV}$M3Pd82%e8Z?;gKfe>f~mNJK|v}@}!+F_}m(+iaaB@ z$ULaSC}&jS4!LuyP?*>E#a4%Heiu=7YF{chor|9pZW1bF=j%a3WI6FZ)8{MOMYy|& zvPsd5!QHZze`GJr5_0i%p)|a{61P6|KOw%aPwRk8q&BP)(V7pWbnflB_*SM@afG}_ z{ob9_ZnbO9-wz6#09=TvY@m^nrl7El5J(HOA8OLcBazd2t|^S z-l!)3%%ONXm&?VUH$}=8HR4;Mtujp8qUef=oA)IWWdBUbn07Z|)yQilKWH>tr6z;K zwtccKvg!^gPc)H5lS!VCLn@5klb0u9K2fXErrZqp)LeBeCBLhz8l|OFs} znf_30^py0^@B_b)01`j~NB{{Sfj5}IvrEZ+vBjaG*kUX({Nja|R(|y4y^noz?-w)G zuWWp5KU*taFpod;`b$SIelq@C?JrcF#ugtHjX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