Move nonce generator to utils module

This commit is contained in:
Patrick Auernig 2018-03-28 23:50:25 +02:00
parent 185b012fc0
commit 332dbab413
3 changed files with 9 additions and 4 deletions

View File

@ -1,6 +1,6 @@
use serde::Serialize;
use uuid::Uuid;
use super::Payload;
use utils::nonce;
#[derive(Debug, Default, Serialize)]
pub struct Command<T>
@ -19,7 +19,7 @@ impl<T> Command<T>
{
Command {
cmd: cmd.into(),
nonce: Uuid::new_v4().to_string(),
nonce: nonce(),
args: args
}
}

View File

@ -1,5 +1,5 @@
use uuid::Uuid;
use super::Payload;
use utils::nonce;
#[derive(Debug, Default, Serialize)]
pub struct Handshake {
@ -11,7 +11,7 @@ pub struct Handshake {
impl Handshake {
pub fn new(client_id: u64, version: u32) -> Self {
Self {
nonce: Uuid::new_v4().to_string(),
nonce: nonce(),
v: version,
client_id: client_id.to_string()
}

View File

@ -1,5 +1,10 @@
use libc::getpid;
use uuid::Uuid;
pub fn pid() -> i32 {
unsafe { getpid() as i32 }
}
pub fn nonce() -> String {
Uuid::new_v4().to_string()
}