|
|
@ -22,8 +22,8 @@ use super::rpc; |
|
|
|
|
|
|
|
|
|
|
|
/// Chat connect data structure.
|
|
|
|
/// Chat connect data structure.
|
|
|
|
/// params: Friend about me height
|
|
|
|
/// params: Friend about me height
|
|
|
|
#[derive(Serialize, Deserialize)] |
|
|
|
//#[derive(Serialize, Deserialize)]
|
|
|
|
pub struct LayerConnect(pub i64); |
|
|
|
//pub struct LayerConnect(pub i64);
|
|
|
|
|
|
|
|
|
|
|
|
/// ESSE chat layer Event.
|
|
|
|
/// ESSE chat layer Event.
|
|
|
|
#[derive(Serialize, Deserialize)] |
|
|
|
#[derive(Serialize, Deserialize)] |
|
|
@ -58,9 +58,9 @@ pub(crate) async fn handle(msg: RecvType, global: &Arc<Global>) -> Result<Handle |
|
|
|
let pid = global.pid().await; |
|
|
|
let pid = global.pid().await; |
|
|
|
|
|
|
|
|
|
|
|
match msg { |
|
|
|
match msg { |
|
|
|
RecvType::Connect(peer, data) | RecvType::ResultConnect(peer, data) => { |
|
|
|
RecvType::Connect(peer, _) | RecvType::ResultConnect(peer, _) => { |
|
|
|
// ESSE chat layer connect date structure.
|
|
|
|
// ESSE chat layer connect date structure.
|
|
|
|
if let Ok(height) = handle_connect(pid, &peer, data, global, &mut results).await { |
|
|
|
if let Ok(height) = handle_connect(pid, &peer, global, &mut results).await { |
|
|
|
let peer_id = peer.id; |
|
|
|
let peer_id = peer.id; |
|
|
|
let msg = SendType::Result(0, peer, true, false, vec![]); |
|
|
|
let msg = SendType::Result(0, peer, true, false, vec![]); |
|
|
|
results.layers.push((CHAT_ID, msg)); |
|
|
|
results.layers.push((CHAT_ID, msg)); |
|
|
@ -74,10 +74,10 @@ pub(crate) async fn handle(msg: RecvType, global: &Arc<Global>) -> Result<Handle |
|
|
|
results.layers.push((CHAT_ID, msg)); |
|
|
|
results.layers.push((CHAT_ID, msg)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
RecvType::Result(peer, is_ok, data) => { |
|
|
|
RecvType::Result(peer, is_ok, _) => { |
|
|
|
// ESSE chat layer result date structure.
|
|
|
|
// ESSE chat layer result date structure.
|
|
|
|
if is_ok { |
|
|
|
if is_ok { |
|
|
|
if let Ok(height) = handle_connect(pid, &peer, data, global, &mut results).await { |
|
|
|
if let Ok(height) = handle_connect(pid, &peer, global, &mut results).await { |
|
|
|
let info = LayerEvent::InfoReq(height); |
|
|
|
let info = LayerEvent::InfoReq(height); |
|
|
|
let data = bincode::serialize(&info).unwrap_or(vec![]); |
|
|
|
let data = bincode::serialize(&info).unwrap_or(vec![]); |
|
|
|
let msg = SendType::Event(0, peer.id, data); |
|
|
|
let msg = SendType::Event(0, peer.id, data); |
|
|
@ -134,7 +134,6 @@ pub(crate) async fn handle(msg: RecvType, global: &Arc<Global>) -> Result<Handle |
|
|
|
async fn handle_connect( |
|
|
|
async fn handle_connect( |
|
|
|
pid: PeerId, |
|
|
|
pid: PeerId, |
|
|
|
peer: &Peer, |
|
|
|
peer: &Peer, |
|
|
|
data: Vec<u8>, |
|
|
|
|
|
|
|
global: &Arc<Global>, |
|
|
|
global: &Arc<Global>, |
|
|
|
results: &mut HandleResult, |
|
|
|
results: &mut HandleResult, |
|
|
|
) -> Result<u64> { |
|
|
|
) -> Result<u64> { |
|
|
@ -328,6 +327,7 @@ impl LayerEvent { |
|
|
|
if !keep { |
|
|
|
if !keep { |
|
|
|
results.layers.push((CHAT_ID, SendType::Disconnect(fpid))) |
|
|
|
results.layers.push((CHAT_ID, SendType::Disconnect(fpid))) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// TODO close session
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -335,6 +335,12 @@ impl LayerEvent { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub(crate) fn chat_conn(pid: PeerId, results: &mut HandleResult) { |
|
|
|
|
|
|
|
results |
|
|
|
|
|
|
|
.layers |
|
|
|
|
|
|
|
.push((CHAT_ID, SendType::Connect(0, Peer::peer(pid), vec![]))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// UPDATE SESSION.
|
|
|
|
// UPDATE SESSION.
|
|
|
|
pub(crate) fn update_session(s_db: &DStorage, id: &i64, msg: &Message, results: &mut HandleResult) { |
|
|
|
pub(crate) fn update_session(s_db: &DStorage, id: &i64, msg: &Message, results: &mut HandleResult) { |
|
|
|
let scontent = match msg.m_type { |
|
|
|
let scontent = match msg.m_type { |
|
|
|