Skip to content

Config: Correctly marshal Address to JSON#4021

Merged
RPRX merged 2 commits intoXTLS:mainfrom
yiguodev:main
Nov 19, 2024
Merged

Config: Correctly marshal Address to JSON#4021
RPRX merged 2 commits intoXTLS:mainfrom
yiguodev:main

Conversation

@yiguodev
Copy link
Collaborator

Because Mr. R has appended new "extra" field to sharing protocol, it's time to use the original config of Xray-core when parsing share links.
This commit contains two modifications.

  1. append "Name" field to "OutboundDetourConfig".
  2. support marshaling "Address".

Maybe we should make more changes in the future, but it is enough currently for VLESS sharing protocol.

@Fangliding
Copy link
Member

@yiguodev
Copy link
Collaborator Author

If we just "Marshal" current conf.Config, "address" will be like the below.

"address": {
    "Address": "example.com"
}

or

"address": {
    "Address": [
        127,
        0,
        0,
        1
    ]
}

They are not same with document. I think they will make client developers confused.

@Fangliding
Copy link
Member

and the "name" ?

@yiguodev
Copy link
Collaborator Author

"name" is used to store descriptive-text. Currently, there is no such field. If not, we must use other field to store it, like "sendThrough", this field will not be used in most cases when developing client. But I think it is better to append a new field "name".

@Fangliding
Copy link
Member

Fangliding commented Nov 17, 2024

No need to add it, config file can be freely added invalid fields, the core will ignore them

@yiguodev
Copy link
Collaborator Author

I see. The first change has been reverted.

@RPRX
Copy link
Member

RPRX commented Nov 18, 2024

虽然 extra 的本意是直接复制 json 而不是 marshal,你是想把内存中的配置导出为 json 吗

话说 2d7b0e8 后 test 炸了,但刚刚没找到炸哪了,@Fangliding

@yiguodev
Copy link
Collaborator Author

目前 libXray 的分享链接解析结果是基于自定义的 XrayJson 构建的。添加 extra 之后,原则上解析结果应该兼容 xhttpSettings 的所有字段。所以不如直接基于 Xray-core 的 conf.Config 来构建结果(已在 libXray 的 dev 分支实现)。
本次 PR 是保证 marshal conf.Config 时,格式和文档保持一致。

@RPRX
Copy link
Member

RPRX commented Nov 18, 2024

懂了,就是说你开发的那个 iOS APP 对 Xray-core 的使用并不像 v2rayN&G 一样是先写 json,而是直接把 core 当 lib 来调用

然后这个 PR 是为了正确地把内存中的配置导出为分享链接,虽然我觉得可以直接把用户写的 extra 给出去

但你要注意行为导入导出 extra 时行为要和 core 保持一致

@yiguodev
Copy link
Collaborator Author

目前的实现,libXray 只负责将 extra 填充到对应的字段上(生成分享链接和解析分享链接均是如此),并不会修改 host,path,mode。具体的导入导出逻辑交给客户端去决定(当然,客户端也可以直接把这些字段都交给 core 来决定)。
libXray 对于 json 的操作只限于根据 json 去生成分享链接和根据分享链接来生成 json 。
这个 PR 只保证 libXray 的结果正确。

我做的 App 也不是直接把 core 当 lib 来调用,对 go 层的调用完全依赖于 libXray。

@RPRX
Copy link
Member

RPRX commented Nov 18, 2024

目前的实现,libXray 只负责将 extra 填充到对应的字段上(生成分享链接和解析分享链接均是如此),并不会修改 host,path,mode。具体的导入导出逻辑交给客户端去决定(当然,客户端也可以直接把这些字段都交给 core 来决定)。

填充到 xhttpSettings 还是 extra?如果是前者,行为就不一致了,具体看 #4000

@yiguodev
Copy link
Collaborator Author

填充到 extra,这次 commit 我完整看过了。

@RPRX RPRX changed the title using original config to parse share links Config: Correctly marshal Address to JSON Nov 19, 2024
@RPRX RPRX merged commit 55e045d into XTLS:main Nov 19, 2024
it2konst pushed a commit to it2konst/gametunnel-core that referenced this pull request Mar 1, 2026
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