Skip to content

Allow user to pass SocketProtector callback function for android #1972

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

Closed
wants to merge 4 commits into from

Conversation

zhangsan946
Copy link
Contributor

Allow user to implement the Rust interface which calls the Java VPNService protect method, and to be used to protect the socket fd right after the socket is created on Android.

@zonyitoo
Copy link
Collaborator

Should SocketProtector defined as a trait?

@zhangsan946
Copy link
Contributor Author

@zonyitoo there is no need, when user wanna pass a callback, all he needs to do is to create a SocketProtector with SocketProtector::new(move |fd| callback(fd)) and pass to ConnectOpts. If to be trait, it is expected user needs implement a dedicated struct just for this callback while the former is a much simpler implementation.

@zonyitoo
Copy link
Collaborator

No. Users don't need to really implement this trait if they only has a function, just add a helper function:

fn make_socket_protector<F>(f: F) -> FnSocketProtector<F> ...

which FnSocketProtector<F> is exactly the same as your SocketProtector implementation.

This design could be found in tower, hyper, ... which could allow users who doesn't want to simply call a function, they could make a "Functor" with states.

@zhangsan946 zhangsan946 deleted the android_protect branch June 17, 2025 12:30
@zhangsan946 zhangsan946 restored the android_protect branch June 17, 2025 12:30
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

Successfully merging this pull request may close these issues.

3 participants