1use rusty_tpkt::TpktError;
2use thiserror::Error;
3
4#[derive(Error, Debug)]
5pub enum CotpError {
6 #[error("COTP Protocol Error - {}", .0)]
7 ProtocolError(String),
8
9 #[error("COTP over TPKT Protocol Stack Error - {}", .0)]
10 ProtocolStackError(#[from] TpktError),
11
12 #[error("COTP IO Error: {:?}", .0)]
13 IoError(#[from] std::io::Error),
14
15 #[error("COTP Error: {}", .0)]
16 InternalError(String),
17}
18
19#[derive(PartialEq, Clone, Debug)]
20pub struct CotpConnectInformation {
21 pub initiator_reference: u16,
22 pub calling_tsap_id: Option<Vec<u8>>,
23 pub called_tsap_id: Option<Vec<u8>>,
24}
25
26impl Default for CotpConnectInformation {
27 fn default() -> Self {
28 Self {
29 initiator_reference: rand::random(),
30 calling_tsap_id: None,
31 called_tsap_id: None,
32 }
33 }
34}
35
36#[derive(PartialEq, Debug)]
37pub struct CotpAcceptInformation {
38 pub responder_reference: u16,
39}
40
41impl Default for CotpAcceptInformation {
42 fn default() -> Self {
43 Self { responder_reference: rand::random() }
44 }
45}
46
47pub enum CotpRecvResult {
48 Closed,
49 Data(Vec<u8>),
50}
51
52pub trait CotpResponder: Send {
53 fn accept(self, options: CotpAcceptInformation) -> impl std::future::Future<Output = Result<impl CotpConnection, CotpError>> + Send;
54}
55
56pub trait CotpConnection: Send {
57 fn split(self) -> impl std::future::Future<Output = Result<(impl CotpReader, impl CotpWriter), CotpError>> + Send;
58}
59
60pub trait CotpReader: Send {
61 fn recv(&mut self) -> impl std::future::Future<Output = Result<CotpRecvResult, CotpError>> + Send;
62}
63
64pub trait CotpWriter: Send {
65 fn send(&mut self, data: &[u8]) -> impl std::future::Future<Output = Result<(), CotpError>> + Send;
66 fn continue_send(&mut self) -> impl std::future::Future<Output = Result<(), CotpError>> + Send;
67}