Skip to content

client: mobile: accept config content#411

Merged
kp-antonio-yang merged 6 commits into
mainfrom
feat/mobile-read-conf
May 20, 2026
Merged

client: mobile: accept config content#411
kp-antonio-yang merged 6 commits into
mainfrom
feat/mobile-read-conf

Conversation

@kp-antonio-yang

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

Copy link
Copy Markdown
Contributor

This PR splits the mobile interface commits out from #391, allowing the mobile project to iterate independently without being blocked by the ongoing internal config unification work.

Description

  • Enriched Json Schema
  • Accept config content in mobile
  • Simplified command usage in the dev shell by automatically resolving the script location
  • Rename EventHandlers, which is also an interface in Koltlin
  • Unify auth fields in config (change username field under server to user, and the same field name in global level)
  • remove strong type input for mobile client

Motivation and Context

By decoupling the mobile project from the lightway project, the mobile client can move faster and more easily adopt a dynamic UI.
This PR is split from #391. It is for 3M part of overall flow chart, and the meanwhile the 2M is dropped.
client-initialization-flow

How Has This Been Tested?

Following existing tests.

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)
    • Enriched JSON schema with more details about format, attributes, and examples
    • Modified mobile interface to accept string content in YAML config
    • Rename field user from username in ConnectionConfig (the config of servers)

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

@kp-antonio-yang kp-antonio-yang changed the title Feat/mobile read conf client: mobile: accept config content Apr 30, 2026
@github-actions

github-actions Bot commented Apr 30, 2026

Copy link
Copy Markdown

Code coverage summary for 36bb7e7:

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/keyshare.rs                                 5                 5     0.00%           1                 1     0.00%           5                 5     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                                         280               280     0.00%          31                31     0.00%         174               174     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                                         235                39    83.40%          12                 5    58.33%         173                34    80.35%           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/io/inside/tun.rs                                   82                82     0.00%          12                12     0.00%          60                60     0.00%           0                 0         -
lightway-client/src/io/outside.rs                                      14                14     0.00%           2                 2     0.00%          12                12     0.00%           0                 0         -
lightway-client/src/io/outside/tcp.rs                                  89                89     0.00%          12                12     0.00%          56                56     0.00%           0                 0         -
lightway-client/src/io/outside/udp.rs                                 167               167     0.00%          17                17     0.00%         108               108     0.00%           0                 0         -
lightway-client/src/io/outside/udp_batch_receiver.rs                   61                11    81.97%           6                 1    83.33%          56                12    78.57%           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                                           1246               670    46.23%         102                53    48.04%         835               489    41.44%           0                 0         -
lightway-client/src/main.rs                                           361               361     0.00%          20                20     0.00%         228               228     0.00%           0                 0         -
lightway-client/src/platform/linux/dns_manager.rs                     118                91    22.88%          14                 9    35.71%          87                62    28.74%           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                                      1663               826    50.33%          72                27    62.50%        1173               552    52.94%           0                 0         -
lightway-core/src/connection/builders.rs                              244                46    81.15%          21                 8    61.90%         252                53    78.97%           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/expresslane.rs                            27                11    59.26%           4                 1    75.00%          36                 7    80.56%           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                                          214                51    76.17%          28                11    60.71%         235                64    72.77%           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/keyshare.rs                                           5                 0   100.00%           1                 0   100.00%           5                 0   100.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%          47                37    21.28%           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/tls/mod.rs                                            4                 4     0.00%           1                 1     0.00%           3                 3     0.00%           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                                             438                42    90.41%          29                 1    96.55%         235                12    94.89%           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                          192                 1    99.48%          10                 0   100.00%         110                 0   100.00%           0                 0         -
lightway-core/src/wire/expresslane_data.rs                           1330                69    94.81%          48                 5    89.58%         679                37    94.55%           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/auth.rs                                           273                49    82.05%          22                 6    72.73%         171                28    83.63%           0                 0         -
lightway-server/src/config.rs                                          26                26     0.00%           1                 1     0.00%          44                44     0.00%           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                             339               339     0.00%          40                40     0.00%         294               294     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                             545                 0   100.00%          28                 0   100.00%         257                 0   100.00%           0                 0         -
lightway-server/src/lib.rs                                            292               292     0.00%          15                15     0.00%         194               194     0.00%           0                 0         -
lightway-server/src/main.rs                                           246               246     0.00%          10                10     0.00%         129               129     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%          90                39    56.67%           0                 0         -
uniffi-bindgen/src/uniffi-bindgen.rs                                    3                 3     0.00%           1                 1     0.00%           3                 3     0.00%           0                 0         -
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                               18848              5816    69.14%        1354               542    59.97%       11550              4048    64.95%           0                 0         -

✅ Region coverage 69% passes
✅ Line coverage 64% passes

@kp-antonio-yang kp-antonio-yang force-pushed the feat/mobile-read-conf branch 5 times, most recently from 1a1e2b1 to 2e036f1 Compare April 30, 2026 04:46
@kp-antonio-yang kp-antonio-yang marked this pull request as ready for review April 30, 2026 05:27
@kp-antonio-yang kp-antonio-yang requested a review from a team as a code owner April 30, 2026 05:27
Comment thread lightway-client/src/lib.rs
Comment thread lightway-client/src/config.rs Outdated
Comment on lines +29 to +31
// NOTE for JsonSchema
// - Use feature gate not cfg, such that cli client can generate schema based
// on features for other target if needed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you share more about this? It has always been possible to cross compile to other targets

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A Windows/macOS GUI client can still be cross-compiled from a Linux machine. In that case, the developer would run the client on Linux to generate the JSON schema, which would then be used for the Windows/macOS build. This is just a note to keep in mind for future cross-compilation scenarios.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, but can you share more about why we should use feature gate instead of cfg? Do you mean we shouldn't use Rust's conditional compilation based on platform, but use cargo features for platform specific configs?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeh, cfg with target on functions are good and common in our repo, and I did not against it, so I just add a note on the struct for the #[cfg(feature = ...)]exception.

This is a exceptional note in for the struct to show the JSON schema. Guide a developer need add fields and also considering to generate a schema for other platform.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still unclear to me. Allow me to try to paraphrase:

Prefer `#[cfg(feature = "...")]` over target cfgs (e.g. `cfg(windows)`) 
so CLI on any host can generate schema for other targets via cargo features.

Did I capture what you're trying to say?

@kp-antonio-yang kp-antonio-yang May 14, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theoretically, we could download artifacts from CI, run across multiple platforms, and store the JSON schema as artifacts. In practice however, this does not always hold up:

  • The CLI cannot run on mobile clients, so there is no way to generate the JSON schema from an Android device. Putting the CLI on an Android device purely to produce a schema in the CI flow does not make sense. This also means there is no consistent approach to config and JSON schema generation if some fields are gated by target and others by feature.
  • As mentioned in my earlier example, a fronted full stack developer cannot easily obtain the JSON schema for all platforms from a working feature branch on a fork repo without all platform supported CI.

There will likely be more edge cases along these lines. I believe keeping this simple makes the library significantly easier to use as an open source project, and these small non-ideal tradeoffs are worth tolerating.

The practical approach with the least friction for everyone is:

  1. Feature gates should be on the fields of the config struct.
  2. cfg target attributes are well suited for functions, as mentioned previously — just don't break the 1.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point about not being able to generate a schema on mobile via CLI. But I'm still confused about what you're proposing. Can you see if the following matches your intent? Please feel free to write if none of them captures exactly what you mean

A. Swap one Rust gate for another

  • Replace every occurrence of #[cfg(windows)] with #[cfg(feature = "windows")]
  • That would involve adding a windows Cargo feature. Schema is regenerated per feature combo on the host.

B. Drop the Rust gate on the field; use x-cfg only

  • Target-varying fields stay unconditionally compiled; #[schemars(extend("x-cfg" = "..."))] carries the platform meaning for the UI.
  • One schema covers all platforms, generated once from any host.
  • Cargo features (postquantum, debug, etc.) keep their #[cfg(feature = "...")] gates.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Give the biggest tailoring power to developer via schema from ONE cli

B. Drop the Rust gate on the field of Config; use x-cfg only

  • Target-varying fields stay unconditionally compiled; #[schemars(extend("x-cfg" = "..."))] carries the > platform meaning for the UI.
  • One Schema cover all platforms generated from host which can run cli.
  • Cargo features (postquantum, debug, etc.) keep their #[cfg(feature = "...")] gates.

What is biggest tailoring power?

As an open source project, the greatest power means the lowest barrier — easiest to use, with details that are clear without requiring code changes:

  • No code modifications or special machines needed. The schema can target any platform with the desired feature flags (postquantum, debug, etc.).
  • All details are discoverable from the schema itself without reading source code — conveyed via x-cfg, format, and other JSON schema attributes.

Why does tailoring power matter?

By lowering down the integration efforts, developers can easy to integrate to their tools, then use it, eventually contribute back. It is about interface, so it is consumer facing and it is spec. As a spec of lib or an opensource project here, the consumer is developer.


Off-topic for this PR but related — my mental model of feature vs cfg:

There is a set of functions sharing the same signature, where #[cfg(target)] automatically selects the correct implementation at compile time. This means a Windows developer and an Android developer working in the same project speak almost the same domain language:

struct Config {
   #[cfg(feature="windows")]
   #[schemars(extend("x-cfg" = "windows"))]
   win_only_field: usize,
   
   #[cfg(feature="android")]
   #[schemars(extend("x-cfg" = "android"))]
   android_only_field: usize,
   // ...
}

fn main () {
   let config = Config::load();
   connect(config)
}

#[cfg(window)]
fn connect(config: Config) {
     let Config {
       win_only_field,
       ..
     } = config;
    
    if win_only_filed > 256 {
       // ...
    }
}

#[cfg(android)]
fn connect(config: Config) {
     let Config {
       android_only_field,
       ..
     } = config;
    let tun = Tun::new(android_only_field);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You lost me again. I have 2 questions for you and I would like you to answer them directly:

  1. Does the current comment, prefer #[cfg(feature = "...")] over target cfgs (e.g. cfg(windows)), captures what you meant to say?
  2. What's the primary technical reason behind your comment? You've listed several social reasons above, but I don't think they hold water.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Yes, the preference is #[cfg(feature = "...")] over target-based gates on Config struct fields. Other target gates like #[cfg(windows)] are not touched — this PR is specifically about mobile accepting config content, and other targets are out of scope here. Once other clients start adopting JSON schema, their PRs can modify the fields they need, following the pattern established here and guided by the note.

  2. It is true that there is no cli for mobile, and the mobile target needs a feature gate to generate the schema.

If there is no consensus on whether to prefer #[cfg(feature = "...")] over target gates as a general guide, we can leave that question open, remove the note for now, and let the mobile changes land as they are. We can revisit the broader convention in a follow-up once alignment is reached.

@kp-antonio-yang kp-antonio-yang force-pushed the feat/mobile-read-conf branch 2 times, most recently from 23318d3 to 762bcdd Compare May 11, 2026 03:02
@kp-antonio-yang kp-antonio-yang force-pushed the feat/mobile-read-conf branch from 762bcdd to bcd8d45 Compare May 11, 2026 09:22

@xv-thomas-leong xv-thomas-leong left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more comments

Comment thread lightway-client/src/config.rs
Comment thread lightway-client/src/config.rs Outdated
Comment thread lightway-client/src/config.rs Outdated
Comment on lines +29 to +31
// NOTE for JsonSchema
// - Use feature gate not cfg, such that cli client can generate schema based
// on features for other target if needed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still unclear to me. Allow me to try to paraphrase:

Prefer `#[cfg(feature = "...")]` over target cfgs (e.g. `cfg(windows)`) 
so CLI on any host can generate schema for other targets via cargo features.

Did I capture what you're trying to say?

Comment thread lightway-client/src/mobile.rs Outdated
Comment thread lightway-client/src/mobile.rs Outdated
Comment thread nix/modules/devshells.nix Outdated
@kp-antonio-yang kp-antonio-yang force-pushed the feat/mobile-read-conf branch 2 times, most recently from 975f7bb to c6a6a9f Compare May 12, 2026 10:01
@kp-antonio-yang kp-antonio-yang force-pushed the feat/mobile-read-conf branch from c6a6a9f to f0ee457 Compare May 18, 2026 06:51
@kp-antonio-yang kp-antonio-yang marked this pull request as draft May 18, 2026 07:19
@kp-antonio-yang kp-antonio-yang force-pushed the feat/mobile-read-conf branch from b5d1f89 to a457946 Compare May 18, 2026 08:21
@kp-antonio-yang kp-antonio-yang marked this pull request as ready for review May 18, 2026 08:57
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 textarea format for larger String field
- pass password format for credentials String field
- pass x-cfg information
- add example description 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, and also the OSS client can directly use dynamic UI,
such that the overall maintenance efforts will be less.
The build and clean command in dev shell will always run on project
root.
Remove rust prefix, because we do not have benefit from this, and it
will still good to use in mobile client without issues.
Mobile client now using the same input to start the vpn network, and
reduce the code complexity of client side.
Use the same field name for the user name of auth in global level (Config)
and in connection level (ConnectionConfig)
@kp-antonio-yang kp-antonio-yang force-pushed the feat/mobile-read-conf branch from a457946 to 1abe436 Compare May 20, 2026 03:16
@kp-antonio-yang kp-antonio-yang merged commit e9c607f into main May 20, 2026
22 checks passed
@kp-antonio-yang kp-antonio-yang deleted the feat/mobile-read-conf branch May 20, 2026 13:17
@kp-antonio-yang

kp-antonio-yang commented May 21, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the reviews. Will add document under /doc for this in #433

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