Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

map: make the struct public #133

Merged
merged 2 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions gossip_map/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
[package]
name = "clightningrpc_gossip_map"
version = "0.1.0"
version = "0.0.1-beta.2"
edition = "2021"
description = "Crate that provides a plugin API to give the possibility to implement a plugin in Rust"
license = "CC0-1.0"
homepage = "https://github.com/laanwj/rust-clightning-rpc"
repository = "https://github.com/laanwj/rust-clightning-rpc.git"
keywords = [ "plugin", "cln", "rpc", "lightning", "bitcoin" ]
readme = "README.md"

[dependencies]
anyhow = "1"
log = "0.4.21"
byteorder = "1.4.3"
hex = "0.4.3"
bitcoin = { version = "0.30.0" }
fundamentals = { git = "https://github.com/lnspec-tools/ln-fundamentals.git", branch = "macros/fix_fixed_read" }
fundamentals-derive = { git = "https://github.com/lnspec-tools/ln-fundamentals.git", branch = "macros/fix_fixed_read" }
fundamentals = { version = "0.0.1-alpha.4" }
fundamentals-derive = { version = "0.0.1-alpha.2"}

[dev-dependencies]
anyhow = "1.0.70"
Expand Down
16 changes: 16 additions & 0 deletions gossip_map/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# gossip map

Core Lightning Gossip Map parser to access the gossip map with rust.

## Example

``` rust
fn main() {
let path = concat!(env!("CARGO_MANIFEST_DIR"), "/../contrib/gossip_store");
let pubkey = "03e2408a49f07d2f4083a47344138ef89e7617e63919202c92aa8d49b574a560ae";
let map = GossipMap::from_file(path);
assert!(map.is_ok(), "{:?}", map);
let map = map.unwrap();
assert!(map.get_node(pubkey).is_some(), "node with id `{pubkey}` not found!");
}
```
23 changes: 15 additions & 8 deletions gossip_map/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@
/// Gossip map implementation, that allow you to manage the gossip_store
/// written by core lightning.
#[derive(Debug)]
struct GossipMap {
// FIXME: make this optional
path: String,
pub struct GossipMap {
path: Option<String>,
version: u8,
stream: Option<BufReader<File>>,

Check warning on line 32 in gossip_map/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (stable)

field `stream` is never read

Check warning on line 32 in gossip_map/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (stable)

field `stream` is never read

Check warning on line 32 in gossip_map/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (beta)

field `stream` is never read

Check warning on line 32 in gossip_map/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (beta)

field `stream` is never read

Check warning on line 32 in gossip_map/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (nightly)

field `stream` is never read

Check warning on line 32 in gossip_map/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (nightly)

field `stream` is never read
nodes: HashMap<GossipNodeId, GossipNode>,
channels: HashMap<ShortChannelId, GossipChannel>,
orphan_channel_updates: HashMap<ShortChannelId, ChannelUpdate>,
Expand All @@ -41,7 +40,7 @@
pub fn new(version: u8) -> Self {
log::debug!("gossip map version `{version}`");
GossipMap {
path: "".to_owned(),
path: None,
version,
stream: None,
nodes: HashMap::new(),
Expand All @@ -55,7 +54,7 @@
let gossip_store = File::open(file_name)?;
let stream = BufReader::new(gossip_store);
let mut gossip_map = GossipMap {
path: file_name.to_owned(),
path: Some(file_name.to_owned()),
version: 0,
stream: Some(stream),
nodes: HashMap::new(),
Expand All @@ -76,13 +75,21 @@
}

/// add a node announcement message inside the gossip map
fn add_node_announcement(&mut self, node_announce: NodeAnnouncement) {}
fn add_node_announcement(&mut self, node_announce: NodeAnnouncement) {

Check warning on line 78 in gossip_map/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (stable)

unused variable: `node_announce`

Check warning on line 78 in gossip_map/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (stable)

methods `add_node_announcement` and `add_channel_announcement` are never used

Check warning on line 78 in gossip_map/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (stable)

unused variable: `node_announce`

Check warning on line 78 in gossip_map/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (stable)

methods `add_node_announcement` and `add_channel_announcement` are never used

Check warning on line 78 in gossip_map/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (beta)

unused variable: `node_announce`

Check warning on line 78 in gossip_map/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (beta)

methods `add_node_announcement` and `add_channel_announcement` are never used

Check warning on line 78 in gossip_map/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (beta)

unused variable: `node_announce`

Check warning on line 78 in gossip_map/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (beta)

methods `add_node_announcement` and `add_channel_announcement` are never used

Check warning on line 78 in gossip_map/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (nightly)

unused variable: `node_announce`

Check warning on line 78 in gossip_map/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (nightly)

methods `add_node_announcement` and `add_channel_announcement` are never used

Check warning on line 78 in gossip_map/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (nightly)

unused variable: `node_announce`

Check warning on line 78 in gossip_map/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (nightly)

methods `add_node_announcement` and `add_channel_announcement` are never used
unimplemented!()
}

/// add a channel announcement message inside the gossip map.
fn add_channel_announcement(&mut self, channel_announce: ChannelAnnouncement) {}
fn add_channel_announcement(&mut self, channel_announce: ChannelAnnouncement) {

Check warning on line 83 in gossip_map/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (stable)

unused variable: `channel_announce`

Check warning on line 83 in gossip_map/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (stable)

unused variable: `channel_announce`

Check warning on line 83 in gossip_map/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (beta)

unused variable: `channel_announce`

Check warning on line 83 in gossip_map/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (beta)

unused variable: `channel_announce`

Check warning on line 83 in gossip_map/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (nightly)

unused variable: `channel_announce`

Check warning on line 83 in gossip_map/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (nightly)

unused variable: `channel_announce`
unimplemented!()
}

fn refresh(&mut self) -> anyhow::Result<()> {
let gossip_store = File::open(self.path.clone())?;
let gossip_store = File::open(
self.path
.as_ref()
.ok_or(anyhow::anyhow!("Gossip map not found"))?,
)?;
let mut stream = BufReader::new(gossip_store);

let version = u8::from_wire(&mut stream)? as u16;
Expand Down
Loading