Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: support modifying datagram to allow customizable protocol header #34

Open
oyyd opened this issue Jan 14, 2024 · 1 comment

Comments

@oyyd
Copy link

oyyd commented Jan 14, 2024

Firstly, thanks for the great repository!

Currently, tokio_kcp can't communicate with kcp-go because: beside kcp, kcp-go also adds other features that change its protocol header, e.g. crypto, crc, fec. It should be emphasized that these features are kcp-go specific.

Though, being compatible with kcp-go might be not the goal of tokio_kcp, I believe adding the ability for users to modify the datagram to support their own headers makes it possbile. It would also extend the potential usage of tokio_kcp.

@oyyd
Copy link
Author

oyyd commented Jan 14, 2024

For example, define a trait like below for users to impl and use them in tokio_kcp:

pub trait ProtocolExtender {
    // tokio_kcp needs this beforehand when caculate mtu
    fn header_len() -> u16;

    // When receive udp datagram, firstly call recv() to modify the data, then pass it to kcp.
    fn recv(&mut self, data: Vec<u8>) -> Vec<u8>;

    // When kcp tries to send data, firstly call send() to modify the data, then pass it to udp socket.
    fn send(&mut self, data: Vec<u8>) -> Vec<u8>;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant