|
@ -13,7 +13,6 @@ use std::collections::{HashMap, HashSet}; |
|
|
use std::io::{BufRead, BufReader, Lines, Write}; |
|
|
use std::io::{BufRead, BufReader, Lines, Write}; |
|
|
use std::net::{SocketAddr, TcpStream}; |
|
|
use std::net::{SocketAddr, TcpStream}; |
|
|
use std::path::PathBuf; |
|
|
use std::path::PathBuf; |
|
|
#[cfg(feature = "latest_rust")] |
|
|
|
|
|
use std::sync::atomic::{AtomicU64, Ordering}; |
|
|
use std::sync::atomic::{AtomicU64, Ordering}; |
|
|
use std::sync::{Arc, Mutex}; |
|
|
use std::sync::{Arc, Mutex}; |
|
|
use std::time::Duration; |
|
|
use std::time::Duration; |
|
@ -151,7 +150,7 @@ pub trait CookieGetter: Send + Sync { |
|
|
struct Connection { |
|
|
struct Connection { |
|
|
tx: TcpStream, |
|
|
tx: TcpStream, |
|
|
rx: Lines<BufReader<TcpStream>>, |
|
|
rx: Lines<BufReader<TcpStream>>, |
|
|
cookie_getter: Arc<CookieGetter>, |
|
|
cookie_getter: Arc<dyn CookieGetter>, |
|
|
addr: SocketAddr, |
|
|
addr: SocketAddr, |
|
|
signal: Waiter, |
|
|
signal: Waiter, |
|
|
} |
|
|
} |
|
@ -172,7 +171,7 @@ fn tcp_connect(addr: SocketAddr, signal: &Waiter) -> Result<TcpStream> { |
|
|
impl Connection { |
|
|
impl Connection { |
|
|
fn new( |
|
|
fn new( |
|
|
addr: SocketAddr, |
|
|
addr: SocketAddr, |
|
|
cookie_getter: Arc<CookieGetter>, |
|
|
cookie_getter: Arc<dyn CookieGetter>, |
|
|
signal: Waiter, |
|
|
signal: Waiter, |
|
|
) -> Result<Connection> { |
|
|
) -> Result<Connection> { |
|
|
let conn = tcp_connect(addr, &signal)?; |
|
|
let conn = tcp_connect(addr, &signal)?; |
|
@ -269,12 +268,10 @@ impl Connection { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#[cfg(feature = "latest_rust")] |
|
|
|
|
|
struct Counter { |
|
|
struct Counter { |
|
|
value: AtomicU64, |
|
|
value: AtomicU64, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#[cfg(feature = "latest_rust")] |
|
|
|
|
|
impl Counter { |
|
|
impl Counter { |
|
|
fn new() -> Self { |
|
|
fn new() -> Self { |
|
|
Counter { value: 0.into() } |
|
|
Counter { value: 0.into() } |
|
@ -286,26 +283,6 @@ impl Counter { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#[cfg(not(feature = "latest_rust"))] |
|
|
|
|
|
struct Counter { |
|
|
|
|
|
value: Mutex<u64>, |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[cfg(not(feature = "latest_rust"))] |
|
|
|
|
|
impl Counter { |
|
|
|
|
|
fn new() -> Self { |
|
|
|
|
|
Counter { |
|
|
|
|
|
value: Mutex::new(0), |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn next(&self) -> u64 { |
|
|
|
|
|
let mut value = self.value.lock().unwrap(); |
|
|
|
|
|
*value += 1; |
|
|
|
|
|
*value |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub struct Daemon { |
|
|
pub struct Daemon { |
|
|
daemon_dir: PathBuf, |
|
|
daemon_dir: PathBuf, |
|
|
network: Network, |
|
|
network: Network, |
|
@ -323,7 +300,7 @@ impl Daemon { |
|
|
pub fn new( |
|
|
pub fn new( |
|
|
daemon_dir: &PathBuf, |
|
|
daemon_dir: &PathBuf, |
|
|
daemon_rpc_addr: SocketAddr, |
|
|
daemon_rpc_addr: SocketAddr, |
|
|
cookie_getter: Arc<CookieGetter>, |
|
|
cookie_getter: Arc<dyn CookieGetter>, |
|
|
network: Network, |
|
|
network: Network, |
|
|
signal: Waiter, |
|
|
signal: Waiter, |
|
|
blocktxids_cache: Arc<BlockTxIDsCache>, |
|
|
blocktxids_cache: Arc<BlockTxIDsCache>, |
|
|