Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于输出 json 结构的顺序问题 #38

Open
love4taylor opened this issue Apr 10, 2024 · 5 comments
Open

关于输出 json 结构的顺序问题 #38

love4taylor opened this issue Apr 10, 2024 · 5 comments

Comments

@love4taylor
Copy link
Contributor

能否保持输入模版的结构顺序

@xmdhs
Copy link
Owner

xmdhs commented Apr 11, 2024

现在应该是保持了模板的顺序

@love4taylor
Copy link
Contributor Author

我这没变化,还是乱的

input

{
  "log": {
    "disabled": false,
    "level": "info",
    "timestamp": false
  },
  "dns": {
    "servers": [
      {
        "tag": "novaxns",
        "address": "",
        "detour": "direct"
      },
      {
        "address": "rcode://success",
        "tag": "block"
      }
    ],
    "rules": [
      {
        "domain_suffix": [
          ".arpa.",
          ".arpa"
        ],
        "server": "block"
      }
    ]
  },

......

output

{
    "dns": {
        "rules": [
            {
                "domain_suffix": [
                    ".arpa.",
                    ".arpa"
                ],
                "server": "block"
            }
        ],
        "servers": [
            {
                "address": "",
                "detour": "direct",
                "tag": "novaxns"
            },
            {
                "address": "rcode://success",
                "tag": "block"
            }
        ]
    },
    "experimental": {
        "cache_file": {
            "enabled": true
        },
        "clash_api": {
            "external_controller": "127.0.0.1:9090",
            "secret": ""
        }
    },

......

@xmdhs
Copy link
Owner

xmdhs commented Apr 11, 2024

Go 的 map 就是乱序的,所以不太好保持模板的顺序。但是规则之类的是有顺序的。

@alan16742
Copy link

由于go默认排序这个原因,导致默认出站可能是无效的服务器

  • 配置模板
"outbounds": [
{
    "tag": "select",
    "type": "selector",
    "default": "urltest",
    "outbounds": [
    "urltest",
    "HongKong"
    ]
},
{
    "tag": "HongKong",
    "type": "urltest",
    "outbounds": ["include: 🇭🇰|HK|hk|香港|港|HongKong"]
},
{
    "tag": "urltest",
    "type": "urltest",
    "outbounds": ["exclude: 需要包含所有"]
}
],
  • 转换后的配置
"outbounds": [
    {
        "password": "1234",
        "server": "test.com",
        "server_port": 1234,
        "tag": "无效节点香港",
        "type": "shadowsocks",
        "method": "aes-256-gcm"
    },
    {
        "password": "1234",
        "server": "test.com",
        "server_port": 1234,
        "tag": "有效节点香港",
        "type": "shadowsocks",
        "method": "aes-256-gcm"
    },
    {
        "tag": "direct",
        "type": "direct"
    },
    {
        "tag": "block",
        "type": "block"
    },
    {
        "tag": "dns-out",
        "type": "dns"
    },
    {
        "default": "urltest",
        "outbounds": [
            "urltest",
            "HongKong"
        ],
        "tag": "select",
        "type": "selector"
    },
    {
        "outbounds": [
            "无效节点香港",
            "有效节点香港"
        ],
        "tag": "HongKong",
        "type": "urltest"
    },
    {
        "outbounds": [
            "无效节点香港",
            "有效节点香港"
        ],
        "tag": "urltest",
        "type": "urltest"
    }
]

在经由前面的模板转换后,所有的节点排序排在了节点集合之前,导致第一个节点成为了默认节点,后续的出站路由表匹配完所有规则后没有命中就会走 无效节点香港 出站,但是由于这是个无效节点,所以实际上就是无法访问国外网站。

  • 修改建议二选一
  1. 加上 final 指定 出站服务器
    "route": {
        "auto_detect_interface": true,
		"final": "select",
		...
		}
  1. 加个条件将模版中的集合置于各节点前,成为默认出站
    {
        "default": "urltest",
        "outbounds": [
            "urltest",
            "HongKong"
        ],
        "tag": "select",
        "type": "selector"
    },
    {
        "password": "1234",
        "server": "test.com",
        "server_port": 1234,
        "tag": "无效节点香港",
        "type": "shadowsocks",
        "method": "aes-256-gcm"
    },
  • 附加
    这种状况在 禁用默认生成的 urltest 和 selector 时出现,禁用这个往往是想要个性化选择节点,如果不禁用就会出现下面这种 个性化配置无法启用 的情况,禁用则会导致 默认出站可能是无效的服务器 的情况。
    "outbounds": [
{
    "tag": "selector",
    "type": "selector",
    "outbounds": [
        "include: 新加坡",
        "exclude: 香港"
    ]
}
],
---
        {
            "tag": "select",
            "type": "selector",
            "default": "urltest",
            "outbounds": [
                "urltest",
                "📢 TG新频道 msclminfo",
                "🇭🇰 高级 香港 1",
                "🇭🇰 高级 香港 2 新入口A",
                "🇭🇰 高级 香港 2 新入口B",
                "🇭🇰 高级 香港 3",
                "🇭🇰 高级 香港 4 新入口A",
                "🇭🇰 高级 香港 4 新入口B",
                "🇭🇰 标准 香港 5",
                "🇭🇰 标准 香港 6",
                "🇸🇬 高级 新加坡 1",
                "🇸🇬 高级 新加坡 2 新入口A",
                "🇸🇬 高级 新加坡 2 新入口B",
                "🇸🇬 标准 新加坡 3",
                "🇸🇬 标准 新加坡 5",
                "🇯🇵 高级 日本 1 A",
                "🇯🇵 高级 日本 1 新入口A",
                "🇯🇵 高级 日本 1 新入口B",
                "🇯🇵 标准 日本 2",
                "🇯🇵 标准 日本 3",
                "🇯🇵 标准 日本 4",
                "🇺🇸 高级 美国 1",
                "🇺🇸 标准 美国 2 新入口A",
                "🇺🇸 标准 美国 3",
                "🇺🇸 标准 美国 4 新入口B",
                "🇰🇷 韩国 C",
                "🇮🇳 印度 [新节点]",
                "🇬🇧 标准 英国",
                "🇸🇪 瑞典 [新节点]",
                "🇩🇪 德国 [新节点]",
                "🇦🇺 澳大利亚 [新节点]",
                "🇪🇸 西班牙 [新节点]",
                "📢 请常更新订阅-0806更新"
            ]
        },

xmdhs added a commit that referenced this issue Aug 8, 2024
@xmdhs
Copy link
Owner

xmdhs commented Aug 8, 2024

outbounds 一直都是有序的,只是规则不太一样。

现在在禁用默认生成的 urltest 和 selector后,模板中添加的节点会在第一位。

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

No branches or pull requests

3 participants