two sub not-owning instance send update-request, on getting an update
This commit is contained in:
@@ -229,9 +229,17 @@ impl Instance {
|
||||
vec.push(sub);
|
||||
},
|
||||
None => {
|
||||
subs_inner.insert(id, vec![sub]);
|
||||
subs_inner.insert(id.clone(), vec![sub]);
|
||||
}
|
||||
}
|
||||
|
||||
// if we are not the owner of this item, send a sub msg to them
|
||||
if !self.we_are_namespace()? {
|
||||
let con = self.get_connection_by_ns(id.namespace())?;
|
||||
let msg = MizeMessage::new_sub(id, con.id);
|
||||
con.send(msg)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -96,6 +96,13 @@ fn handle_msg(msg: &mut MizeMessage, instance: &Instance) -> MizeResult<()> {
|
||||
instance.sub(id, sub)?;
|
||||
},
|
||||
|
||||
MessageCmd::Sub => {
|
||||
let id = msg.id(instance)?;
|
||||
let mut connection = instance.get_connection(msg.conn_id)?.clone();
|
||||
let sub = Subscription::from_conn(connection.clone());
|
||||
instance.sub(id, sub)?;
|
||||
},
|
||||
|
||||
MessageCmd::Update => {
|
||||
let data = msg.data()?;
|
||||
let id = msg.id(instance)?;
|
||||
|
||||
@@ -26,6 +26,7 @@ static CMD_CREATE: u16 = 4;
|
||||
static CMD_CREATE_REPLY: u16 = 5;
|
||||
static CMD_UPDATE_REQUEST: u16 = 6;
|
||||
static CMD_GET_SUB: u16 = 7;
|
||||
static CMD_SUB: u16 = 8;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum MessageCmd {
|
||||
@@ -36,6 +37,7 @@ pub enum MessageCmd {
|
||||
CreateReply,
|
||||
UpdateRequest,
|
||||
GetSub,
|
||||
Sub,
|
||||
}
|
||||
|
||||
|
||||
@@ -66,6 +68,16 @@ impl MizeMessage {
|
||||
MizeMessage::new(value, conn_id)
|
||||
}
|
||||
|
||||
pub fn new_sub(id: MizeId, conn_id: u64) -> MizeMessage {
|
||||
let id_path = id.path().into_iter().map(|string| CborValue::Text(string.to_owned())).collect();
|
||||
|
||||
let cmd = (CborValue::Integer(MSG_CMD.into()), CborValue::Integer(CMD_SUB.into()));
|
||||
let id = (CborValue::Integer(MSG_ID.into()), CborValue::Array(id_path));
|
||||
let value = CborValue::Map(vec![cmd, id]);
|
||||
|
||||
MizeMessage::new(value, conn_id)
|
||||
}
|
||||
|
||||
pub fn new_create(conn_id: u64) -> MizeMessage {
|
||||
let cmd = (CborValue::Integer(MSG_CMD.into()), CborValue::Integer(CMD_CREATE.into()));
|
||||
let value = CborValue::Map(vec![cmd]);
|
||||
@@ -157,6 +169,8 @@ impl MizeMessage {
|
||||
4 => MessageCmd::Create,
|
||||
5 => MessageCmd::CreateReply,
|
||||
6 => MessageCmd::UpdateRequest,
|
||||
7 => MessageCmd::GetSub,
|
||||
8 => MessageCmd::Sub,
|
||||
_ => {
|
||||
return Err(MizeError::new().msg("error cmd of msg was not a valid command"));
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user