const PING_PERIOD: Duration = Duration::from_secs(5); // 5 s.
const EMAIL_RESEND_PERIOD: Duration = Duration::from_secs(2 * 60 * 60); // 2 h.
const STATE_PRINT_PERIOD: Duration = Duration::from_secs(15 * 60); // 15 min.
+const SOCKET_TIMEOUT: Duration = Duration::from_secs(7);
fn main() -> Result<()> {
println!("Staking Watchdog Watchdog");
let socket = UdpSocket::bind("0.0.0.0:0").unwrap();
socket.connect("192.168.2.102:8739").unwrap();
- socket
- .set_read_timeout(Some(Duration::from_secs(5)))
- .unwrap();
- socket
- .set_write_timeout(Some(Duration::from_secs(5)))
- .unwrap();
+ socket.set_nonblocking(false).unwrap();
+ socket.set_read_timeout(Some(SOCKET_TIMEOUT)).unwrap();
+ socket.set_write_timeout(Some(SOCKET_TIMEOUT)).unwrap();
loop {
let time_beginning_loop = time::Instant::now();
// Send e-mail.
println!("Sending email...");
match send_email(
- "Watchdog ERROR",
+ "Watchdog Watchdog ERROR",
&format!("Error: {:?}", error),
&config.smtp_login,
&config.smtp_password,
#[derive(Debug)]
enum PingError {
- SocketError(std::io::Error),
+ SocketReceiveError(std::io::Error),
+ SocketSendError(std::io::Error),
WrongMessageReceived(String),
}
)));
}
}
- Err(error) => return Err(PingError::SocketError(error)),
+ Err(error) => return Err(PingError::SocketReceiveError(error)),
}
}
- Err(error) => return Err(PingError::SocketError(error)),
+ Err(error) => return Err(PingError::SocketSendError(error)),
}
Ok(time::Instant::now() - now)
fn send_email(title: &str, body: &str, login: &str, pass: &str) -> Result<()> {
let email = Message::builder()
.message_id(None)
- .from("Staking Watchdog <redmine@d-lan.net>".parse()?)
+ .from("Staking Watchdog Watchdog <redmine@d-lan.net>".parse()?)
.to("Greg Burri <greg.burri@gmail.com>".parse()?)
.subject(title)
.header(ContentType::TEXT_PLAIN)