Browse Source

Message and tunnel structs

interface-2
Lev 3 years ago
parent
commit
c33253acb9
  1. 4
      src/ironforce.rs
  2. 1
      src/lib.rs
  3. 74
      src/message.rs
  4. 30
      src/tunnel.rs

4
src/ironforce.rs

@ -1,3 +1,5 @@
pub struct IronForce { use crate::transport::Transport;
pub struct IronForce {
transport: Transport
} }

1
src/lib.rs

@ -13,6 +13,7 @@ mod transport;
mod interface; mod interface;
mod interfaces; mod interfaces;
mod res; mod res;
mod tunnel;
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {

74
src/message.rs

@ -1,5 +1,79 @@
use alloc::vec::Vec; use alloc::vec::Vec;
use crate::crypto::{Keys, PublicKey};
use crate::res::IFResult;
use crate::tunnel::TunnelPublic;
/// A serialized message /// A serialized message
pub(crate) type MessageBytes = Vec<u8>; pub(crate) type MessageBytes = Vec<u8>;
pub enum Signature {
/// The message is signed. Author is unknown
NotSigned,
/// The message is signed with the sender's key visible to everyone
Signed {
sender: PublicKey,
signature: Vec<u8>,
},
/// Sender's key is encrypted for the recipient
SignedPrivately {
sender_encrypted: Vec<u8>,
signature: Vec<u8>,
}
}
pub enum MessageType {
SingleCast,
Broadcast,
Service(ServiceMessageType),
}
pub enum ServiceMessageType {
TunnelBuilding(TunnelPublic)
}
pub enum MessageContent {
/// Just plaintext message content
Plain(Vec<u8>),
/// Message content bytes encrypted for the recipient
Encrypted(Vec<u8>),
}
pub struct Message {
/// Content of the message (not to be confused with the bytes that we are sending through interfaces)
content: MessageContent,
/// The type of this message
message_type: MessageType,
/// Sender's signature
signature: Signature,
/// A random number that is used in hash together with the content
salt: u64,
/// Hash of message content and the salt
hash: Vec<u8>,
/// Optional: hash of the message encrypted for the recipient, so that the recipient can know that this message is for them, but nobody else
recipient_verification: Option<Vec<u8>>,
/// ID of the tunnel that is used
tunnel_id: u64,
}
impl Message {
/// Verify message's hash
pub fn verify(&self) -> bool {
todo!()
}
/// Check if this message is for this set of keys
pub fn check_recipient(&self, _keys: Keys) -> bool {
todo!()
}
/// Get decrypted content of the message
pub fn get_decrypted(&self, _keys: Keys) -> IFResult<Vec<u8>> {
todo!()
}
pub fn calculate_hash(_content: MessageContent, _message_type: MessageType, _sender: Option<PublicKey>) -> Vec<u8> {
todo!()
}
}

30
src/tunnel.rs

@ -0,0 +1,30 @@
use alloc::vec::Vec;
use crate::crypto::PublicKey;
/// A tunnel that is used for communication
pub struct Tunnel {
/// Tunnel's id
id: Option<u64>,
/// Ids that are
local_ids: Vec<u64>,
/// Ids of peers (in transport) by which we can send a message - one for backward direction, another for forward
peer_ids: (u64, u64),
/// Time at which this tunnel should be destroyed (UNIX epoch)
ttd: u64,
/// Public keys of nodes
nodes_in_tunnel: Option<Vec<PublicKey>>,
/// Is this tunnel used for multicast?
is_multicast: bool,
}
/// Tunnel, but only the fields that are ok to share
pub struct TunnelPublic {
/// Tunnel's id
id: Option<u64>,
/// Ids that are
local_ids: Vec<u64>,
/// Time at which this tunnel should be destroyed (UNIX epoch)
ttd: u64,
/// Public keys of nodes
nodes_in_tunnel: Option<Vec<PublicKey>>,
}
Loading…
Cancel
Save