Skip to content

Commit

Permalink
Start storing address details in third normal form.
Browse files Browse the repository at this point in the history
  • Loading branch information
arik-so committed Mar 19, 2024
1 parent 3563c45 commit 282b03b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
35 changes: 33 additions & 2 deletions src/persistence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::mem;
use std::sync::Arc;
use std::time::{Duration, Instant};
use hex::DisplayHex;
use lightning::ln::msgs::SocketAddress;
use lightning::log_info;
use lightning::routing::gossip::NetworkGraph;
use lightning::util::logger::Logger;
Expand Down Expand Up @@ -173,8 +174,38 @@ impl<L: Deref> GossipPersister<L> where L::Target: Logger {
])).await.unwrap().unwrap()
};

let _node_id: i32 = node_announcement_row.get("id");
println!("node id: {}", _node_id);
let node_id: i32 = node_announcement_row.get("id");

for current_address in announcement.contents.addresses {
let address_row = tokio::time::timeout(POSTGRES_INSERT_TIMEOUT, client
.query_one("INSERT INTO node_address (\
announcement_id
) VALUES ($1) RETURNING id", &[
&node_id,
])).await.unwrap().unwrap();
let address_id: i32 = address_row.get("id");
match current_address {
SocketAddress::TcpIpV4 { .. } => {}
SocketAddress::TcpIpV6 { .. } => {}
SocketAddress::OnionV2(_) => {}
SocketAddress::OnionV3 { .. } => {}
SocketAddress::Hostname { hostname, port } => {
let host_string = hostname.to_string();
tokio::time::timeout(POSTGRES_INSERT_TIMEOUT, client
.execute("INSERT INTO address_hostname (\
address_id, \
hostname, \
port \
) VALUES ($1, $2, $3)", &[
&address_id,
&host_string,
&(port as i32)
])).await.unwrap().unwrap();
}
}
}

println!("node id: {}", node_id);

// insert addresses into DB in third normal form

Expand Down
1 change: 1 addition & 0 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ async fn test_node_announcement_persistence() {
port: 443,
});
announcement.contents.addresses.push(SocketAddress::TcpIpV4 { addr: [127, 0, 0, 1], port: 9635 });
announcement.contents.addresses.push(SocketAddress::TcpIpV6 { addr: [1; 16], port: 1337 });
announcement.contents.addresses.push(SocketAddress::OnionV2([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]));
announcement.contents.addresses.push(SocketAddress::OnionV3 {
ed25519_pubkey: [1; 32],
Expand Down

0 comments on commit 282b03b

Please sign in to comment.