2021-10-26 05:00:31 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/xtls/xray-core/app/observatory"
|
|
|
|
"github.com/xtls/xray-core/common"
|
2021-12-15 00:28:47 +00:00
|
|
|
core "github.com/xtls/xray-core/core"
|
2021-10-26 05:00:31 +00:00
|
|
|
"github.com/xtls/xray-core/features/extension"
|
2022-05-18 07:29:01 +00:00
|
|
|
"google.golang.org/grpc"
|
2021-10-26 05:00:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
sv := &service{v: s}
|
|
|
|
err := s.RequireFeatures(func(Observatory extension.Observatory) {
|
|
|
|
sv.observatory = Observatory
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return sv, nil
|
|
|
|
}))
|
|
|
|
}
|