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

receive full address for visualizer #306

Merged
merged 1 commit into from
Jun 20, 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 grovedb/src/debugger.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
//! GroveDB debugging support module.

use std::{fs, net::Ipv4Addr, sync::Weak};

Check warning on line 3 in grovedb/src/debugger.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `net::Ipv4Addr`

warning: unused import: `net::Ipv4Addr` --> grovedb/src/debugger.rs:3:15 | 3 | use std::{fs, net::Ipv4Addr, sync::Weak}; | ^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default

use axum::{extract::State, http::StatusCode, response::IntoResponse, routing::post, Json, Router};
use grovedb_merk::debugger::NodeDbg;
use grovedb_path::SubtreePath;
use grovedbg_types::{NodeFetchRequest, NodeUpdate, Path};
use tokio::sync::mpsc::{self, Sender};
use tokio::{
net::ToSocketAddrs,
sync::mpsc::{self, Sender},
};
use tower_http::services::ServeDir;

use crate::{reference_path::ReferencePathType, GroveDb};

const GROVEDBG_ZIP: [u8; include_bytes!(concat!(env!("OUT_DIR"), "/grovedbg.zip")).len()] =
*include_bytes!(concat!(env!("OUT_DIR"), "/grovedbg.zip"));

pub(super) fn start_visualizer(grovedb: Weak<GroveDb>, port: u16) {
pub(super) fn start_visualizer<A>(grovedb: Weak<GroveDb>, addr: A)
where
A: ToSocketAddrs + Send + 'static,
{
std::thread::spawn(move || {
let grovedbg_tmp =
tempfile::tempdir().expect("cannot create tempdir for grovedbg contents");
let grovedbg_zip = grovedbg_tmp.path().join("grovedbg.zip");
let grovedbg_www = grovedbg_tmp.path().join("grovedbg_www");

fs::write(&grovedbg_zip, &GROVEDBG_ZIP).expect("cannot crate grovedbg.zip");

Check warning on line 30 in grovedb/src/debugger.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> grovedb/src/debugger.rs:30:34 | 30 | fs::write(&grovedbg_zip, &GROVEDBG_ZIP).expect("cannot crate grovedbg.zip"); | ^^^^^^^^^^^^^ help: change this to: `GROVEDBG_ZIP` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args = note: `#[warn(clippy::needless_borrows_for_generic_args)]` on by default
zip_extensions::read::zip_extract(&grovedbg_zip, &grovedbg_www)
.expect("cannot extract grovedbg contents");

Expand All @@ -35,7 +41,7 @@
tokio::runtime::Runtime::new()
.unwrap()
.block_on(async move {
let listener = tokio::net::TcpListener::bind((Ipv4Addr::LOCALHOST, port))
let listener = tokio::net::TcpListener::bind(addr)
.await
.expect("can't bind visualizer port");
axum::serve(listener, app)
Expand Down
9 changes: 7 additions & 2 deletions grovedb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@
use grovedb_visualize::DebugByteVectors;
#[cfg(any(feature = "full", feature = "verify"))]
pub use query::{PathQuery, SizedQuery};
#[cfg(feature = "grovedbg")]
use tokio::net::ToSocketAddrs;

#[cfg(feature = "full")]
use crate::element::helpers::raw_decode;
Expand Down Expand Up @@ -257,9 +259,12 @@

#[cfg(feature = "grovedbg")]
// Start visualizer server for the GroveDB instance
pub fn start_visualizer(self: &Arc<Self>, port: u16) {
pub fn start_visualizer<A>(self: &Arc<Self>, addr: A)
where
A: ToSocketAddrs + Send + 'static,
{
let weak = Arc::downgrade(self);
start_visualizer(weak, port);
start_visualizer(weak, addr);
}

/// Uses raw iter to delete GroveDB key values pairs from rocksdb
Expand Down Expand Up @@ -854,7 +859,7 @@
pub fn verify_grovedb(
&self,
transaction: TransactionArg,
) -> Result<HashMap<Vec<Vec<u8>>, (CryptoHash, CryptoHash, CryptoHash)>, Error> {

Check warning on line 862 in grovedb/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

very complex type used. Consider factoring parts into `type` definitions

warning: very complex type used. Consider factoring parts into `type` definitions --> grovedb/src/lib.rs:862:10 | 862 | ) -> Result<HashMap<Vec<Vec<u8>>, (CryptoHash, CryptoHash, CryptoHash)>, Error> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_complexity = note: `#[warn(clippy::type_complexity)]` on by default
if let Some(transaction) = transaction {
let root_merk = self
.open_transactional_merk_at_path(SubtreePath::empty(), transaction, None)
Expand All @@ -880,7 +885,7 @@
merk: Merk<S>,
path: &SubtreePath<B>,
batch: Option<&'db StorageBatch>,
) -> Result<HashMap<Vec<Vec<u8>>, (CryptoHash, CryptoHash, CryptoHash)>, Error> {

Check warning on line 888 in grovedb/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

very complex type used. Consider factoring parts into `type` definitions

warning: very complex type used. Consider factoring parts into `type` definitions --> grovedb/src/lib.rs:888:10 | 888 | ) -> Result<HashMap<Vec<Vec<u8>>, (CryptoHash, CryptoHash, CryptoHash)>, Error> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_complexity
let mut all_query = Query::new();
all_query.insert_all();

Expand Down Expand Up @@ -950,7 +955,7 @@
path: &SubtreePath<B>,
batch: Option<&'db StorageBatch>,
transaction: &Transaction,
) -> Result<HashMap<Vec<Vec<u8>>, (CryptoHash, CryptoHash, CryptoHash)>, Error> {

Check warning on line 958 in grovedb/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

very complex type used. Consider factoring parts into `type` definitions

warning: very complex type used. Consider factoring parts into `type` definitions --> grovedb/src/lib.rs:958:10 | 958 | ) -> Result<HashMap<Vec<Vec<u8>>, (CryptoHash, CryptoHash, CryptoHash)>, Error> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_complexity
let mut all_query = Query::new();
all_query.insert_all();

Expand Down
Loading