|
|
@@ -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
|
|
|
+ }))
|
|
|
+}
|