Skip to content

Feat/unify initializing flow#391

Draft
kp-antonio-yang wants to merge 23 commits intofeat/general-configsfrom
feat/unify-initializing-flow
Draft

Feat/unify initializing flow#391
kp-antonio-yang wants to merge 23 commits intofeat/general-configsfrom
feat/unify-initializing-flow

Conversation

@kp-antonio-yang
Copy link
Copy Markdown
Contributor

@kp-antonio-yang kp-antonio-yang commented Apr 16, 2026

Description

Mobile and CLI clients currently diverge in their state management, configuration structure, and naming conventions. This PR aligns the two, unifying the network initialization flow and establishing a consistent interface across both clients.

Motivation and Context

  • LightwayClientConnectArgs -> ClientConnectionConfig
  • Collect event handlers as module
  • Collect mobile inside io from mobile
  • Collect mobile outside io from mobile
  • Normalize config when taking server configures
    Following are the context and flow chart.
client-initialization-flow

How Has This Been Tested?

Follow current test cases

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • The correct base branch is being used, if not main

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 16, 2026

Code coverage summary for 329e8c1:

Filename                                                          Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
lightway-app-utils/src/args/cipher.rs                                   5                 5     0.00%           1                 1     0.00%           5                 5     0.00%           0                 0         -
lightway-app-utils/src/args/connection_type.rs                          8                 8     0.00%           2                 2     0.00%           8                 8     0.00%           0                 0         -
lightway-app-utils/src/args/duration.rs                               121                22    81.82%          11                 5    54.55%          64                15    76.56%           0                 0         -
lightway-app-utils/src/args/ip_map.rs                                  27                27     0.00%           5                 5     0.00%          19                19     0.00%           0                 0         -
lightway-app-utils/src/args/logging.rs                                 37                37     0.00%           3                 3     0.00%          31                31     0.00%           0                 0         -
lightway-app-utils/src/args/nonzero_duration.rs                       128                24    81.25%          10                 4    60.00%          68                16    76.47%           0                 0         -
lightway-app-utils/src/connection_ticker.rs                           229                17    92.58%          28                 4    85.71%         126                15    88.10%           0                 0         -
lightway-app-utils/src/dplpmtud_timer.rs                              209                13    93.78%          22                 4    81.82%         117                11    90.60%           0                 0         -
lightway-app-utils/src/event_stream.rs                                 19                 0   100.00%           3                 0   100.00%          11                 0   100.00%           0                 0         -
lightway-app-utils/src/packet_codec.rs                                  2                 2     0.00%           1                 1     0.00%           1                 1     0.00%           0                 0         -
lightway-app-utils/src/sockopt/ip_mtu_discover.rs                      81                81     0.00%           6                 6     0.00%          72                72     0.00%           0                 0         -
lightway-app-utils/src/sockopt/ip_pktinfo.rs                           14                14     0.00%           1                 1     0.00%          16                16     0.00%           0                 0         -
lightway-app-utils/src/tun.rs                                         281               281     0.00%          31                31     0.00%         175               175     0.00%           0                 0         -
lightway-app-utils/src/utils.rs                                        21                21     0.00%           1                 1     0.00%          11                11     0.00%           0                 0         -
lightway-client/src/config.rs                                         357               163    54.34%          15                 8    46.67%         288               145    49.65%           0                 0         -
lightway-client/src/dns_manager.rs                                     18                18     0.00%           4                 4     0.00%          16                16     0.00%           0                 0         -
lightway-client/src/event_handlers.rs                                  58                58     0.00%           3                 3     0.00%          50                50     0.00%           0                 0         -
lightway-client/src/io/inside/tun.rs                                   78                78     0.00%          11                11     0.00%          57                57     0.00%           0                 0         -
lightway-client/src/io/outside.rs                                      28                28     0.00%           4                 4     0.00%          20                20     0.00%           0                 0         -
lightway-client/src/io/outside/tcp.rs                                  79                79     0.00%          11                11     0.00%          48                48     0.00%           0                 0         -
lightway-client/src/io/outside/udp.rs                                 121               121     0.00%          13                13     0.00%          76                76     0.00%           0                 0         -
lightway-client/src/keepalive.rs                                      615                44    92.85%          55                 6    89.09%         330                25    92.42%           0                 0         -
lightway-client/src/lib.rs                                           1133               570    49.69%          91                44    51.65%         738               412    44.17%           0                 0         -
lightway-client/src/main.rs                                           147               147     0.00%          10                10     0.00%          83                83     0.00%           0                 0         -
lightway-client/src/platform/linux/dns_manager.rs                     101                74    26.73%          14                 9    35.71%          77                52    32.47%           0                 0         -
lightway-client/src/platform/linux/dns_manager/direct_file.rs         106                42    60.38%          12                 6    50.00%          65                29    55.38%           0                 0         -
lightway-client/src/platform/linux/dns_manager/resolvconf.rs           61                61     0.00%           8                 8     0.00%          52                52     0.00%           0                 0         -
lightway-client/src/platform/linux/dns_manager/resolvectl.rs           41                41     0.00%           5                 5     0.00%          34                34     0.00%           0                 0         -
lightway-client/src/route_manager.rs                                 1190               212    82.18%          77                 8    89.61%         663               117    82.35%           0                 0         -
lightway-core/src/borrowed_bytesmut.rs                                373                 0   100.00%          24                 0   100.00%         185                 0   100.00%           0                 0         -
lightway-core/src/builder_predicates.rs                                24                12    50.00%           4                 2    50.00%          24                12    50.00%           0                 0         -
lightway-core/src/cipher.rs                                            13                 0   100.00%           2                 0   100.00%          10                 0   100.00%           0                 0         -
lightway-core/src/connection.rs                                      1605               786    51.03%          71                26    63.38%        1129               523    53.68%           0                 0         -
lightway-core/src/connection/builders.rs                              239                46    80.75%          21                 8    61.90%         247                53    78.54%           0                 0         -
lightway-core/src/connection/dplpmtud.rs                             1741                81    95.35%          63                 0   100.00%         830                 7    99.16%           0                 0         -
lightway-core/src/connection/fragment_map.rs                          366                 6    98.36%          25                 0   100.00%         254                 3    98.82%           0                 0         -
lightway-core/src/connection/io_adapter.rs                            526                23    95.63%          34                 5    85.29%         276                21    92.39%           0                 0         -
lightway-core/src/connection/key_update.rs                             34                13    61.76%           5                 0   100.00%          38                19    50.00%           0                 0         -
lightway-core/src/context.rs                                          202                45    77.72%          26                 9    65.38%         213                52    75.59%           0                 0         -
lightway-core/src/context/ip_pool.rs                                    8                 3    62.50%           1                 0   100.00%           5                 0   100.00%           0                 0         -
lightway-core/src/context/server_auth.rs                               32                24    25.00%           4                 3    25.00%          24                20    16.67%           0                 0         -
lightway-core/src/encoding_request_states.rs                            3                 0   100.00%           1                 0   100.00%           3                 0   100.00%           0                 0         -
lightway-core/src/io.rs                                                10                10     0.00%           3                 3     0.00%           9                 9     0.00%           0                 0         -
lightway-core/src/lib.rs                                                9                 0   100.00%           3                 0   100.00%           9                 0   100.00%           0                 0         -
lightway-core/src/metrics.rs                                           51                41    19.61%          21                17    19.05%          48                38    20.83%           0                 0         -
lightway-core/src/packet.rs                                            38                10    73.68%           4                 1    75.00%          30                 6    80.00%           0                 0         -
lightway-core/src/plugin.rs                                           303                13    95.71%          21                 3    85.71%         145                 7    95.17%           0                 0         -
lightway-core/src/utils.rs                                            334                26    92.22%          22                 2    90.91%         165                17    89.70%           0                 0         -
lightway-core/src/version.rs                                           93                 0   100.00%          17                 0   100.00%          82                 0   100.00%           0                 0         -
lightway-core/src/wire.rs                                             435                39    91.03%          28                 0   100.00%         232                 9    96.12%           0                 0         -
lightway-core/src/wire/auth_failure.rs                                 27                 1    96.30%           3                 0   100.00%          17                 0   100.00%           0                 0         -
lightway-core/src/wire/auth_request.rs                                472                12    97.46%          26                 0   100.00%         241                 0   100.00%           0                 0         -
lightway-core/src/wire/auth_success_with_config_ipv4.rs               222                 3    98.65%          11                 0   100.00%         124                 0   100.00%           0                 0         -
lightway-core/src/wire/data.rs                                         51                 1    98.04%           5                 0   100.00%          33                 0   100.00%           0                 0         -
lightway-core/src/wire/data_frag.rs                                   127                 1    99.21%          14                 0   100.00%          80                 0   100.00%           0                 0         -
lightway-core/src/wire/encoding_request.rs                             82                 2    97.56%           6                 0   100.00%          42                 1    97.62%           0                 0         -
lightway-core/src/wire/encoding_response.rs                            82                 2    97.56%           6                 0   100.00%          42                 1    97.62%           0                 0         -
lightway-core/src/wire/expresslane_config.rs                          166                 1    99.40%           8                 0   100.00%          92                 0   100.00%           0                 0         -
lightway-core/src/wire/expresslane_data.rs                            995                50    94.97%          39                 4    89.74%         498                27    94.58%           0                 0         -
lightway-core/src/wire/ping.rs                                         95                 2    97.89%           7                 0   100.00%          59                 0   100.00%           0                 0         -
lightway-core/src/wire/pong.rs                                        109                 2    98.17%           8                 0   100.00%          72                 0   100.00%           0                 0         -
lightway-core/src/wire/server_config.rs                                69                 2    97.10%           4                 0   100.00%          37                 0   100.00%           0                 0         -
lightway-server/src/args.rs                                            27                27     0.00%           1                 1     0.00%          36                36     0.00%           0                 0         -
lightway-server/src/auth.rs                                           273                49    82.05%          22                 6    72.73%         171                28    83.63%           0                 0         -
lightway-server/src/connection.rs                                     137               137     0.00%          11                11     0.00%         110               110     0.00%           0                 0         -
lightway-server/src/connection_manager.rs                             330               330     0.00%          39                39     0.00%         278               278     0.00%           0                 0         -
lightway-server/src/connection_manager/connection_map.rs              407                20    95.09%          21                 1    95.24%         228                 8    96.49%           0                 0         -
lightway-server/src/io/inside/tun.rs                                   44                44     0.00%           9                 9     0.00%          30                30     0.00%           0                 0         -
lightway-server/src/io/outside/tcp.rs                                  90                90     0.00%           9                 9     0.00%          65                65     0.00%           0                 0         -
lightway-server/src/io/outside/udp.rs                                 320               320     0.00%          16                16     0.00%         206               206     0.00%           0                 0         -
lightway-server/src/io/outside/udp/cmsg.rs                            197                53    73.10%          14                 5    64.29%         158                43    72.78%           0                 0         -
lightway-server/src/ip_manager.rs                                     542                50    90.77%          22                 4    81.82%         242                23    90.50%           0                 0         -
lightway-server/src/ip_manager/ip_pool.rs                             540                 0   100.00%          27                 0   100.00%         252                 0   100.00%           0                 0         -
lightway-server/src/lib.rs                                            251               251     0.00%          14                14     0.00%         169               169     0.00%           0                 0         -
lightway-server/src/main.rs                                           228               228     0.00%          10                10     0.00%         122               122     0.00%           0                 0         -
lightway-server/src/metrics.rs                                        254               250     1.57%          85                83     2.35%         215               211     1.86%           0                 0         -
lightway-server/src/statistics.rs                                     132                59    55.30%           8                 4    50.00%          86                35    59.30%           0                 0         -
uniffi-bindgen/src/uniffi-bindgen.rs                                    3                 3     0.00%           1                 1     0.00%           3                 3     0.00%           0                 0         -
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                               18026              5456    69.73%        1304               514    60.58%       10987              3803    65.39%           0                 0         -

✅ Region coverage 69% passes
✅ Line coverage 65% passes

@kp-antonio-yang kp-antonio-yang force-pushed the feat/general-configs branch 6 times, most recently from 0910ae2 to 7de88cf Compare April 20, 2026 06:01
@kp-antonio-yang kp-antonio-yang force-pushed the feat/unify-initializing-flow branch 4 times, most recently from 6648517 to 3cd816c Compare April 21, 2026 07:17
@kp-antonio-yang kp-antonio-yang force-pushed the feat/general-configs branch 2 times, most recently from a23994f to b3a8910 Compare April 21, 2026 08:08
@kp-antonio-yang kp-antonio-yang force-pushed the feat/unify-initializing-flow branch from 3cd816c to 68b221e Compare April 21, 2026 09:20
The `twelf` is not under maintenance it introduced legacy `serde_yaml`(0.8.23).
The latest version is 0.9.34, but it was deprecated in March 2024. Such that
`struct-patch` introduced and decoupled the deseralizer and config patch
function.  The flexible way to overlay configs will be easy and maintainable.
@kp-antonio-yang kp-antonio-yang force-pushed the feat/general-configs branch 2 times, most recently from 0701c9f to 330f52d Compare April 22, 2026 08:07
The docments of cli are from Patch struct, remove the redundant default
values from clap, so we dont need to difference between user inputs and
default values, and all the default valuses are unified from Default
trait.
On platforms other than macOS, there is no strict naming rule for the tun
interface, so lightway is used as the default. On macOS, a simple assertion is
added to catch invalid tun names early, rather than silently NOTE.
Introduce `--generate=<ConfigFormat>` option to lightway-client, it will
be nice for developers to have a full spec to know the all parameters for
integration, and also add a dummy ConfigFormat::JsonSchema with todo! as
our next move.
The `.schema.json` is generated from client side cli,
such that jsonschema can help on integration.

- Add test cases for our customized duration types
- Add test cases for ByteSize
Add config mod, which providing sharing Configs for mobile and cli clients, and unify all the config utils for clients.

- MobileConfig is a small set of Config with less fields adepted to UniFFI, rename from `mobile::LightwayUserSettings`
- MobileConnectionConfig is a small set of ConnectionConfig adepted to UniFFI, renamed from `endpoint::RustEndpointConfig`
- Add apply methods for MobileConfig, MobileConnectionConfig to Config, ConnectionConfig
- Sharing ConnectionConfig for mobile
- Collecting and sharing basic operations(`take_auth`, `load_ca`, ...) of configs for all clients
ExptesslaneState and DeviceNetworkState are also part of interfaces.
Such that we put state.rs a mod.
Rename the VpnConnection and Logger of mobile library for simple,
the Rust prefix is moved
@kp-antonio-yang kp-antonio-yang force-pushed the feat/unify-initializing-flow branch from 41adf70 to e3ab218 Compare April 22, 2026 10:32
Collecting event handling related functions, traits in a module
To unify the config, struct in connecting level, following
struct renamed or merge into a mod, and provide a unified method to
produce the connecting config, ClientConnectionConfig

- Config::into_client_connection_config() -> ClientConnectionConfig
- LightwayClientConnectArgs -> crate::ClientConnectionConfig
- any fields in ClientConnection move from mobile to crate, and it will be
  collected in following steps
@kp-antonio-yang kp-antonio-yang force-pushed the feat/unify-initializing-flow branch from e3ab218 to 643eea5 Compare April 23, 2026 01:32
Keep Config.servers private and provid `take_servers` to produce
normalized ConnectionConfigs with following process

- If ConnectionConfig have no Auth, then copy from Config
- If ConnectionConfig have no CA, then copy from Config
- Load CA content from file, if it is provied by path
With general ClientConfig, mobile and cli client can follow the same
network initialization flow.
To have a unify flow to initialize VPN network, the funcion renamed as
the same cli using.

`mobile::lightway::async_lightway_start(..)` is moved to
`client(ClientConfig, Vec<ClientConnectionConfig>)` with the same
function name and function inputs.
To have a unify flow to initialize VPN network, the funcion renamed as
the same cli using.
`mobile::lightway::lightway_client_connect(..)` is moved to
`connect(ClientConfig, ClientConnectionConfig)` with the same
function name and function inputs.
mv MobileInsideIo, TunnelState to io::inside, such all the inside
implemeation collected in a same place.
To unify the initialization, the plugins are defined by
ClientConnectionConfig in mobile and cli clients.
mv OutsideSocket, build functions, task runner functions to io::outside,
such that all the outside impl collected in a same place.
Move mobile::LightwayConnection to ClientConnection cfg gate, such that
the network initialization of cli and mobile are the same.
Error is also an interface of lib, such that we expose it as a mod.
Such that a developer using lightway-client crate will easy to debug and
follow by reading the source code.
Because the type checking is working on ClientConnectionConfig, we can
use loose type of server_ip field for MobileConnectionConfig
Pass field meta information of json schema to client, such that
mobile clients can based on the meta information to show the
field really works in mobile client

- pass textview for larger String field
- pass x-cfg information
- add example for durations and socket address fields
By adding a config_content input, the mobile will easy to apply yaml configs
as the same as cli client using, such that we can easy to treat all clients
in a unify way.
The build and clean command in dev shell will always run on project
root.
@kp-antonio-yang kp-antonio-yang force-pushed the feat/unify-initializing-flow branch from 643eea5 to fe92673 Compare April 23, 2026 03:16
@kp-antonio-yang kp-antonio-yang force-pushed the feat/general-configs branch 8 times, most recently from 7737cc1 to 5294904 Compare April 24, 2026 08:06
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.

1 participant