Skip to content

Commit

Permalink
Remove refresh interval, use DEFAULT_INTERVAL=10 for sleeps
Browse files Browse the repository at this point in the history
- Probably can remove a lot more of code related to refresh interval
- But, proceeding with caution due to something in the challenge sections/refresh interval sections causing a hang in epic-wallet calls, when all is removed
- Working on figuring out what the problem area is
- For now, this commit is fully functional, when taken in tandem with the prior
  • Loading branch information
who-biz committed Mar 15, 2023
1 parent 0fd1baa commit 8173171
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 45 deletions.
3 changes: 0 additions & 3 deletions controller/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ where
/// Arguments for listen command
pub struct ListenArgs {
pub method: String,
pub interval: Option<u64>,
}

pub fn listen<L, C, K>(
Expand Down Expand Up @@ -165,7 +164,6 @@ where
wallet.clone(),
keychain_mask.clone(),
epicbox_config.clone(),
args.interval,
);
warn!("try to reconnect to epicbox");
match listener {
Expand Down Expand Up @@ -196,7 +194,6 @@ where
};

debug!("{}", args.method.clone());
debug!("{}", args.interval.unwrap_or(10));

if let Err(e) = res {
return Err(ErrorKind::LibWallet(e.kind(), e.cause_string()).into());
Expand Down
52 changes: 12 additions & 40 deletions impls/src/adapters/epicbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ use tungstenite::{Error as ErrorTungstenite, Message};
const CONNECTION_ERR_MSG: &str = "\nCan't connect to the epicbox server!\n\
Check your epic-wallet.toml settings and make sure epicbox domain is correct.\n";
const DEFAULT_INTERVAL: u64 = 10;
const MIN_INTERVAL: u64 = 2;
const MAX_INTERVAL: u64 = 120;

const DEFAULT_CHALLENGE_RAW: &str = "7WUDtkSaKyGRUnQ22rE3QUXChV8DmA6NnunDYP4vheTpc";

/// Epicbox 'plugin' implementation
Expand Down Expand Up @@ -120,14 +117,13 @@ impl EpicboxListenChannel {
wallet: Arc<Mutex<Box<dyn WalletInst<'static, L, C, K> + 'static>>>,
keychain_mask: Arc<Mutex<Option<SecretKey>>>,
epicbox_config: EpicboxConfig,
interval_arg: Option<u64>,
) -> Result<(), Error>
where
L: WalletLCProvider<'static, C, K> + 'static,
C: NodeClient + 'static,
K: Keychain + 'static,
{
let (address, sec_key, interval) = {
let (address, sec_key) = {
let a_keychain = keychain_mask.clone();
let a_wallet = wallet.clone();
let mask = a_keychain.lock();
Expand All @@ -147,12 +143,7 @@ impl EpicboxListenChannel {
epicbox_config.epicbox_port,
);

let mut interval = interval_arg;
if interval.is_none() {
interval = epicbox_config.epicbox_listener_interval
}

(address, sec_key, interval)
(address, sec_key)
};
let url = {
let cloned_address = address.clone();
Expand Down Expand Up @@ -190,7 +181,7 @@ impl EpicboxListenChannel {

warn!("Starting epicbox listener for: {}", address);

subscriber.start(controller, interval)
subscriber.start(controller)
}
}
impl EpicboxChannel {
Expand Down Expand Up @@ -264,7 +255,7 @@ where
C: NodeClient + 'static,
K: Keychain + 'static,
{
let (address, sec_key, interval) = {
let (address, sec_key) = {
let a_wallet = wallet.clone();
let mut w_lock = a_wallet.lock();
let lc = w_lock.lc_provider()?;
Expand All @@ -276,14 +267,12 @@ where
.unwrap();
let pub_key = PublicKey::from_secret_key(k.secp(), &sec_key).unwrap();

let interval: Option<u64> = config.epicbox_listener_interval;

let address = EpicboxAddress::new(
pub_key.clone(),
Some(config.epicbox_domain.clone()),
config.epicbox_port,
);
(address, sec_key, interval)
(address, sec_key)
};
let url = {
let cloned_address = address.clone();
Expand Down Expand Up @@ -314,7 +303,7 @@ where
.expect("Could not init epicbox controller!");

csubscriber
.start(controller, interval)
.start(controller)
.expect("Could not start epicbox controller!");
()
});
Expand Down Expand Up @@ -580,11 +569,7 @@ where
}
}
pub trait Subscriber {
fn start<P, L, C, K>(
&mut self,
handler: EpicboxController<P, L, C, K>,
interval: Option<u64>,
) -> Result<(), Error>
fn start<P, L, C, K>(&mut self, handler: EpicboxController<P, L, C, K>) -> Result<(), Error>
where
P: Publisher,
L: WalletLCProvider<'static, C, K> + 'static,
Expand All @@ -593,19 +578,15 @@ pub trait Subscriber {
fn stop(&self);
}
impl Subscriber for EpicboxSubscriber {
fn start<P, L, C, K>(
&mut self,
handler: EpicboxController<P, L, C, K>,
interval: Option<u64>,
) -> Result<(), Error>
fn start<P, L, C, K>(&mut self, handler: EpicboxController<P, L, C, K>) -> Result<(), Error>
where
P: Publisher,
L: WalletLCProvider<'static, C, K> + 'static,
C: NodeClient + 'static,
K: Keychain + 'static,
{
self.broker
.subscribe(&self.address, &self.secret_key, handler, interval)
.subscribe(&self.address, &self.secret_key, handler)
}

fn stop(&self) {
Expand Down Expand Up @@ -646,7 +627,6 @@ impl EpicboxBroker {
address: &EpicboxAddress,
secret_key: &SecretKey,
handler: EpicboxController<P, L, C, K>,
interval: Option<u64>,
) -> Result<(), Error>
where
P: Publisher,
Expand All @@ -658,15 +638,8 @@ impl EpicboxBroker {
let sender = self.inner.clone();
let mut first_run = true;

// Parse from epicbox config or use default value for the
// time interval between new subscribe calls from the wallet
let mut seconds = interval.unwrap_or(DEFAULT_INTERVAL);
if seconds < MIN_INTERVAL {
seconds = MIN_INTERVAL
} else if seconds > MAX_INTERVAL {
seconds = MAX_INTERVAL
}
let duration = std::time::Duration::from_secs(seconds);
// time interval for sleep in main loop
let duration = std::time::Duration::from_secs(DEFAULT_INTERVAL);

let mut client = EpicboxClient {
sender,
Expand Down Expand Up @@ -722,7 +695,7 @@ impl EpicboxBroker {
client
.challenge_send()
.map_err(|_| {
error!("Error attempting to subscribe!");
error!("Error attempting to send Challenge!");
})
.unwrap();

Expand Down Expand Up @@ -788,7 +761,6 @@ impl EpicboxBroker {
.map_err(|_| error!("error attempting challenge!"))
.unwrap();

debug!("Refresh epicbox subscription (interval: {:?})", duration);
if first_run {
std::thread::sleep(duration);
first_run = false;
Expand Down
2 changes: 0 additions & 2 deletions src/cmd/wallet_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,15 +352,13 @@ pub fn parse_listen_args(
config.api_listen_port = port.parse().unwrap();
}

let interval = parse_u64_or_none(args.value_of("interval"));
let method = parse_required(args, "method")?;

if args.is_present("no_tor") {
tor_config.use_tor_listener = false;
}
Ok(command::ListenArgs {
method: method.to_owned(),
interval,
})
}

Expand Down

0 comments on commit 8173171

Please sign in to comment.