William Casarin e3c9e2834e cache: refactor cache structure and reduce allocations
This commit reworks the cache data structures and operations to
significantly cut down on unnecessary allocations and improve overall
cache management logic.

Key changes include:

- Replacing event-specific CacheEntry types with a generic CacheEntry<T>
  that stores values and timestamps.

- Removing the old Arc references in HashMap entries, reducing
  reference-counted pointer overhead.

- Providing helper methods (new(), maybe(), empty(), value()) on
  CacheEntry for more ergonomic and explicit value handling.

- Simplifying the retrieval functions (get_mute_list, get_relay_list,
  get_contact_list) by using a shared helper (get_cache_entry) that
  checks for expiration and removes stale entries automatically.

- Streamlining add_event and related cache insertion methods to insert
  the correct CacheEntry variant depending on the event kind.

- Removing unnecessary methods (e.g., references_pubkey) and simplifying
  extensions in nostr_event_extensions.rs.

- Enhancing code clarity by separating expiration logic from retrieval
  and insertion, making the cache easier to maintain, debug, and extend.

These improvements should reduce runtime memory overhead and increase
code clarity, while maintaining the existing external behavior of the
cache. Future changes will be easier to implement, as the new generic
CacheEntry abstraction and simplified code paths provide a more
maintainable foundation.

Signed-off-by: William Casarin <jb55@jb55.com>
2024-12-09 13:49:08 +09:00
2024-07-19 20:52:30 -07:00
2024-07-19 20:52:30 -07:00
2024-12-09 13:49:08 +09:00
2024-12-09 13:49:08 +09:00
2024-08-26 12:02:06 -07:00
2024-07-11 09:53:43 -07:00
2024-08-02 16:48:56 -07:00
2024-08-23 14:31:03 -07:00

Notepush

A high performance Nostr relay for sending out push notifications using the Apple Push Notification Service (APNS).

⚠️🔥WIP! Experimental!⚠️🔥

Installation

  1. Get a build or build it yourself using cargo build --release
  2. On the working directory from which you start this relay, create an .env file with the following contents:
APNS_TOPIC="com.your_org.your_app"        # Your app's bundle ID
APNS_AUTH_PRIVATE_KEY_FILE_PATH=./AuthKey_1234567890.p8	# Path to the private key file used to generate JWT tokens with the Apple APNS server. You can obtain this from https://developer.apple.com/account/resources/authkeys/list
APNS_AUTH_PRIVATE_KEY_ID=1234567890 # The ID of the private key used to generate JWT tokens with the Apple APNS server. You can obtain this from https://developer.apple.com/account/resources/authkeys/list
APNS_ENVIRONMENT="development"    # The environment to use with the APNS server. Can be "development" or "production"
APPLE_TEAM_ID=1248163264        # The ID of the team. Can be found in AppStore Connect.
DB_PATH=./apns_notifications.db         # Path to the SQLite database file that will be used to store data about sent notifications, relative to the working directory
RELAY_URL=wss://relay.damus.io           # URL to the relay server which will be consulted to get information such as mute lists.
HOST="0.0.0.0"                          # The host to bind the server to (Defaults to 0.0.0.0 to bind to all interfaces)
PORT=8000                               # The port to bind the server to. Defaults to 8000
API_BASE_URL=http://localhost:8000      # Base URL from the API is allowed access (used by the server to perform NIP-98 authentication)
  1. Run this relay using the built binary or the cargo run command. If you want to change the log level, you can set the RUST_LOG environment variable to DEBUG or INFO before running the relay.

Example:

$ RUST_LOG=DEBUG cargo run

Contributions

For contribution guidelines, please check this document.

Development setup

  1. Install the Rust toolchain
  2. Clone this repository
  3. Run cargo build to build the project
  4. Run cargo test to run the tests
  5. Run cargo run to run the project

Testing utilities

You can use test/test-inputs with a websockets test tool such as websocat to play around with the relay. If you have Nix installed, you can run:

$ nix-shell
[nix-shell] $ websocat ws://localhost:8000
<ENTER_FULL_JSON_PAYLOAD_HERE_AND_PRESS_ENTER>
Description
No description provided
Readme 282 KiB
Languages
Rust 99.8%
Nix 0.2%