1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-20 22:45:24 +00:00

Add observatory grpc call

This commit is contained in:
Shelikhoo 2021-03-06 19:09:26 +00:00
parent 3a705cec5a
commit a168ff3df6
No known key found for this signature in database
GPG Key ID: C4D5E79D22B25316
2 changed files with 42 additions and 0 deletions

View File

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

View File

@ -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"