adding recv methods for auth & dissoc & heartbeat
This commit is contained in:
parent
f175aad8e8
commit
ceebbdb200
@ -10,8 +10,6 @@ pub struct Tx {
|
||||
header: Header,
|
||||
}
|
||||
|
||||
pub struct Rx;
|
||||
|
||||
impl Authenticate<side::Tx> {
|
||||
pub(super) fn new(token: [u8; 8]) -> Self {
|
||||
Self {
|
||||
@ -27,3 +25,21 @@ impl Authenticate<side::Tx> {
|
||||
&tx.header
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Rx {
|
||||
token: [u8; 8],
|
||||
}
|
||||
|
||||
impl Authenticate<side::Rx> {
|
||||
pub(super) fn new(token: [u8; 8]) -> Self {
|
||||
Self {
|
||||
inner: Side::Rx(Rx { token }),
|
||||
_marker: side::Rx,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn token(&self) -> &[u8; 8] {
|
||||
let Side::Rx(rx) = &self.inner else { unreachable!() };
|
||||
&rx.token
|
||||
}
|
||||
}
|
||||
|
@ -10,8 +10,6 @@ pub struct Tx {
|
||||
header: Header,
|
||||
}
|
||||
|
||||
pub struct Rx;
|
||||
|
||||
impl Dissociate<side::Tx> {
|
||||
pub(super) fn new(assoc_id: u16) -> Self {
|
||||
Self {
|
||||
@ -27,3 +25,21 @@ impl Dissociate<side::Tx> {
|
||||
&tx.header
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Rx {
|
||||
assoc_id: u16,
|
||||
}
|
||||
|
||||
impl Dissociate<side::Rx> {
|
||||
pub(super) fn new(assoc_id: u16) -> Self {
|
||||
Self {
|
||||
inner: Side::Rx(Rx { assoc_id }),
|
||||
_marker: side::Rx,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn assoc_id(&self) -> &u16 {
|
||||
let Side::Rx(rx) = &self.inner else { unreachable!() };
|
||||
&rx.assoc_id
|
||||
}
|
||||
}
|
||||
|
@ -10,8 +10,6 @@ pub struct Tx {
|
||||
header: Header,
|
||||
}
|
||||
|
||||
pub struct Rx;
|
||||
|
||||
impl Heartbeat<side::Tx> {
|
||||
pub(super) fn new() -> Self {
|
||||
Self {
|
||||
@ -27,3 +25,14 @@ impl Heartbeat<side::Tx> {
|
||||
&tx.header
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Rx;
|
||||
|
||||
impl Heartbeat<side::Rx> {
|
||||
pub(super) fn new() -> Self {
|
||||
Self {
|
||||
inner: Side::Rx(Rx),
|
||||
_marker: side::Rx,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,7 @@
|
||||
use crate::protocol::{Address, Connect as ConnectHeader, Packet as PacketHeader};
|
||||
use crate::protocol::{
|
||||
Address, Authenticate as AuthenticateHeader, Connect as ConnectHeader,
|
||||
Dissociate as DissociateHeader, Heartbeat as HeartbeatHeader, Packet as PacketHeader,
|
||||
};
|
||||
use parking_lot::Mutex;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
@ -45,7 +48,12 @@ where
|
||||
}
|
||||
|
||||
pub fn send_authenticate(&self, token: [u8; 8]) -> Authenticate<side::Tx> {
|
||||
Authenticate::new(token)
|
||||
Authenticate::<side::Tx>::new(token)
|
||||
}
|
||||
|
||||
pub fn recv_authenticate(&self, header: AuthenticateHeader) -> Authenticate<side::Rx> {
|
||||
let (token,) = header.into();
|
||||
Authenticate::<side::Rx>::new(token)
|
||||
}
|
||||
|
||||
pub fn send_connect(&self, addr: Address) -> Connect<side::Tx> {
|
||||
@ -82,11 +90,21 @@ where
|
||||
}
|
||||
|
||||
pub fn send_dissociate(&self, assoc_id: u16) -> Dissociate<side::Tx> {
|
||||
self.udp_sessions.lock().dissociate(assoc_id)
|
||||
self.udp_sessions.lock().send_dissociate(assoc_id)
|
||||
}
|
||||
|
||||
pub fn recv_dissociate(&self, header: DissociateHeader) -> Dissociate<side::Rx> {
|
||||
let (assoc_id,) = header.into();
|
||||
self.udp_sessions.lock().recv_dissociate(assoc_id)
|
||||
}
|
||||
|
||||
pub fn send_heartbeat(&self) -> Heartbeat<side::Tx> {
|
||||
Heartbeat::new()
|
||||
Heartbeat::<side::Tx>::new()
|
||||
}
|
||||
|
||||
pub fn recv_heartbeat(&self, header: HeartbeatHeader) -> Heartbeat<side::Rx> {
|
||||
let () = header.into();
|
||||
Heartbeat::<side::Rx>::new()
|
||||
}
|
||||
|
||||
pub fn task_connect_count(&self) -> usize {
|
||||
@ -174,9 +192,14 @@ where
|
||||
.recv_packet(sessions, assoc_id, pkt_id, frag_total, frag_id, size, addr)
|
||||
}
|
||||
|
||||
fn dissociate(&mut self, assoc_id: u16) -> Dissociate<side::Tx> {
|
||||
fn send_dissociate(&mut self, assoc_id: u16) -> Dissociate<side::Tx> {
|
||||
self.sessions.remove(&assoc_id);
|
||||
Dissociate::new(assoc_id)
|
||||
Dissociate::<side::Tx>::new(assoc_id)
|
||||
}
|
||||
|
||||
fn recv_dissociate(&mut self, assoc_id: u16) -> Dissociate<side::Rx> {
|
||||
self.sessions.remove(&assoc_id);
|
||||
Dissociate::<side::Rx>::new(assoc_id)
|
||||
}
|
||||
|
||||
fn insert<A>(
|
||||
|
@ -18,10 +18,7 @@ pub struct Tx {
|
||||
max_pkt_size: usize,
|
||||
}
|
||||
|
||||
impl<B> Packet<side::Tx, B>
|
||||
where
|
||||
B: AsRef<[u8]>,
|
||||
{
|
||||
impl<B> Packet<side::Tx, B> {
|
||||
pub(super) fn new(assoc_id: u16, pkt_id: u16, addr: Address, max_pkt_size: usize) -> Self {
|
||||
Self {
|
||||
inner: Side::Tx(Tx {
|
||||
|
Loading…
x
Reference in New Issue
Block a user