use data::{EntryAction, ImmutableData, MutableData, PermissionSet, User};
use rust_sodium::crypto::sign;
use std::collections::{BTreeMap, BTreeSet};
use types::MessageId as MsgId;
use xor_name::XorName;
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
pub enum Request {
Refresh(Vec<u8>, MsgId),
GetAccountInfo(MsgId),
PutIData {
data: ImmutableData,
msg_id: MsgId,
},
GetIData {
name: XorName,
msg_id: MsgId,
},
GetMData {
name: XorName,
tag: u64,
msg_id: MsgId,
},
PutMData {
data: MutableData,
msg_id: MsgId,
requester: sign::PublicKey,
},
GetMDataVersion {
name: XorName,
tag: u64,
msg_id: MsgId,
},
GetMDataShell {
name: XorName,
tag: u64,
msg_id: MsgId,
},
ListMDataEntries {
name: XorName,
tag: u64,
msg_id: MsgId,
},
ListMDataKeys {
name: XorName,
tag: u64,
msg_id: MsgId,
},
ListMDataValues {
name: XorName,
tag: u64,
msg_id: MsgId,
},
GetMDataValue {
name: XorName,
tag: u64,
key: Vec<u8>,
msg_id: MsgId,
},
MutateMDataEntries {
name: XorName,
tag: u64,
actions: BTreeMap<Vec<u8>, EntryAction>,
msg_id: MsgId,
requester: sign::PublicKey,
},
ListMDataPermissions {
name: XorName,
tag: u64,
msg_id: MsgId,
},
ListMDataUserPermissions {
name: XorName,
tag: u64,
user: User,
msg_id: MsgId,
},
SetMDataUserPermissions {
name: XorName,
tag: u64,
user: User,
permissions: PermissionSet,
version: u64,
msg_id: MsgId,
requester: sign::PublicKey,
},
DelMDataUserPermissions {
name: XorName,
tag: u64,
user: User,
version: u64,
msg_id: MsgId,
requester: sign::PublicKey,
},
ChangeMDataOwner {
name: XorName,
tag: u64,
new_owners: BTreeSet<sign::PublicKey>,
version: u64,
msg_id: MsgId,
},
ListAuthKeysAndVersion(MsgId),
InsAuthKey {
key: sign::PublicKey,
version: u64,
msg_id: MsgId,
},
DelAuthKey {
key: sign::PublicKey,
version: u64,
msg_id: MsgId,
},
}
impl Request {
pub fn message_id(&self) -> &MsgId {
use Request::*;
match *self {
Refresh(_, ref msg_id)
| GetAccountInfo(ref msg_id)
| PutIData { ref msg_id, .. }
| GetIData { ref msg_id, .. }
| GetMData { ref msg_id, .. }
| PutMData { ref msg_id, .. }
| GetMDataVersion { ref msg_id, .. }
| GetMDataShell { ref msg_id, .. }
| ListMDataEntries { ref msg_id, .. }
| ListMDataKeys { ref msg_id, .. }
| ListMDataValues { ref msg_id, .. }
| GetMDataValue { ref msg_id, .. }
| MutateMDataEntries { ref msg_id, .. }
| ListMDataPermissions { ref msg_id, .. }
| ListMDataUserPermissions { ref msg_id, .. }
| SetMDataUserPermissions { ref msg_id, .. }
| DelMDataUserPermissions { ref msg_id, .. }
| ChangeMDataOwner { ref msg_id, .. }
| ListAuthKeysAndVersion(ref msg_id)
| InsAuthKey { ref msg_id, .. }
| DelAuthKey { ref msg_id, .. } => msg_id,
}
}
pub fn is_cacheable(&self) -> bool {
if let Request::GetIData { .. } = *self {
true
} else {
false
}
}
}