2020-04-10 20:01:48 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2020-04-06 17:55:39 +00:00
|
|
|
use std::net::SocketAddr;
|
2020-04-10 20:01:48 +00:00
|
|
|
use std::time::Duration;
|
2020-04-05 21:33:42 +00:00
|
|
|
|
2020-04-06 17:55:39 +00:00
|
|
|
use crate::data::*;
|
|
|
|
|
2020-04-12 20:24:53 +00:00
|
|
|
pub const DEFAULT_TIMEOUT: Duration = Duration::from_secs(10);
|
|
|
|
pub const BLOCK_RW_TIMEOUT: Duration = Duration::from_secs(42);
|
2020-04-07 14:26:22 +00:00
|
|
|
|
2020-04-05 21:33:42 +00:00
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
|
pub enum Message {
|
|
|
|
Ok,
|
|
|
|
Error(String),
|
|
|
|
|
2020-04-10 20:01:48 +00:00
|
|
|
Ping(PingMessage),
|
2020-04-06 20:27:51 +00:00
|
|
|
PullStatus,
|
|
|
|
PullConfig,
|
|
|
|
AdvertiseNodesUp(Vec<AdvertisedNode>),
|
|
|
|
AdvertiseConfig(NetworkConfig),
|
2020-04-07 22:39:07 +00:00
|
|
|
|
2020-04-09 21:45:07 +00:00
|
|
|
GetBlock(Hash),
|
2020-04-07 22:39:07 +00:00
|
|
|
PutBlock(PutBlockMessage),
|
2020-04-08 20:00:41 +00:00
|
|
|
|
|
|
|
TableRPC(String, #[serde(with = "serde_bytes")] Vec<u8>),
|
2020-04-06 17:55:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
|
pub struct PingMessage {
|
|
|
|
pub id: UUID,
|
|
|
|
pub rpc_port: u16,
|
|
|
|
|
2020-04-06 20:27:51 +00:00
|
|
|
pub status_hash: Hash,
|
2020-04-06 17:55:39 +00:00
|
|
|
pub config_version: u64,
|
|
|
|
}
|
|
|
|
|
2020-04-06 20:27:51 +00:00
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
|
|
pub struct AdvertisedNode {
|
2020-04-06 17:55:39 +00:00
|
|
|
pub id: UUID,
|
|
|
|
pub addr: SocketAddr,
|
2020-04-05 21:33:42 +00:00
|
|
|
}
|
2020-04-07 22:39:07 +00:00
|
|
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
|
pub struct PutBlockMessage {
|
2020-04-09 21:45:07 +00:00
|
|
|
pub hash: Hash,
|
2020-04-07 22:39:07 +00:00
|
|
|
|
2020-04-10 20:01:48 +00:00
|
|
|
#[serde(with = "serde_bytes")]
|
2020-04-07 22:39:07 +00:00
|
|
|
pub data: Vec<u8>,
|
|
|
|
}
|