How luodeb/fluttervpnproxy works
Project Type and Purpose
• This is a Flutter mobile application that integrates deep native code on Android. Its primary purpose is to implement a basic VPN service that utilizes an HTTP proxy – achieved by leveraging Android’s VpnService.
• The README indicates that it’s inspired by an existing VpnProxy project but has been simplified for learning purposes. The focus is on the HTTP proxy functionality using VpnService.
Analyzing the File Structure
• Top-level Directories:
• Android: Contains the native Android project code with Java and Kotlin files.
• lib: Contains Flutter/Dart code, including the main application entry point and the method channel for native communication.
• test: Contains testing code for Flutter widgets.
• In the Android directory:
• The Java packages (under android/app/src/main/java/com/example/my_vpn_plugin) are highly modularized. They separate functionalities into:
• Core components: (e.g., LocalVpnService.java, TcpProxyServer.java, NatSessionManager.java) handling the initialization of the VPN service and the main engine for traffic interception.
• DNS modules: (e.g., DnsProxy.java, DnsPacket.java) dealing with DNS packet manipulation.
• TCP/IP handling: (e.g., TCPHeader.java, UDPHeader.java, IPHeader.java) responsible for processing low-level network protocols.
• Tunnel modules: (e.g., Tunnel.java, RawTunnel.java, TunnelFactory.java, and specifically the HTTP Connect tunnel classes) which provide the mechanism for establishing the VPN tunnel.
• The Kotlin folder (MainActivity.kt) likely provides the bridge with Flutter and hooks into the Android components.
• In the lib folder:
• The Dart files (main.dart, my_vpn_method_channel.dart) suggest that the Flutter layer communicates with the native Android plugin via method channels.