garage/src/proto.rs

49 lines
962 B
Rust
Raw Normal View History

use serde::{Deserialize, Serialize};
2020-04-06 17:55:39 +00:00
use std::net::SocketAddr;
use std::time::Duration;
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);
#[derive(Debug, Serialize, Deserialize)]
pub enum Message {
Ok,
Error(String),
Ping(PingMessage),
2020-04-06 20:27:51 +00:00
PullStatus,
PullConfig,
AdvertiseNodesUp(Vec<AdvertisedNode>),
AdvertiseConfig(NetworkConfig),
2020-04-09 21:45:07 +00:00
GetBlock(Hash),
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,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct PutBlockMessage {
2020-04-09 21:45:07 +00:00
pub hash: Hash,
#[serde(with = "serde_bytes")]
pub data: Vec<u8>,
}