Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hansieodendaal committed Feb 23, 2022
1 parent 6e979fd commit bfb07e8
Showing 1 changed file with 29 additions and 30 deletions.
59 changes: 29 additions & 30 deletions applications/tari_merge_mining_proxy/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,37 +655,36 @@ impl InnerService {
None => "".to_string(),
}
};
let mut iter = self.config.monerod_url.iter();
// 'find' will position 'iter.next()' at the next item in the list
let _ = iter.find(|&x| x == &last_used_url);
let mut count = 0;
loop {
count += 1;
// Query the list twice before giving up
if count > self.config.monerod_url.len() * 2 {
break;

// Query the list twice before giving up, starting after the last used entry
let pos = if let Some(index) = self.config.monerod_url.iter().position(|x| x == &last_used_url) {
index
} else {
0
};
let (left, right) = self.config.monerod_url.split_at(pos);
let left = left.to_vec();
let right = right.to_vec();
let iter = right.iter().chain(left.iter()).chain(right.iter()).chain(left.iter());

for next_url in iter {
let uri = format!("{}{}", next_url, uri.path()).parse::<Url>()?;
match reqwest::get(uri.clone()).await {
Ok(_) => {
let mut lock = self.current_monerod_server.write().expect("Write lock should not fail");
*lock = Some(next_url.to_string());
let mut lock = self
.last_assigned_monerod_server
.write()
.expect("Write lock should not fail");
*lock = Some(next_url.to_string());
info!(target: LOG_TARGET, "Monerod server available: {:?}", uri.clone());
return Ok(uri);
},
Err(_) => {
warn!(target: LOG_TARGET, "Monerod server unavailable: {:?}", uri);
},
}
if let Some(next_url) = iter.next() {
let uri = format!("{}{}", next_url, uri.path()).parse::<Url>()?;
match reqwest::get(uri.clone()).await {
Ok(_) => {
let mut lock = self.current_monerod_server.write().expect("Write lock should not fail");
*lock = Some(next_url.to_string());
let mut lock = self
.last_assigned_monerod_server
.write()
.expect("Write lock should not fail");
*lock = Some(next_url.to_string());
info!(target: LOG_TARGET, "Monerod server available: {:?}", uri.clone());
return Ok(uri);
},
Err(_) => {
warn!(target: LOG_TARGET, "Monerod server unavailable: {:?}", uri);
},
}
} else {
iter = self.config.monerod_url.iter();
};
}

Err(MmProxyError::ServersUnavailable)
Expand Down

0 comments on commit bfb07e8

Please sign in to comment.