Skip to content

Commit af7a76d

Browse files
authored
API: Add ListInbounds and ListOutbounds (#4723)
1 parent d44c78b commit af7a76d

File tree

19 files changed

+791
-140
lines changed

19 files changed

+791
-140
lines changed

app/commander/outbound.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/xtls/xray-core/common/errors"
99
"github.com/xtls/xray-core/common/net"
1010
"github.com/xtls/xray-core/common/net/cnc"
11+
"github.com/xtls/xray-core/common/serial"
1112
"github.com/xtls/xray-core/common/signal/done"
1213
"github.com/xtls/xray-core/transport"
1314
)
@@ -108,3 +109,13 @@ func (co *Outbound) Close() error {
108109
co.closed = true
109110
return co.listener.Close()
110111
}
112+
113+
// SenderSettings implements outbound.Handler.
114+
func (co *Outbound) SenderSettings() *serial.TypedMessage {
115+
return nil
116+
}
117+
118+
// ProxySettings implements outbound.Handler.
119+
func (co *Outbound) ProxySettings() *serial.TypedMessage {
120+
return nil
121+
}

app/metrics/outbound.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/xtls/xray-core/common/errors"
99
"github.com/xtls/xray-core/common/net"
1010
"github.com/xtls/xray-core/common/net/cnc"
11+
"github.com/xtls/xray-core/common/serial"
1112
"github.com/xtls/xray-core/common/signal/done"
1213
"github.com/xtls/xray-core/transport"
1314
)
@@ -108,3 +109,13 @@ func (co *Outbound) Close() error {
108109
co.closed = true
109110
return co.listener.Close()
110111
}
112+
113+
// SenderSettings implements outbound.Handler.
114+
func (co *Outbound) SenderSettings() *serial.TypedMessage {
115+
return nil
116+
}
117+
118+
// ProxySettings implements outbound.Handler.
119+
func (co *Outbound) ProxySettings() *serial.TypedMessage {
120+
return nil
121+
}

app/proxyman/command/command.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package command
33
import (
44
"context"
55

6+
"github.com/xtls/xray-core/app/commander"
67
"github.com/xtls/xray-core/common"
78
"github.com/xtls/xray-core/common/errors"
89
"github.com/xtls/xray-core/common/protocol"
@@ -99,6 +100,19 @@ func (s *handlerServer) AlterInbound(ctx context.Context, request *AlterInboundR
99100
return &AlterInboundResponse{}, operation.ApplyInbound(ctx, handler)
100101
}
101102

103+
func (s *handlerServer) ListInbounds(ctx context.Context, request *ListInboundsRequest) (*ListInboundsResponse, error) {
104+
handlers := s.ihm.ListHandlers(ctx)
105+
response := &ListInboundsResponse{}
106+
for _, handler := range handlers {
107+
response.Inbounds = append(response.Inbounds, &core.InboundHandlerConfig{
108+
Tag: handler.Tag(),
109+
ReceiverSettings: handler.ReceiverSettings(),
110+
ProxySettings: handler.ProxySettings(),
111+
})
112+
}
113+
return response, nil
114+
}
115+
102116
func (s *handlerServer) GetInboundUsers(ctx context.Context, request *GetInboundUserRequest) (*GetInboundUserResponse, error) {
103117
handler, err := s.ihm.GetHandler(ctx, request.Tag)
104118
if err != nil {
@@ -164,6 +178,23 @@ func (s *handlerServer) AlterOutbound(ctx context.Context, request *AlterOutboun
164178
return &AlterOutboundResponse{}, operation.ApplyOutbound(ctx, handler)
165179
}
166180

181+
func (s *handlerServer) ListOutbounds(ctx context.Context, request *ListOutboundsRequest) (*ListOutboundsResponse, error) {
182+
handlers := s.ohm.ListHandlers(ctx)
183+
response := &ListOutboundsResponse{}
184+
for _, handler := range handlers {
185+
// Ignore gRPC outbound
186+
if _, ok := handler.(*commander.Outbound); ok {
187+
continue
188+
}
189+
response.Outbounds = append(response.Outbounds, &core.OutboundHandlerConfig{
190+
Tag: handler.Tag(),
191+
SenderSettings: handler.SenderSettings(),
192+
ProxySettings: handler.ProxySettings(),
193+
})
194+
}
195+
return response, nil
196+
}
197+
167198
func (s *handlerServer) mustEmbedUnimplementedHandlerServiceServer() {}
168199

169200
type service struct {

0 commit comments

Comments
 (0)