-
Notifications
You must be signed in to change notification settings - Fork 370
/
Copy pathhandler.rs
68 lines (60 loc) · 2.37 KB
/
handler.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! This module implements the processing logic for ICS4 (channel) messages.
use crate::handler::{Event, EventType, HandlerOutput};
use crate::ics04_channel::context::ChannelReader;
use crate::ics04_channel::channel::ChannelEnd;
use crate::ics04_channel::error::Error;
use crate::ics04_channel::msgs::ChannelMsg;
use crate::ics24_host::identifier::{ChannelId, PortId};
pub mod chan_open_init;
#[derive(Clone, Debug)]
pub enum ChannelEvent {
ChanOpenInit(ChannelResult),
// ConnOpenTry(ConnectionResult),
// ConnOpenAck(ConnectionResult),
// ConnOpenConfirm(ConnectionResult),
}
#[derive(Clone, Debug)]
pub struct ChannelResult {
pub port_id: PortId,
pub channel_id: ChannelId,
pub channel_end: ChannelEnd,
}
impl From<ChannelEvent> for Event {
fn from(ev: ChannelEvent) -> Event {
match ev {
ChannelEvent::ChanOpenInit(chan) => Event::new(
EventType::Custom("channel_open_init".to_string()),
vec![("channel_id".to_string(), chan.channel_id.to_string())],
),
// ChannelEvent::ChanOpenTry(conn) => Event::new(
// EventType::Custom("channel_open_try".to_string()),
// vec![("channel_id".to_string(), chan.channel_id.to_string())],
// ),
// ChannelEvent::ChanOpenAck(conn) => Event::new(
// EventType::Custom("channel_open_ack".to_string()),
// vec![("channel_id".to_string(), chan.channel_id.to_string())],
// ),
// ChannelEvent::ChanOpenConfirm(conn) => Event::new(
// EventType::Custom("channel_open_confirm".to_string()),
// vec![("channel_id".to_string(), conn.channel _id.to_string())],
// ),
}
}
}
/// General entry point for processing any type of message related to the ICS4 channel open
/// handshake protocol.
pub fn dispatch<Ctx>(
ctx: &Ctx,
msg: ChannelMsg,
) -> Result<HandlerOutput<ChannelResult>, Error>
where
Ctx: ChannelReader,
{
Ok(match msg {
ChannelMsg::ChannelOpenInit(msg) => chan_open_init::process(ctx, msg)?,
// ChannelMsg::ChannelOpenTry(msg) => chan_open_try::process(ctx, *msg)?,
// ChannelMsg::ChannelOpenAck(msg) => chan_open_ack::process(ctx, *msg)?,
// ChannelMsg::ChannelOpenConfirm(msg) => chan_open_confirm::process(ctx, msg)?,
_ => panic!(),
})
}