Skip to content

Commit 62bb0ba

Browse files
committed
Add nostr-gossip-memory crate
Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent 5e9fdbd commit 62bb0ba

File tree

13 files changed

+739
-1
lines changed

13 files changed

+739
-1
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
- nostr-http-file-storage
3737
- nostr-database
3838
- nostr-gossip
39+
- nostr-gossip-memory
3940
- nostr-lmdb
4041
- nostr-indexeddb --target wasm32-unknown-unknown
4142
- nostr-ndb

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ members = [
1010

1111
# Gossip
1212
"gossip/nostr-gossip",
13+
"gossip/nostr-gossip-memory",
1314

1415
# Remote File Storage implementations
1516
"rfs/nostr-blossom",
@@ -42,7 +43,8 @@ negentropy = { version = "0.5", default-features = false }
4243
nostr = { version = "0.43", path = "./crates/nostr", default-features = false }
4344
nostr-connect = { version = "0.43", path = "./signer/nostr-connect", default-features = false }
4445
nostr-database = { version = "0.43", path = "./database/nostr-database", default-features = false }
45-
nostr-gossip = { version = "0.43.0", path = "./gossip/nostr-gossip", default-features = false }
46+
nostr-gossip = { version = "0.43", path = "./gossip/nostr-gossip", default-features = false }
47+
nostr-gossip-memory = { version = "0.43", path = "./gossip/nostr-gossip-memory", default-features = false }
4648
nostr-lmdb = { version = "0.43", path = "./database/nostr-lmdb", default-features = false }
4749
nostr-ndb = { version = "0.43", path = "./database/nostr-ndb", default-features = false }
4850
nostr-relay-builder = { version = "0.43", path = "./crates/nostr-relay-builder", default-features = false }

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ The project is split up into several crates:
1414
- [**nostr-ndb**](./database/nostr-ndb): [nostrdb](https://github.com/damus-io/nostrdb) storage backend
1515
- [**nostr-indexeddb**](./database/nostr-indexeddb): IndexedDB storage backend
1616
- [**nostr-gossip**](./gossip/nostr-gossip): Gossip traits
17+
- [**nostr-gossip-memory**](./gossip/nostr-gossip-memory): In-memory gossip database
1718
- Remote File Storage implementations:
1819
- [**nostr-blossom**](./rfs/nostr-blossom): A library for interacting with the Blossom protocol
1920
- [**nostr-http-file-storage**](./rfs/nostr-http-file-storage): HTTP File Storage client (NIP-96)

contrib/scripts/check-crates.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ buildargs=(
3535
"-p nostr-http-file-storage"
3636
"-p nostr-database"
3737
"-p nostr-gossip"
38+
"-p nostr-gossip-memory"
3839
"-p nostr-lmdb"
3940
"-p nostr-indexeddb --target wasm32-unknown-unknown"
4041
"-p nostr-ndb"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Changelog
2+
3+
<!-- All notable changes to this project will be documented in this file. -->
4+
5+
<!-- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), -->
6+
<!-- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -->
7+
8+
<!-- Template
9+
10+
## Unreleased
11+
12+
### Breaking changes
13+
14+
### Changed
15+
16+
### Added
17+
18+
### Fixed
19+
20+
### Removed
21+
22+
### Deprecated
23+
24+
-->
25+
26+
## Unreleased
27+
28+
First release.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[package]
2+
name = "nostr-gossip-memory"
3+
version = "0.43.0"
4+
edition = "2021"
5+
description = "In-memory gossip database"
6+
authors.workspace = true
7+
homepage.workspace = true
8+
repository.workspace = true
9+
license.workspace = true
10+
readme = "README.md"
11+
rust-version.workspace = true
12+
keywords = ["nostr", "gossip", "in-memory"]
13+
14+
[dependencies]
15+
lru.workspace = true
16+
nostr = { workspace = true, features = ["std"] }
17+
nostr-gossip.workspace = true
18+
tokio = { workspace = true, features = ["sync"] }
19+
20+
[dev-dependencies]
21+
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Gossip in-memory storage
2+
3+
## Changelog
4+
5+
All notable changes to this library are documented in the [CHANGELOG.md](CHANGELOG.md).
6+
7+
## State
8+
9+
**This library is in an ALPHA state**, things that are implemented generally work but the API will change in breaking ways.
10+
11+
## Donations
12+
13+
`rust-nostr` is free and open-source. This means we do not earn any revenue by selling it. Instead, we rely on your financial support. If you actively use any of the `rust-nostr` libs/software/services, then please [donate](https://rust-nostr.org/donate).
14+
15+
## License
16+
17+
This project is distributed under the MIT software license - see the [LICENSE](../../LICENSE) file for details
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright (c) 2022-2023 Yuki Kishimoto
2+
// Copyright (c) 2023-2025 Rust Nostr Developers
3+
// Distributed under the MIT software license
4+
5+
use std::time::Duration;
6+
7+
pub(super) const PUBKEY_METADATA_OUTDATED_AFTER: Duration = Duration::from_secs(60 * 60); // 60 min
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#[derive(Clone, Copy, Default)]
2+
pub(crate) struct Flags(u16);
3+
4+
impl Flags {
5+
//pub(crate) const NONE: Self = Self(0); // 0
6+
7+
pub(crate) const READ: Self = Self(1 << 0); // 1
8+
9+
pub(crate) const WRITE: Self = Self(1 << 1); // 2
10+
11+
pub(crate) const PRIVATE_MESSAGE: Self = Self(1 << 2); // 4
12+
13+
pub(crate) const HINT: Self = Self(1 << 3); // 8
14+
15+
pub(crate) const RECEIVED: Self = Self(1 << 4); // 16
16+
17+
// /// New empty flags.
18+
// #[inline]
19+
// pub(crate) const fn new() -> Self {
20+
// Self::NONE
21+
// }
22+
23+
/// Add flag.
24+
#[inline]
25+
pub(crate) const fn add(&mut self, other: Self) {
26+
self.0 |= other.0;
27+
}
28+
29+
/// Remove flag.
30+
#[inline]
31+
pub(crate) const fn remove(&mut self, other: Self) {
32+
self.0 ^= other.0;
33+
}
34+
35+
#[inline]
36+
pub(crate) const fn has(&self, other: Self) -> bool {
37+
self.0 & other.0 != 0
38+
}
39+
40+
// #[inline]
41+
// pub(crate) const fn as_u16(&self) -> u16 {
42+
// self.0
43+
// }
44+
}

0 commit comments

Comments
 (0)