First Commmit
This commit is contained in:
82
experimental/v2rayapi/server.go
Normal file
82
experimental/v2rayapi/server.go
Normal file
@@ -0,0 +1,82 @@
|
||||
package v2rayapi
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"net/http"
|
||||
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
"github.com/sagernet/sing-box/experimental"
|
||||
"github.com/sagernet/sing-box/log"
|
||||
"github.com/sagernet/sing-box/option"
|
||||
"github.com/sagernet/sing/common"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
)
|
||||
|
||||
func init() {
|
||||
experimental.RegisterV2RayServerConstructor(NewServer)
|
||||
}
|
||||
|
||||
var _ adapter.V2RayServer = (*Server)(nil)
|
||||
|
||||
type Server struct {
|
||||
logger log.Logger
|
||||
listen string
|
||||
tcpListener net.Listener
|
||||
grpcServer *grpc.Server
|
||||
statsService *StatsService
|
||||
}
|
||||
|
||||
func NewServer(logger log.Logger, options option.V2RayAPIOptions) (adapter.V2RayServer, error) {
|
||||
grpcServer := grpc.NewServer(grpc.Creds(insecure.NewCredentials()))
|
||||
statsService := NewStatsService(common.PtrValueOrDefault(options.Stats))
|
||||
if statsService != nil {
|
||||
RegisterStatsServiceServer(grpcServer, statsService)
|
||||
}
|
||||
server := &Server{
|
||||
logger: logger,
|
||||
listen: options.Listen,
|
||||
grpcServer: grpcServer,
|
||||
statsService: statsService,
|
||||
}
|
||||
return server, nil
|
||||
}
|
||||
|
||||
func (s *Server) Name() string {
|
||||
return "v2ray server"
|
||||
}
|
||||
|
||||
func (s *Server) Start(stage adapter.StartStage) error {
|
||||
if stage != adapter.StartStatePostStart {
|
||||
return nil
|
||||
}
|
||||
listener, err := net.Listen("tcp", s.listen)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.logger.Info("grpc server started at ", listener.Addr())
|
||||
s.tcpListener = listener
|
||||
go func() {
|
||||
err = s.grpcServer.Serve(listener)
|
||||
if err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||
s.logger.Error(err)
|
||||
}
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) Close() error {
|
||||
if s.grpcServer != nil {
|
||||
s.grpcServer.Stop()
|
||||
}
|
||||
return common.Close(
|
||||
common.PtrOrNil(s.grpcServer),
|
||||
s.tcpListener,
|
||||
)
|
||||
}
|
||||
|
||||
func (s *Server) StatsService() adapter.ConnectionTracker {
|
||||
return s.statsService
|
||||
}
|
||||
222
experimental/v2rayapi/stats.go
Normal file
222
experimental/v2rayapi/stats.go
Normal file
@@ -0,0 +1,222 @@
|
||||
package v2rayapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
"github.com/sagernet/sing-box/option"
|
||||
"github.com/sagernet/sing/common/bufio"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
N "github.com/sagernet/sing/common/network"
|
||||
)
|
||||
|
||||
func init() {
|
||||
StatsService_ServiceDesc.ServiceName = "v2ray.core.app.stats.command.StatsService"
|
||||
}
|
||||
|
||||
var (
|
||||
_ adapter.ConnectionTracker = (*StatsService)(nil)
|
||||
_ StatsServiceServer = (*StatsService)(nil)
|
||||
)
|
||||
|
||||
type StatsService struct {
|
||||
createdAt time.Time
|
||||
inbounds map[string]bool
|
||||
outbounds map[string]bool
|
||||
users map[string]bool
|
||||
access sync.Mutex
|
||||
counters map[string]*atomic.Int64
|
||||
}
|
||||
|
||||
func NewStatsService(options option.V2RayStatsServiceOptions) *StatsService {
|
||||
if !options.Enabled {
|
||||
return nil
|
||||
}
|
||||
inbounds := make(map[string]bool)
|
||||
outbounds := make(map[string]bool)
|
||||
users := make(map[string]bool)
|
||||
for _, inbound := range options.Inbounds {
|
||||
inbounds[inbound] = true
|
||||
}
|
||||
for _, outbound := range options.Outbounds {
|
||||
outbounds[outbound] = true
|
||||
}
|
||||
for _, user := range options.Users {
|
||||
users[user] = true
|
||||
}
|
||||
return &StatsService{
|
||||
createdAt: time.Now(),
|
||||
inbounds: inbounds,
|
||||
outbounds: outbounds,
|
||||
users: users,
|
||||
counters: make(map[string]*atomic.Int64),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *StatsService) RoutedConnection(ctx context.Context, conn net.Conn, metadata adapter.InboundContext, matchedRule adapter.Rule, matchOutbound adapter.Outbound) net.Conn {
|
||||
inbound := metadata.Inbound
|
||||
user := metadata.User
|
||||
outbound := matchOutbound.Tag()
|
||||
var readCounter []*atomic.Int64
|
||||
var writeCounter []*atomic.Int64
|
||||
countInbound := inbound != "" && s.inbounds[inbound]
|
||||
countOutbound := outbound != "" && s.outbounds[outbound]
|
||||
countUser := user != "" && s.users[user]
|
||||
if !countInbound && !countOutbound && !countUser {
|
||||
return conn
|
||||
}
|
||||
s.access.Lock()
|
||||
if countInbound {
|
||||
readCounter = append(readCounter, s.loadOrCreateCounter("inbound>>>"+inbound+">>>traffic>>>uplink"))
|
||||
writeCounter = append(writeCounter, s.loadOrCreateCounter("inbound>>>"+inbound+">>>traffic>>>downlink"))
|
||||
}
|
||||
if countOutbound {
|
||||
readCounter = append(readCounter, s.loadOrCreateCounter("outbound>>>"+outbound+">>>traffic>>>uplink"))
|
||||
writeCounter = append(writeCounter, s.loadOrCreateCounter("outbound>>>"+outbound+">>>traffic>>>downlink"))
|
||||
}
|
||||
if countUser {
|
||||
readCounter = append(readCounter, s.loadOrCreateCounter("user>>>"+user+">>>traffic>>>uplink"))
|
||||
writeCounter = append(writeCounter, s.loadOrCreateCounter("user>>>"+user+">>>traffic>>>downlink"))
|
||||
}
|
||||
s.access.Unlock()
|
||||
return bufio.NewInt64CounterConn(conn, readCounter, writeCounter)
|
||||
}
|
||||
|
||||
func (s *StatsService) RoutedPacketConnection(ctx context.Context, conn N.PacketConn, metadata adapter.InboundContext, matchedRule adapter.Rule, matchOutbound adapter.Outbound) N.PacketConn {
|
||||
inbound := metadata.Inbound
|
||||
user := metadata.User
|
||||
outbound := matchOutbound.Tag()
|
||||
var readCounter []*atomic.Int64
|
||||
var writeCounter []*atomic.Int64
|
||||
countInbound := inbound != "" && s.inbounds[inbound]
|
||||
countOutbound := outbound != "" && s.outbounds[outbound]
|
||||
countUser := user != "" && s.users[user]
|
||||
if !countInbound && !countOutbound && !countUser {
|
||||
return conn
|
||||
}
|
||||
s.access.Lock()
|
||||
if countInbound {
|
||||
readCounter = append(readCounter, s.loadOrCreateCounter("inbound>>>"+inbound+">>>traffic>>>uplink"))
|
||||
writeCounter = append(writeCounter, s.loadOrCreateCounter("inbound>>>"+inbound+">>>traffic>>>downlink"))
|
||||
}
|
||||
if countOutbound {
|
||||
readCounter = append(readCounter, s.loadOrCreateCounter("outbound>>>"+outbound+">>>traffic>>>uplink"))
|
||||
writeCounter = append(writeCounter, s.loadOrCreateCounter("outbound>>>"+outbound+">>>traffic>>>downlink"))
|
||||
}
|
||||
if countUser {
|
||||
readCounter = append(readCounter, s.loadOrCreateCounter("user>>>"+user+">>>traffic>>>uplink"))
|
||||
writeCounter = append(writeCounter, s.loadOrCreateCounter("user>>>"+user+">>>traffic>>>downlink"))
|
||||
}
|
||||
s.access.Unlock()
|
||||
return bufio.NewInt64CounterPacketConn(conn, readCounter, nil, writeCounter, nil)
|
||||
}
|
||||
|
||||
func (s *StatsService) GetStats(ctx context.Context, request *GetStatsRequest) (*GetStatsResponse, error) {
|
||||
s.access.Lock()
|
||||
counter, loaded := s.counters[request.Name]
|
||||
s.access.Unlock()
|
||||
if !loaded {
|
||||
return nil, E.New(request.Name, " not found.")
|
||||
}
|
||||
var value int64
|
||||
if request.Reset_ {
|
||||
value = counter.Swap(0)
|
||||
} else {
|
||||
value = counter.Load()
|
||||
}
|
||||
return &GetStatsResponse{Stat: &Stat{Name: request.Name, Value: value}}, nil
|
||||
}
|
||||
|
||||
func (s *StatsService) QueryStats(ctx context.Context, request *QueryStatsRequest) (*QueryStatsResponse, error) {
|
||||
var response QueryStatsResponse
|
||||
s.access.Lock()
|
||||
defer s.access.Unlock()
|
||||
if len(request.Patterns) == 0 {
|
||||
for name, counter := range s.counters {
|
||||
var value int64
|
||||
if request.Reset_ {
|
||||
value = counter.Swap(0)
|
||||
} else {
|
||||
value = counter.Load()
|
||||
}
|
||||
response.Stat = append(response.Stat, &Stat{Name: name, Value: value})
|
||||
}
|
||||
} else if request.Regexp {
|
||||
matchers := make([]*regexp.Regexp, 0, len(request.Patterns))
|
||||
for _, pattern := range request.Patterns {
|
||||
matcher, err := regexp.Compile(pattern)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
matchers = append(matchers, matcher)
|
||||
}
|
||||
for name, counter := range s.counters {
|
||||
for _, matcher := range matchers {
|
||||
if matcher.MatchString(name) {
|
||||
var value int64
|
||||
if request.Reset_ {
|
||||
value = counter.Swap(0)
|
||||
} else {
|
||||
value = counter.Load()
|
||||
}
|
||||
response.Stat = append(response.Stat, &Stat{Name: name, Value: value})
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for name, counter := range s.counters {
|
||||
for _, matcher := range request.Patterns {
|
||||
if strings.Contains(name, matcher) {
|
||||
var value int64
|
||||
if request.Reset_ {
|
||||
value = counter.Swap(0)
|
||||
} else {
|
||||
value = counter.Load()
|
||||
}
|
||||
response.Stat = append(response.Stat, &Stat{Name: name, Value: value})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return &response, nil
|
||||
}
|
||||
|
||||
func (s *StatsService) GetSysStats(ctx context.Context, request *SysStatsRequest) (*SysStatsResponse, error) {
|
||||
var rtm runtime.MemStats
|
||||
runtime.ReadMemStats(&rtm)
|
||||
response := &SysStatsResponse{
|
||||
Uptime: uint32(time.Since(s.createdAt).Seconds()),
|
||||
NumGoroutine: uint32(runtime.NumGoroutine()),
|
||||
Alloc: rtm.Alloc,
|
||||
TotalAlloc: rtm.TotalAlloc,
|
||||
Sys: rtm.Sys,
|
||||
Mallocs: rtm.Mallocs,
|
||||
Frees: rtm.Frees,
|
||||
LiveObjects: rtm.Mallocs - rtm.Frees,
|
||||
NumGC: rtm.NumGC,
|
||||
PauseTotalNs: rtm.PauseTotalNs,
|
||||
}
|
||||
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *StatsService) mustEmbedUnimplementedStatsServiceServer() {
|
||||
}
|
||||
|
||||
//nolint:staticcheck
|
||||
func (s *StatsService) loadOrCreateCounter(name string) *atomic.Int64 {
|
||||
counter, loaded := s.counters[name]
|
||||
if loaded {
|
||||
return counter
|
||||
}
|
||||
counter = &atomic.Int64{}
|
||||
s.counters[name] = counter
|
||||
return counter
|
||||
}
|
||||
538
experimental/v2rayapi/stats.pb.go
Normal file
538
experimental/v2rayapi/stats.pb.go
Normal file
@@ -0,0 +1,538 @@
|
||||
package v2rayapi
|
||||
|
||||
import (
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
unsafe "unsafe"
|
||||
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
)
|
||||
|
||||
const (
|
||||
// Verify that this generated code is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
type GetStatsRequest struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
// Name of the stat counter.
|
||||
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
|
||||
// Whether or not to reset the counter to fetching its value.
|
||||
Reset_ bool `protobuf:"varint,2,opt,name=reset,proto3" json:"reset,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *GetStatsRequest) Reset() {
|
||||
*x = GetStatsRequest{}
|
||||
mi := &file_experimental_v2rayapi_stats_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *GetStatsRequest) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*GetStatsRequest) ProtoMessage() {}
|
||||
|
||||
func (x *GetStatsRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_experimental_v2rayapi_stats_proto_msgTypes[0]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use GetStatsRequest.ProtoReflect.Descriptor instead.
|
||||
func (*GetStatsRequest) Descriptor() ([]byte, []int) {
|
||||
return file_experimental_v2rayapi_stats_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *GetStatsRequest) GetName() string {
|
||||
if x != nil {
|
||||
return x.Name
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *GetStatsRequest) GetReset_() bool {
|
||||
if x != nil {
|
||||
return x.Reset_
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type Stat struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
|
||||
Value int64 `protobuf:"varint,2,opt,name=value,proto3" json:"value,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *Stat) Reset() {
|
||||
*x = Stat{}
|
||||
mi := &file_experimental_v2rayapi_stats_proto_msgTypes[1]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *Stat) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*Stat) ProtoMessage() {}
|
||||
|
||||
func (x *Stat) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_experimental_v2rayapi_stats_proto_msgTypes[1]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use Stat.ProtoReflect.Descriptor instead.
|
||||
func (*Stat) Descriptor() ([]byte, []int) {
|
||||
return file_experimental_v2rayapi_stats_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
func (x *Stat) GetName() string {
|
||||
if x != nil {
|
||||
return x.Name
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Stat) GetValue() int64 {
|
||||
if x != nil {
|
||||
return x.Value
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type GetStatsResponse struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Stat *Stat `protobuf:"bytes,1,opt,name=stat,proto3" json:"stat,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *GetStatsResponse) Reset() {
|
||||
*x = GetStatsResponse{}
|
||||
mi := &file_experimental_v2rayapi_stats_proto_msgTypes[2]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *GetStatsResponse) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*GetStatsResponse) ProtoMessage() {}
|
||||
|
||||
func (x *GetStatsResponse) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_experimental_v2rayapi_stats_proto_msgTypes[2]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use GetStatsResponse.ProtoReflect.Descriptor instead.
|
||||
func (*GetStatsResponse) Descriptor() ([]byte, []int) {
|
||||
return file_experimental_v2rayapi_stats_proto_rawDescGZIP(), []int{2}
|
||||
}
|
||||
|
||||
func (x *GetStatsResponse) GetStat() *Stat {
|
||||
if x != nil {
|
||||
return x.Stat
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type QueryStatsRequest struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
// Deprecated, use Patterns instead
|
||||
Pattern string `protobuf:"bytes,1,opt,name=pattern,proto3" json:"pattern,omitempty"`
|
||||
Reset_ bool `protobuf:"varint,2,opt,name=reset,proto3" json:"reset,omitempty"`
|
||||
Patterns []string `protobuf:"bytes,3,rep,name=patterns,proto3" json:"patterns,omitempty"`
|
||||
Regexp bool `protobuf:"varint,4,opt,name=regexp,proto3" json:"regexp,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *QueryStatsRequest) Reset() {
|
||||
*x = QueryStatsRequest{}
|
||||
mi := &file_experimental_v2rayapi_stats_proto_msgTypes[3]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *QueryStatsRequest) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*QueryStatsRequest) ProtoMessage() {}
|
||||
|
||||
func (x *QueryStatsRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_experimental_v2rayapi_stats_proto_msgTypes[3]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use QueryStatsRequest.ProtoReflect.Descriptor instead.
|
||||
func (*QueryStatsRequest) Descriptor() ([]byte, []int) {
|
||||
return file_experimental_v2rayapi_stats_proto_rawDescGZIP(), []int{3}
|
||||
}
|
||||
|
||||
func (x *QueryStatsRequest) GetPattern() string {
|
||||
if x != nil {
|
||||
return x.Pattern
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *QueryStatsRequest) GetReset_() bool {
|
||||
if x != nil {
|
||||
return x.Reset_
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (x *QueryStatsRequest) GetPatterns() []string {
|
||||
if x != nil {
|
||||
return x.Patterns
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *QueryStatsRequest) GetRegexp() bool {
|
||||
if x != nil {
|
||||
return x.Regexp
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type QueryStatsResponse struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Stat []*Stat `protobuf:"bytes,1,rep,name=stat,proto3" json:"stat,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *QueryStatsResponse) Reset() {
|
||||
*x = QueryStatsResponse{}
|
||||
mi := &file_experimental_v2rayapi_stats_proto_msgTypes[4]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *QueryStatsResponse) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*QueryStatsResponse) ProtoMessage() {}
|
||||
|
||||
func (x *QueryStatsResponse) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_experimental_v2rayapi_stats_proto_msgTypes[4]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use QueryStatsResponse.ProtoReflect.Descriptor instead.
|
||||
func (*QueryStatsResponse) Descriptor() ([]byte, []int) {
|
||||
return file_experimental_v2rayapi_stats_proto_rawDescGZIP(), []int{4}
|
||||
}
|
||||
|
||||
func (x *QueryStatsResponse) GetStat() []*Stat {
|
||||
if x != nil {
|
||||
return x.Stat
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type SysStatsRequest struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *SysStatsRequest) Reset() {
|
||||
*x = SysStatsRequest{}
|
||||
mi := &file_experimental_v2rayapi_stats_proto_msgTypes[5]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *SysStatsRequest) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*SysStatsRequest) ProtoMessage() {}
|
||||
|
||||
func (x *SysStatsRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_experimental_v2rayapi_stats_proto_msgTypes[5]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use SysStatsRequest.ProtoReflect.Descriptor instead.
|
||||
func (*SysStatsRequest) Descriptor() ([]byte, []int) {
|
||||
return file_experimental_v2rayapi_stats_proto_rawDescGZIP(), []int{5}
|
||||
}
|
||||
|
||||
type SysStatsResponse struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
NumGoroutine uint32 `protobuf:"varint,1,opt,name=NumGoroutine,proto3" json:"NumGoroutine,omitempty"`
|
||||
NumGC uint32 `protobuf:"varint,2,opt,name=NumGC,proto3" json:"NumGC,omitempty"`
|
||||
Alloc uint64 `protobuf:"varint,3,opt,name=Alloc,proto3" json:"Alloc,omitempty"`
|
||||
TotalAlloc uint64 `protobuf:"varint,4,opt,name=TotalAlloc,proto3" json:"TotalAlloc,omitempty"`
|
||||
Sys uint64 `protobuf:"varint,5,opt,name=Sys,proto3" json:"Sys,omitempty"`
|
||||
Mallocs uint64 `protobuf:"varint,6,opt,name=Mallocs,proto3" json:"Mallocs,omitempty"`
|
||||
Frees uint64 `protobuf:"varint,7,opt,name=Frees,proto3" json:"Frees,omitempty"`
|
||||
LiveObjects uint64 `protobuf:"varint,8,opt,name=LiveObjects,proto3" json:"LiveObjects,omitempty"`
|
||||
PauseTotalNs uint64 `protobuf:"varint,9,opt,name=PauseTotalNs,proto3" json:"PauseTotalNs,omitempty"`
|
||||
Uptime uint32 `protobuf:"varint,10,opt,name=Uptime,proto3" json:"Uptime,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *SysStatsResponse) Reset() {
|
||||
*x = SysStatsResponse{}
|
||||
mi := &file_experimental_v2rayapi_stats_proto_msgTypes[6]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *SysStatsResponse) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*SysStatsResponse) ProtoMessage() {}
|
||||
|
||||
func (x *SysStatsResponse) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_experimental_v2rayapi_stats_proto_msgTypes[6]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use SysStatsResponse.ProtoReflect.Descriptor instead.
|
||||
func (*SysStatsResponse) Descriptor() ([]byte, []int) {
|
||||
return file_experimental_v2rayapi_stats_proto_rawDescGZIP(), []int{6}
|
||||
}
|
||||
|
||||
func (x *SysStatsResponse) GetNumGoroutine() uint32 {
|
||||
if x != nil {
|
||||
return x.NumGoroutine
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *SysStatsResponse) GetNumGC() uint32 {
|
||||
if x != nil {
|
||||
return x.NumGC
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *SysStatsResponse) GetAlloc() uint64 {
|
||||
if x != nil {
|
||||
return x.Alloc
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *SysStatsResponse) GetTotalAlloc() uint64 {
|
||||
if x != nil {
|
||||
return x.TotalAlloc
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *SysStatsResponse) GetSys() uint64 {
|
||||
if x != nil {
|
||||
return x.Sys
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *SysStatsResponse) GetMallocs() uint64 {
|
||||
if x != nil {
|
||||
return x.Mallocs
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *SysStatsResponse) GetFrees() uint64 {
|
||||
if x != nil {
|
||||
return x.Frees
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *SysStatsResponse) GetLiveObjects() uint64 {
|
||||
if x != nil {
|
||||
return x.LiveObjects
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *SysStatsResponse) GetPauseTotalNs() uint64 {
|
||||
if x != nil {
|
||||
return x.PauseTotalNs
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *SysStatsResponse) GetUptime() uint32 {
|
||||
if x != nil {
|
||||
return x.Uptime
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
var File_experimental_v2rayapi_stats_proto protoreflect.FileDescriptor
|
||||
|
||||
const file_experimental_v2rayapi_stats_proto_rawDesc = "" +
|
||||
"\n" +
|
||||
"!experimental/v2rayapi/stats.proto\x12\x15experimental.v2rayapi\";\n" +
|
||||
"\x0fGetStatsRequest\x12\x12\n" +
|
||||
"\x04name\x18\x01 \x01(\tR\x04name\x12\x14\n" +
|
||||
"\x05reset\x18\x02 \x01(\bR\x05reset\"0\n" +
|
||||
"\x04Stat\x12\x12\n" +
|
||||
"\x04name\x18\x01 \x01(\tR\x04name\x12\x14\n" +
|
||||
"\x05value\x18\x02 \x01(\x03R\x05value\"C\n" +
|
||||
"\x10GetStatsResponse\x12/\n" +
|
||||
"\x04stat\x18\x01 \x01(\v2\x1b.experimental.v2rayapi.StatR\x04stat\"w\n" +
|
||||
"\x11QueryStatsRequest\x12\x18\n" +
|
||||
"\apattern\x18\x01 \x01(\tR\apattern\x12\x14\n" +
|
||||
"\x05reset\x18\x02 \x01(\bR\x05reset\x12\x1a\n" +
|
||||
"\bpatterns\x18\x03 \x03(\tR\bpatterns\x12\x16\n" +
|
||||
"\x06regexp\x18\x04 \x01(\bR\x06regexp\"E\n" +
|
||||
"\x12QueryStatsResponse\x12/\n" +
|
||||
"\x04stat\x18\x01 \x03(\v2\x1b.experimental.v2rayapi.StatR\x04stat\"\x11\n" +
|
||||
"\x0fSysStatsRequest\"\xa2\x02\n" +
|
||||
"\x10SysStatsResponse\x12\"\n" +
|
||||
"\fNumGoroutine\x18\x01 \x01(\rR\fNumGoroutine\x12\x14\n" +
|
||||
"\x05NumGC\x18\x02 \x01(\rR\x05NumGC\x12\x14\n" +
|
||||
"\x05Alloc\x18\x03 \x01(\x04R\x05Alloc\x12\x1e\n" +
|
||||
"\n" +
|
||||
"TotalAlloc\x18\x04 \x01(\x04R\n" +
|
||||
"TotalAlloc\x12\x10\n" +
|
||||
"\x03Sys\x18\x05 \x01(\x04R\x03Sys\x12\x18\n" +
|
||||
"\aMallocs\x18\x06 \x01(\x04R\aMallocs\x12\x14\n" +
|
||||
"\x05Frees\x18\a \x01(\x04R\x05Frees\x12 \n" +
|
||||
"\vLiveObjects\x18\b \x01(\x04R\vLiveObjects\x12\"\n" +
|
||||
"\fPauseTotalNs\x18\t \x01(\x04R\fPauseTotalNs\x12\x16\n" +
|
||||
"\x06Uptime\x18\n" +
|
||||
" \x01(\rR\x06Uptime2\xb4\x02\n" +
|
||||
"\fStatsService\x12]\n" +
|
||||
"\bGetStats\x12&.experimental.v2rayapi.GetStatsRequest\x1a'.experimental.v2rayapi.GetStatsResponse\"\x00\x12c\n" +
|
||||
"\n" +
|
||||
"QueryStats\x12(.experimental.v2rayapi.QueryStatsRequest\x1a).experimental.v2rayapi.QueryStatsResponse\"\x00\x12`\n" +
|
||||
"\vGetSysStats\x12&.experimental.v2rayapi.SysStatsRequest\x1a'.experimental.v2rayapi.SysStatsResponse\"\x00B4Z2github.com/sagernet/sing-box/experimental/v2rayapib\x06proto3"
|
||||
|
||||
var (
|
||||
file_experimental_v2rayapi_stats_proto_rawDescOnce sync.Once
|
||||
file_experimental_v2rayapi_stats_proto_rawDescData []byte
|
||||
)
|
||||
|
||||
func file_experimental_v2rayapi_stats_proto_rawDescGZIP() []byte {
|
||||
file_experimental_v2rayapi_stats_proto_rawDescOnce.Do(func() {
|
||||
file_experimental_v2rayapi_stats_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_experimental_v2rayapi_stats_proto_rawDesc), len(file_experimental_v2rayapi_stats_proto_rawDesc)))
|
||||
})
|
||||
return file_experimental_v2rayapi_stats_proto_rawDescData
|
||||
}
|
||||
|
||||
var (
|
||||
file_experimental_v2rayapi_stats_proto_msgTypes = make([]protoimpl.MessageInfo, 7)
|
||||
file_experimental_v2rayapi_stats_proto_goTypes = []any{
|
||||
(*GetStatsRequest)(nil), // 0: experimental.v2rayapi.GetStatsRequest
|
||||
(*Stat)(nil), // 1: experimental.v2rayapi.Stat
|
||||
(*GetStatsResponse)(nil), // 2: experimental.v2rayapi.GetStatsResponse
|
||||
(*QueryStatsRequest)(nil), // 3: experimental.v2rayapi.QueryStatsRequest
|
||||
(*QueryStatsResponse)(nil), // 4: experimental.v2rayapi.QueryStatsResponse
|
||||
(*SysStatsRequest)(nil), // 5: experimental.v2rayapi.SysStatsRequest
|
||||
(*SysStatsResponse)(nil), // 6: experimental.v2rayapi.SysStatsResponse
|
||||
}
|
||||
)
|
||||
|
||||
var file_experimental_v2rayapi_stats_proto_depIdxs = []int32{
|
||||
1, // 0: experimental.v2rayapi.GetStatsResponse.stat:type_name -> experimental.v2rayapi.Stat
|
||||
1, // 1: experimental.v2rayapi.QueryStatsResponse.stat:type_name -> experimental.v2rayapi.Stat
|
||||
0, // 2: experimental.v2rayapi.StatsService.GetStats:input_type -> experimental.v2rayapi.GetStatsRequest
|
||||
3, // 3: experimental.v2rayapi.StatsService.QueryStats:input_type -> experimental.v2rayapi.QueryStatsRequest
|
||||
5, // 4: experimental.v2rayapi.StatsService.GetSysStats:input_type -> experimental.v2rayapi.SysStatsRequest
|
||||
2, // 5: experimental.v2rayapi.StatsService.GetStats:output_type -> experimental.v2rayapi.GetStatsResponse
|
||||
4, // 6: experimental.v2rayapi.StatsService.QueryStats:output_type -> experimental.v2rayapi.QueryStatsResponse
|
||||
6, // 7: experimental.v2rayapi.StatsService.GetSysStats:output_type -> experimental.v2rayapi.SysStatsResponse
|
||||
5, // [5:8] is the sub-list for method output_type
|
||||
2, // [2:5] is the sub-list for method input_type
|
||||
2, // [2:2] is the sub-list for extension type_name
|
||||
2, // [2:2] is the sub-list for extension extendee
|
||||
0, // [0:2] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_experimental_v2rayapi_stats_proto_init() }
|
||||
func file_experimental_v2rayapi_stats_proto_init() {
|
||||
if File_experimental_v2rayapi_stats_proto != nil {
|
||||
return
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: unsafe.Slice(unsafe.StringData(file_experimental_v2rayapi_stats_proto_rawDesc), len(file_experimental_v2rayapi_stats_proto_rawDesc)),
|
||||
NumEnums: 0,
|
||||
NumMessages: 7,
|
||||
NumExtensions: 0,
|
||||
NumServices: 1,
|
||||
},
|
||||
GoTypes: file_experimental_v2rayapi_stats_proto_goTypes,
|
||||
DependencyIndexes: file_experimental_v2rayapi_stats_proto_depIdxs,
|
||||
MessageInfos: file_experimental_v2rayapi_stats_proto_msgTypes,
|
||||
}.Build()
|
||||
File_experimental_v2rayapi_stats_proto = out.File
|
||||
file_experimental_v2rayapi_stats_proto_goTypes = nil
|
||||
file_experimental_v2rayapi_stats_proto_depIdxs = nil
|
||||
}
|
||||
53
experimental/v2rayapi/stats.proto
Normal file
53
experimental/v2rayapi/stats.proto
Normal file
@@ -0,0 +1,53 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package experimental.v2rayapi;
|
||||
option go_package = "github.com/sagernet/sing-box/experimental/v2rayapi";
|
||||
|
||||
message GetStatsRequest {
|
||||
// Name of the stat counter.
|
||||
string name = 1;
|
||||
// Whether or not to reset the counter to fetching its value.
|
||||
bool reset = 2;
|
||||
}
|
||||
|
||||
message Stat {
|
||||
string name = 1;
|
||||
int64 value = 2;
|
||||
}
|
||||
|
||||
message GetStatsResponse {
|
||||
Stat stat = 1;
|
||||
}
|
||||
|
||||
message QueryStatsRequest {
|
||||
// Deprecated, use Patterns instead
|
||||
string pattern = 1;
|
||||
bool reset = 2;
|
||||
repeated string patterns = 3;
|
||||
bool regexp = 4;
|
||||
}
|
||||
|
||||
message QueryStatsResponse {
|
||||
repeated Stat stat = 1;
|
||||
}
|
||||
|
||||
message SysStatsRequest {}
|
||||
|
||||
message SysStatsResponse {
|
||||
uint32 NumGoroutine = 1;
|
||||
uint32 NumGC = 2;
|
||||
uint64 Alloc = 3;
|
||||
uint64 TotalAlloc = 4;
|
||||
uint64 Sys = 5;
|
||||
uint64 Mallocs = 6;
|
||||
uint64 Frees = 7;
|
||||
uint64 LiveObjects = 8;
|
||||
uint64 PauseTotalNs = 9;
|
||||
uint32 Uptime = 10;
|
||||
}
|
||||
|
||||
service StatsService {
|
||||
rpc GetStats(GetStatsRequest) returns (GetStatsResponse) {}
|
||||
rpc QueryStats(QueryStatsRequest) returns (QueryStatsResponse) {}
|
||||
rpc GetSysStats(SysStatsRequest) returns (SysStatsResponse) {}
|
||||
}
|
||||
194
experimental/v2rayapi/stats_grpc.pb.go
Normal file
194
experimental/v2rayapi/stats_grpc.pb.go
Normal file
@@ -0,0 +1,194 @@
|
||||
package v2rayapi
|
||||
|
||||
import (
|
||||
context "context"
|
||||
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the grpc package it is being compiled against.
|
||||
// Requires gRPC-Go v1.64.0 or later.
|
||||
const _ = grpc.SupportPackageIsVersion9
|
||||
|
||||
const (
|
||||
StatsService_GetStats_FullMethodName = "/experimental.v2rayapi.StatsService/GetStats"
|
||||
StatsService_QueryStats_FullMethodName = "/experimental.v2rayapi.StatsService/QueryStats"
|
||||
StatsService_GetSysStats_FullMethodName = "/experimental.v2rayapi.StatsService/GetSysStats"
|
||||
)
|
||||
|
||||
// StatsServiceClient is the client API for StatsService service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
type StatsServiceClient interface {
|
||||
GetStats(ctx context.Context, in *GetStatsRequest, opts ...grpc.CallOption) (*GetStatsResponse, error)
|
||||
QueryStats(ctx context.Context, in *QueryStatsRequest, opts ...grpc.CallOption) (*QueryStatsResponse, error)
|
||||
GetSysStats(ctx context.Context, in *SysStatsRequest, opts ...grpc.CallOption) (*SysStatsResponse, error)
|
||||
}
|
||||
|
||||
type statsServiceClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewStatsServiceClient(cc grpc.ClientConnInterface) StatsServiceClient {
|
||||
return &statsServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *statsServiceClient) GetStats(ctx context.Context, in *GetStatsRequest, opts ...grpc.CallOption) (*GetStatsResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(GetStatsResponse)
|
||||
err := c.cc.Invoke(ctx, StatsService_GetStats_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *statsServiceClient) QueryStats(ctx context.Context, in *QueryStatsRequest, opts ...grpc.CallOption) (*QueryStatsResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(QueryStatsResponse)
|
||||
err := c.cc.Invoke(ctx, StatsService_QueryStats_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *statsServiceClient) GetSysStats(ctx context.Context, in *SysStatsRequest, opts ...grpc.CallOption) (*SysStatsResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(SysStatsResponse)
|
||||
err := c.cc.Invoke(ctx, StatsService_GetSysStats_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// StatsServiceServer is the server API for StatsService service.
|
||||
// All implementations must embed UnimplementedStatsServiceServer
|
||||
// for forward compatibility.
|
||||
type StatsServiceServer interface {
|
||||
GetStats(context.Context, *GetStatsRequest) (*GetStatsResponse, error)
|
||||
QueryStats(context.Context, *QueryStatsRequest) (*QueryStatsResponse, error)
|
||||
GetSysStats(context.Context, *SysStatsRequest) (*SysStatsResponse, error)
|
||||
mustEmbedUnimplementedStatsServiceServer()
|
||||
}
|
||||
|
||||
// UnimplementedStatsServiceServer must be embedded to have
|
||||
// forward compatible implementations.
|
||||
//
|
||||
// NOTE: this should be embedded by value instead of pointer to avoid a nil
|
||||
// pointer dereference when methods are called.
|
||||
type UnimplementedStatsServiceServer struct{}
|
||||
|
||||
func (UnimplementedStatsServiceServer) GetStats(context.Context, *GetStatsRequest) (*GetStatsResponse, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method GetStats not implemented")
|
||||
}
|
||||
|
||||
func (UnimplementedStatsServiceServer) QueryStats(context.Context, *QueryStatsRequest) (*QueryStatsResponse, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method QueryStats not implemented")
|
||||
}
|
||||
|
||||
func (UnimplementedStatsServiceServer) GetSysStats(context.Context, *SysStatsRequest) (*SysStatsResponse, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method GetSysStats not implemented")
|
||||
}
|
||||
func (UnimplementedStatsServiceServer) mustEmbedUnimplementedStatsServiceServer() {}
|
||||
func (UnimplementedStatsServiceServer) testEmbeddedByValue() {}
|
||||
|
||||
// UnsafeStatsServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to StatsServiceServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeStatsServiceServer interface {
|
||||
mustEmbedUnimplementedStatsServiceServer()
|
||||
}
|
||||
|
||||
func RegisterStatsServiceServer(s grpc.ServiceRegistrar, srv StatsServiceServer) {
|
||||
// If the following call panics, it indicates UnimplementedStatsServiceServer was
|
||||
// embedded by pointer and is nil. This will cause panics if an
|
||||
// unimplemented method is ever invoked, so we test this at initialization
|
||||
// time to prevent it from happening at runtime later due to I/O.
|
||||
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
|
||||
t.testEmbeddedByValue()
|
||||
}
|
||||
s.RegisterService(&StatsService_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _StatsService_GetStats_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetStatsRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(StatsServiceServer).GetStats(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: StatsService_GetStats_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(StatsServiceServer).GetStats(ctx, req.(*GetStatsRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _StatsService_QueryStats_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(QueryStatsRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(StatsServiceServer).QueryStats(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: StatsService_QueryStats_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(StatsServiceServer).QueryStats(ctx, req.(*QueryStatsRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _StatsService_GetSysStats_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(SysStatsRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(StatsServiceServer).GetSysStats(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: StatsService_GetSysStats_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(StatsServiceServer).GetSysStats(ctx, req.(*SysStatsRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// StatsService_ServiceDesc is the grpc.ServiceDesc for StatsService service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var StatsService_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "experimental.v2rayapi.StatsService",
|
||||
HandlerType: (*StatsServiceServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "GetStats",
|
||||
Handler: _StatsService_GetStats_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "QueryStats",
|
||||
Handler: _StatsService_QueryStats_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetSysStats",
|
||||
Handler: _StatsService_GetSysStats_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "experimental/v2rayapi/stats.proto",
|
||||
}
|
||||
Reference in New Issue
Block a user