aboutsummaryrefslogblamecommitdiff
path: root/src/proto.rs
blob: 99ab8fbe6c2ce97e28ebcf5b40aca17fb2eb19b6 (plain) (tree)
1
2
3
4
5
6
7
8
                        
                         

                                    

                   
                                                              
 




                                        
                                



                                              

                                  

                                                                 






                                        
                              


                                

                                               

                             
 







                                        
use std::time::Duration;
use std::net::SocketAddr;
use serde::{Serialize, Deserialize};

use crate::data::*;

pub const DEFAULT_TIMEOUT: Duration = Duration::from_secs(30);

#[derive(Debug, Serialize, Deserialize)]
pub enum Message {
	Ok,
	Error(String),

	Ping(PingMessage),	
	PullStatus,
	PullConfig,
	AdvertiseNodesUp(Vec<AdvertisedNode>),
	AdvertiseConfig(NetworkConfig),

	PutBlock(PutBlockMessage),

	TableRPC(String, #[serde(with = "serde_bytes")] Vec<u8>),
}

#[derive(Debug, Serialize, Deserialize)]
pub struct PingMessage {
	pub id: UUID,
	pub rpc_port: u16,

	pub status_hash: Hash,
	pub config_version: u64,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct AdvertisedNode {
	pub id: UUID,
	pub addr: SocketAddr,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct PutBlockMessage {
	pub meta: BlockMeta,

	#[serde(with="serde_bytes")]
	pub data: Vec<u8>,
}