Skip to content

Commit

Permalink
Move unix socket server in its own module
Browse files Browse the repository at this point in the history
  • Loading branch information
edouardparis committed Nov 18, 2024
1 parent 626f678 commit 1a511e9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
31 changes: 31 additions & 0 deletions liana/src/jsonrpc/server/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#[cfg(unix)]
mod unix;

use std::{
io, path,
sync::{atomic::AtomicBool, Arc},
};

use crate::DaemonControl;

#[cfg(unix)]
pub fn run(
socket_path: &path::Path,
daemon_control: DaemonControl,
shutdown: Arc<AtomicBool>,
) -> Result<(), io::Error> {
let listener = unix::rpcserver_setup(socket_path)?;
log::info!("JSONRPC server started.");
let res = unix::rpcserver_loop(listener, daemon_control, shutdown);
log::info!("JSONRPC server stopped.");
res
}

#[cfg(windows)]
pub fn run(
_socket_path: &path::Path,
_daemon_control: DaemonControl,
_shutdown: Arc<AtomicBool>,
) -> Result<(), io::Error> {
todo!("Implement a json rpc server over Named pipe");
}
File renamed without changes.
8 changes: 2 additions & 6 deletions liana/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub use crate::bitcoin::{
electrum::{Electrum, ElectrumError},
};

use crate::jsonrpc::server::{rpcserver_loop, rpcserver_setup};
use crate::jsonrpc::server;
use crate::{
bitcoin::{poller, BitcoinInterface},
config::Config,
Expand Down Expand Up @@ -516,11 +516,7 @@ impl DaemonHandle {
move || {
let mut rpc_socket = data_dir;
rpc_socket.push("lianad_rpc");
let listener = rpcserver_setup(&rpc_socket)?;
log::info!("JSONRPC server started.");

rpcserver_loop(listener, control, shutdown)?;
log::info!("JSONRPC server stopped.");
server::run(&rpc_socket, control, shutdown)?;
Ok(())
}
})
Expand Down

0 comments on commit 1a511e9

Please sign in to comment.