Browse Source

Add observatory grpc call

Shelikhoo 4 years ago
parent
commit
a168ff3df6
2 changed files with 42 additions and 0 deletions
  1. 39 0
      app/observatory/command/command.go
  2. 3 0
      main/distro/all/all.go

+ 39 - 0
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
+	}))
+}

+ 3 - 0
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/proxyman/command"
 	_ "github.com/v2fly/v2ray-core/v4/app/stats/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.
 	// Other optional features.
 	_ "github.com/v2fly/v2ray-core/v4/app/dns"
 	_ "github.com/v2fly/v2ray-core/v4/app/dns"
 	_ "github.com/v2fly/v2ray-core/v4/app/dns/fakedns"
 	_ "github.com/v2fly/v2ray-core/v4/app/dns/fakedns"