garage/src/proto.rs

48 lines
898 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::*;
pub const DEFAULT_TIMEOUT: Duration = Duration::from_secs(30);
#[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>,
}