diff --git a/app/observatory/command/command.go b/app/observatory/command/command.go new file mode 100644 index 000000000..9049a7591 --- /dev/null +++ b/app/observatory/command/command.go @@ -0,0 +1,39 @@ +package command + +import ( + "context" + core "github.com/v2fly/v2ray-core/v4" + "github.com/v2fly/v2ray-core/v4/app/observatory" + "github.com/v2fly/v2ray-core/v4/common" + "github.com/v2fly/v2ray-core/v4/features/extension" + "google.golang.org/grpc" +) + +type service struct { + UnimplementedObservatoryServiceServer + v *core.Instance + + Observatory extension.Observatory +} + +func (s *service) GetOutboundStatus(ctx context.Context, request *GetOutboundStatusRequest) (*GetOutboundStatusResponse, error) { + resp, err := s.Observatory.GetObservation(ctx) + if err != nil { + return nil, err + } + retdata := resp.(*observatory.ObservationResult) + return &GetOutboundStatusResponse{ + Status: retdata, + }, nil +} + +func (s *service) Register(server *grpc.Server) { + RegisterObservatoryServiceServer(server, s) +} + +func init() { + common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, cfg interface{}) (interface{}, error) { + s := core.MustFromContext(ctx) + return &service{v: s}, nil + })) +} diff --git a/main/distro/all/all.go b/main/distro/all/all.go index 3417b55f9..f2462915c 100644 --- a/main/distro/all/all.go +++ b/main/distro/all/all.go @@ -14,6 +14,9 @@ import ( _ "github.com/v2fly/v2ray-core/v4/app/proxyman/command" _ "github.com/v2fly/v2ray-core/v4/app/stats/command" + // Developer preview services + _ "github.com/v2fly/v2ray-core/v4/app/observatory/command" + // Other optional features. _ "github.com/v2fly/v2ray-core/v4/app/dns" _ "github.com/v2fly/v2ray-core/v4/app/dns/fakedns"