Skip to content

Conversation

@itsalfredakku
Copy link
Member

This pull request introduces several improvements focused on enhancing VPN connection reliability, especially for mobile and Android environments. The most significant changes are the addition of TCP keepalive support to prevent NAT timeouts, a new callback mechanism for socket protection (important for Android's VPN routing), and improvements to the packet loop's keepalive logic for more responsive and reliable connections.

Connection reliability and keepalive improvements:

  • Added TCP keepalive support using the socket2 crate, configuring keepalive probes to start after 10 seconds of idle time and repeat every 5 seconds, to help prevent NAT timeouts on mobile networks (Cargo.toml, src/client/connection.rs). [1] [2] [3]
  • Improved the packet loop to send the first keepalive immediately and to send subsequent keepalives based on elapsed time, rather than using a fixed interval, for more timely keepalive messages (src/ffi/client.rs). [1] [2] [3]

Android/FFI integration and socket protection:

  • Introduced a new ProtectSocketCallback in the FFI layer and added it to the SoftEtherCallbacks struct, enabling the client to request protection of sockets from VPN routing (critical for Android's VpnService integration) (src/ffi/callbacks.rs). [1] [2] [3]
  • Implemented a new connect_with_protect method in VpnConnection that invokes the protection callback on the socket before establishing the TLS connection, and updated FFI client code to use this method (src/client/connection.rs, src/ffi/client.rs). [1] [2] [3]
  • Added JNI integration for socket protection, wiring up the callback to the Java-side onProtectSocket method and ensuring it is registered during native client creation (src/ffi/jni.rs). [1] [2]

Other improvements:

  • Added a flush method to ConnectionManager to allow flushing all send-capable connections, improving control over connection state (src/client/multi_connection.rs).
  • Ensured the new callback is properly cloned and handled in the callbacks struct (src/ffi/client.rs).

These changes collectively improve VPN stability, especially on mobile devices, and enable proper integration with Android's VPN APIs.

@itsalfredakku itsalfredakku merged commit 729afb8 into feature/ffi Jan 2, 2026
1 check passed
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.

2 participants