Xray-core icon indicating copy to clipboard operation
Xray-core copied to clipboard

feat(api): Add ListInbounds and ListOutbounds to the gRPC API

Open gsergey418 opened this issue 7 months ago • 4 comments

Fixes #2745. Add the ListInbounds and ListOutbounds methods to the gRPC HandlerService and write the respective CLI commands lsi and lso.

gsergey418 avatar May 13 '25 14:05 gsergey418

Got it to work, added both methods, wrote a test and added the corresponding CLI commands. Expaneded two interfaces marked as xray:api:stable: features/inbound and features/outbound. May not be the best solution as I'm not very familiar with the codebase, so feel free to correct me. Currently it works like this:

$ ./xray api lsi -s localhost:1081
{
    "inbounds": [
        {
            "proxySettings": {
                "_TypedMessage_": "xray.proxy.http.ServerConfig",
                "accounts": {
                    "gsergey418": "REDACTED"
                }
            },
            "receiverSettings": {
                "_TypedMessage_": "xray.app.proxyman.ReceiverConfig",
                "listen": "127.0.0.1",
                "portList": 1080
            },
            "tag": "http"
        }
    ]
}

$ ./xray api lso -s localhost:1081
{
    "outbounds": [
        {
            "proxySettings": {
                "_TypedMessage_": "xray.proxy.freedom.Config"
            },
            "senderSettings": {
                "_TypedMessage_": "xray.app.proxyman.SenderConfig"
            },
            "tag": "direct"
        },
        {
            "proxySettings": {
                "_TypedMessage_": "xray.proxy.vless.outbound.Config",
                "vnext": [
                    {
                        "address": "REDACTED",
                        "port": 10086,
                        "user": [
                            {
                                "account": {
                                    "_TypedMessage_": "xray.proxy.vless.Account",
                                    "encryption": "none",
                                    "id": "REDACTED"
                                }
                            }
                        ]
                    }
                ]
            },
            "senderSettings": {
                "_TypedMessage_": "xray.app.proxyman.SenderConfig",
                "streamSettings": {
                    "protocolName": "tcp",
                    "socketSettings": {}
                }
            },
            "tag": "proxy"
        },
        {
            "proxySettings": {
                "_TypedMessage_": "xray.proxy.blackhole.Config"
            },
            "senderSettings": {
                "_TypedMessage_": "xray.app.proxyman.SenderConfig"
            },
            "tag": "block"
        }
    ]
}

gsergey418 avatar May 14 '25 13:05 gsergey418

Opened a PR to the documentation. Similar changes needed in Chinese version and https://github.com/XTLS/Xray-API-documents.

gsergey418 avatar May 14 '25 13:05 gsergey418

Could you set protoc and protoc-gen-go to the same version as in the core?

Fangliding avatar May 14 '25 14:05 Fangliding

@Fangliding Done

gsergey418 avatar May 14 '25 14:05 gsergey418

看起来不会损坏现有功能,先合了,感谢 PR

RPRX avatar Jun 06 '25 01:06 RPRX

Got it to work, added both methods, wrote a test and added the corresponding CLI commands. Expaneded two interfaces marked as xray:api:stable: features/inbound and features/outbound. May not be the best solution as I'm not very familiar with the codebase, so feel free to correct me. Currently it works like this:

$ ./xray api lsi -s localhost:1081
{
    "inbounds": [
        {
            "proxySettings": {
                "_TypedMessage_": "xray.proxy.http.ServerConfig",
                "accounts": {
                    "gsergey418": "REDACTED"
                }
            },
            "receiverSettings": {
                "_TypedMessage_": "xray.app.proxyman.ReceiverConfig",
                "listen": "127.0.0.1",
                "portList": 1080
            },
            "tag": "http"
        }
    ]
}

$ ./xray api lso -s localhost:1081
{
    "outbounds": [
        {
            "proxySettings": {
                "_TypedMessage_": "xray.proxy.freedom.Config"
            },
            "senderSettings": {
                "_TypedMessage_": "xray.app.proxyman.SenderConfig"
            },
            "tag": "direct"
        },
        {
            "proxySettings": {
                "_TypedMessage_": "xray.proxy.vless.outbound.Config",
                "vnext": [
                    {
                        "address": "REDACTED",
                        "port": 10086,
                        "user": [
                            {
                                "account": {
                                    "_TypedMessage_": "xray.proxy.vless.Account",
                                    "encryption": "none",
                                    "id": "REDACTED"
                                }
                            }
                        ]
                    }
                ]
            },
            "senderSettings": {
                "_TypedMessage_": "xray.app.proxyman.SenderConfig",
                "streamSettings": {
                    "protocolName": "tcp",
                    "socketSettings": {}
                }
            },
            "tag": "proxy"
        },
        {
            "proxySettings": {
                "_TypedMessage_": "xray.proxy.blackhole.Config"
            },
            "senderSettings": {
                "_TypedMessage_": "xray.app.proxyman.SenderConfig"
            },
            "tag": "block"
        }
    ]
}

Hi @gsergey418!

As i see from your example CLI response ./xray api lsi -s localhost:1081 also return list of users of inbounds? Are you sure that it is good option? What if inbound will have 50k+ users?

Maybe there should be an option to just get list of inbounds without users?

kastov avatar Jun 07 '25 14:06 kastov