From bc73aa2a05a892214550dea95b5bcb568d521238 Mon Sep 17 00:00:00 2001 From: hiddify Date: Sat, 20 May 2023 09:09:37 +0200 Subject: [PATCH] fix: singbox --- xtlsapi/singbox_api/build.sh | 2 + xtlsapi/singbox_api/extensions.proto | 39 ++++++++++++++++ xtlsapi/singbox_api/extensions_pb2.py | 31 +++++++++++++ xtlsapi/singbox_api/extensions_pb2_grpc.py | 4 ++ xtlsapi/singbox_api/stats.proto | 14 +++++- xtlsapi/singbox_api/stats_old.proto | 53 ++++++++++++++++++++++ xtlsapi/singbox_api/stats_pb2.py | 41 +++++++++-------- xtlsapi/singbox_api/stats_pb2_grpc.py | 16 +++---- 8 files changed, 172 insertions(+), 28 deletions(-) create mode 100644 xtlsapi/singbox_api/extensions.proto create mode 100644 xtlsapi/singbox_api/extensions_pb2.py create mode 100644 xtlsapi/singbox_api/extensions_pb2_grpc.py create mode 100644 xtlsapi/singbox_api/stats_old.proto diff --git a/xtlsapi/singbox_api/build.sh b/xtlsapi/singbox_api/build.sh index 1eb978d..0440ffd 100644 --- a/xtlsapi/singbox_api/build.sh +++ b/xtlsapi/singbox_api/build.sh @@ -1,4 +1,6 @@ # sudo apt install -y protobuf-compiler #wget https://github.com/protocolbuffers/protobuf/releases/download/v23.1/protoc-23.1-linux-aarch_64.zip ../../bin/protoc ./stats.proto --python_out=./ +../../bin/protoc ./extensions.proto --python_out=./ python3 -m grpc_tools.protoc -I ./ --python_out=./ --grpc_python_out=./ ./stats.proto +python3 -m grpc_tools.protoc -I ./ --python_out=./ --grpc_python_out=./ ./extensions.proto diff --git a/xtlsapi/singbox_api/extensions.proto b/xtlsapi/singbox_api/extensions.proto new file mode 100644 index 0000000..e7fd821 --- /dev/null +++ b/xtlsapi/singbox_api/extensions.proto @@ -0,0 +1,39 @@ +syntax = "proto3"; + +package v2ray.core.common.protoext; +option csharp_namespace = "V2Ray.Core.Common.ProtoExt"; +option go_package = "github.com/v2fly/v2ray-core/v5/common/protoext"; +option java_package = "com.v2ray.core.common.protoext"; +option java_multiple_files = true; + +import "google/protobuf/descriptor.proto"; + +extend google.protobuf.MessageOptions { + MessageOpt message_opt = 50000; +} + +extend google.protobuf.FieldOptions { + FieldOpt field_opt = 50000; +} + +message MessageOpt{ + repeated string type = 1; + repeated string short_name = 2; + + string transport_original_name = 86001; +} + +message FieldOpt{ + repeated string any_wants = 1; + repeated string allowed_values = 2; + repeated string allowed_value_types = 3; + + // convert_time_read_file_into read a file into another field, and clear this field during input parsing + string convert_time_read_file_into = 4; + // forbidden marks a boolean to be inaccessible to user + bool forbidden = 5; + // convert_time_resource_loading read a file, and place its resource hash into another field + string convert_time_resource_loading = 6; + // convert_time_parse_ip parse a string ip address, and put its binary representation into another field + string convert_time_parse_ip = 7; +} \ No newline at end of file diff --git a/xtlsapi/singbox_api/extensions_pb2.py b/xtlsapi/singbox_api/extensions_pb2.py new file mode 100644 index 0000000..da0ea23 --- /dev/null +++ b/xtlsapi/singbox_api/extensions_pb2.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: extensions.proto +"""Generated protocol buffer code.""" +from google.protobuf.internal import builder as _builder +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import symbol_database as _symbol_database +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + +from google.protobuf import descriptor_pb2 as google_dot_protobuf_dot_descriptor__pb2 + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x10\x65xtensions.proto\x12\x1av2ray.core.common.protoext\x1a google/protobuf/descriptor.proto\"Q\n\nMessageOpt\x12\x0c\n\x04type\x18\x01 \x03(\t\x12\x12\n\nshort_name\x18\x02 \x03(\t\x12!\n\x17transport_original_name\x18\xf1\x9f\x05 \x01(\t\"\xd0\x01\n\x08\x46ieldOpt\x12\x11\n\tany_wants\x18\x01 \x03(\t\x12\x16\n\x0e\x61llowed_values\x18\x02 \x03(\t\x12\x1b\n\x13\x61llowed_value_types\x18\x03 \x03(\t\x12#\n\x1b\x63onvert_time_read_file_into\x18\x04 \x01(\t\x12\x11\n\tforbidden\x18\x05 \x01(\x08\x12%\n\x1d\x63onvert_time_resource_loading\x18\x06 \x01(\t\x12\x1d\n\x15\x63onvert_time_parse_ip\x18\x07 \x01(\t:^\n\x0bmessage_opt\x12\x1f.google.protobuf.MessageOptions\x18\xd0\x86\x03 \x01(\x0b\x32&.v2ray.core.common.protoext.MessageOpt:X\n\tfield_opt\x12\x1d.google.protobuf.FieldOptions\x18\xd0\x86\x03 \x01(\x0b\x32$.v2ray.core.common.protoext.FieldOptBo\n\x1e\x63om.v2ray.core.common.protoextP\x01Z.github.com/v2fly/v2ray-core/v5/common/protoext\xaa\x02\x1aV2Ray.Core.Common.ProtoExtb\x06proto3') + +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'extensions_pb2', globals()) +if _descriptor._USE_C_DESCRIPTORS == False: + google_dot_protobuf_dot_descriptor__pb2.MessageOptions.RegisterExtension(message_opt) + google_dot_protobuf_dot_descriptor__pb2.FieldOptions.RegisterExtension(field_opt) + + DESCRIPTOR._options = None + DESCRIPTOR._serialized_options = b'\n\036com.v2ray.core.common.protoextP\001Z.github.com/v2fly/v2ray-core/v5/common/protoext\252\002\032V2Ray.Core.Common.ProtoExt' + _MESSAGEOPT._serialized_start=82 + _MESSAGEOPT._serialized_end=163 + _FIELDOPT._serialized_start=166 + _FIELDOPT._serialized_end=374 +# @@protoc_insertion_point(module_scope) diff --git a/xtlsapi/singbox_api/extensions_pb2_grpc.py b/xtlsapi/singbox_api/extensions_pb2_grpc.py new file mode 100644 index 0000000..2daafff --- /dev/null +++ b/xtlsapi/singbox_api/extensions_pb2_grpc.py @@ -0,0 +1,4 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +"""Client and server classes corresponding to protobuf-defined services.""" +import grpc + diff --git a/xtlsapi/singbox_api/stats.proto b/xtlsapi/singbox_api/stats.proto index 5fc3da4..1a17303 100644 --- a/xtlsapi/singbox_api/stats.proto +++ b/xtlsapi/singbox_api/stats.proto @@ -1,7 +1,12 @@ syntax = "proto3"; -package experimental.v2rayapi; -option go_package = "github.com/sagernet/sing-box/experimental/v2rayapi"; +package v2ray.core.app.stats.command; +option csharp_namespace = "V2Ray.Core.App.Stats.Command"; +option go_package = "github.com/v2fly/v2ray-core/v5/app/stats/command"; +option java_package = "com.v2ray.core.app.stats.command"; +option java_multiple_files = true; + +import "extensions.proto"; message GetStatsRequest { // Name of the stat counter. @@ -50,4 +55,9 @@ service StatsService { rpc GetStats(GetStatsRequest) returns (GetStatsResponse) {} rpc QueryStats(QueryStatsRequest) returns (QueryStatsResponse) {} rpc GetSysStats(SysStatsRequest) returns (SysStatsResponse) {} +} + +message Config { + option (v2ray.core.common.protoext.message_opt).type = "grpcservice"; + option (v2ray.core.common.protoext.message_opt).short_name = "stats"; } \ No newline at end of file diff --git a/xtlsapi/singbox_api/stats_old.proto b/xtlsapi/singbox_api/stats_old.proto new file mode 100644 index 0000000..5fc3da4 --- /dev/null +++ b/xtlsapi/singbox_api/stats_old.proto @@ -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) {} +} \ No newline at end of file diff --git a/xtlsapi/singbox_api/stats_pb2.py b/xtlsapi/singbox_api/stats_pb2.py index 118cd8c..1a43e3a 100644 --- a/xtlsapi/singbox_api/stats_pb2.py +++ b/xtlsapi/singbox_api/stats_pb2.py @@ -11,30 +11,35 @@ _sym_db = _symbol_database.Default() +import extensions_pb2 as extensions__pb2 -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0bstats.proto\x12\x15\x65xperimental.v2rayapi\".\n\x0fGetStatsRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\r\n\x05reset\x18\x02 \x01(\x08\"#\n\x04Stat\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\x03\"=\n\x10GetStatsResponse\x12)\n\x04stat\x18\x01 \x01(\x0b\x32\x1b.experimental.v2rayapi.Stat\"U\n\x11QueryStatsRequest\x12\x0f\n\x07pattern\x18\x01 \x01(\t\x12\r\n\x05reset\x18\x02 \x01(\x08\x12\x10\n\x08patterns\x18\x03 \x03(\t\x12\x0e\n\x06regexp\x18\x04 \x01(\x08\"?\n\x12QueryStatsResponse\x12)\n\x04stat\x18\x01 \x03(\x0b\x32\x1b.experimental.v2rayapi.Stat\"\x11\n\x0fSysStatsRequest\"\xc2\x01\n\x10SysStatsResponse\x12\x14\n\x0cNumGoroutine\x18\x01 \x01(\r\x12\r\n\x05NumGC\x18\x02 \x01(\r\x12\r\n\x05\x41lloc\x18\x03 \x01(\x04\x12\x12\n\nTotalAlloc\x18\x04 \x01(\x04\x12\x0b\n\x03Sys\x18\x05 \x01(\x04\x12\x0f\n\x07Mallocs\x18\x06 \x01(\x04\x12\r\n\x05\x46rees\x18\x07 \x01(\x04\x12\x13\n\x0bLiveObjects\x18\x08 \x01(\x04\x12\x14\n\x0cPauseTotalNs\x18\t \x01(\x04\x12\x0e\n\x06Uptime\x18\n \x01(\r2\xb4\x02\n\x0cStatsService\x12]\n\x08GetStats\x12&.experimental.v2rayapi.GetStatsRequest\x1a\'.experimental.v2rayapi.GetStatsResponse\"\x00\x12\x63\n\nQueryStats\x12(.experimental.v2rayapi.QueryStatsRequest\x1a).experimental.v2rayapi.QueryStatsResponse\"\x00\x12`\n\x0bGetSysStats\x12&.experimental.v2rayapi.SysStatsRequest\x1a\'.experimental.v2rayapi.SysStatsResponse\"\x00\x42\x34Z2github.com/sagernet/sing-box/experimental/v2rayapib\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0bstats.proto\x12\x1cv2ray.core.app.stats.command\x1a\x10\x65xtensions.proto\".\n\x0fGetStatsRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\r\n\x05reset\x18\x02 \x01(\x08\"#\n\x04Stat\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\x03\"D\n\x10GetStatsResponse\x12\x30\n\x04stat\x18\x01 \x01(\x0b\x32\".v2ray.core.app.stats.command.Stat\"U\n\x11QueryStatsRequest\x12\x0f\n\x07pattern\x18\x01 \x01(\t\x12\r\n\x05reset\x18\x02 \x01(\x08\x12\x10\n\x08patterns\x18\x03 \x03(\t\x12\x0e\n\x06regexp\x18\x04 \x01(\x08\"F\n\x12QueryStatsResponse\x12\x30\n\x04stat\x18\x01 \x03(\x0b\x32\".v2ray.core.app.stats.command.Stat\"\x11\n\x0fSysStatsRequest\"\xc2\x01\n\x10SysStatsResponse\x12\x14\n\x0cNumGoroutine\x18\x01 \x01(\r\x12\r\n\x05NumGC\x18\x02 \x01(\r\x12\r\n\x05\x41lloc\x18\x03 \x01(\x04\x12\x12\n\nTotalAlloc\x18\x04 \x01(\x04\x12\x0b\n\x03Sys\x18\x05 \x01(\x04\x12\x0f\n\x07Mallocs\x18\x06 \x01(\x04\x12\r\n\x05\x46rees\x18\x07 \x01(\x04\x12\x13\n\x0bLiveObjects\x18\x08 \x01(\x04\x12\x14\n\x0cPauseTotalNs\x18\t \x01(\x04\x12\x0e\n\x06Uptime\x18\n \x01(\r\"&\n\x06\x43onfig:\x1c\x82\xb5\x18\r\n\x0bgrpcservice\x82\xb5\x18\x07\x12\x05stats2\xde\x02\n\x0cStatsService\x12k\n\x08GetStats\x12-.v2ray.core.app.stats.command.GetStatsRequest\x1a..v2ray.core.app.stats.command.GetStatsResponse\"\x00\x12q\n\nQueryStats\x12/.v2ray.core.app.stats.command.QueryStatsRequest\x1a\x30.v2ray.core.app.stats.command.QueryStatsResponse\"\x00\x12n\n\x0bGetSysStats\x12-.v2ray.core.app.stats.command.SysStatsRequest\x1a..v2ray.core.app.stats.command.SysStatsResponse\"\x00\x42u\n com.v2ray.core.app.stats.commandP\x01Z0github.com/v2fly/v2ray-core/v5/app/stats/command\xaa\x02\x1cV2Ray.Core.App.Stats.Commandb\x06proto3') _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'stats_pb2', globals()) if _descriptor._USE_C_DESCRIPTORS == False: DESCRIPTOR._options = None - DESCRIPTOR._serialized_options = b'Z2github.com/sagernet/sing-box/experimental/v2rayapi' - _GETSTATSREQUEST._serialized_start=38 - _GETSTATSREQUEST._serialized_end=84 - _STAT._serialized_start=86 - _STAT._serialized_end=121 - _GETSTATSRESPONSE._serialized_start=123 - _GETSTATSRESPONSE._serialized_end=184 - _QUERYSTATSREQUEST._serialized_start=186 - _QUERYSTATSREQUEST._serialized_end=271 - _QUERYSTATSRESPONSE._serialized_start=273 - _QUERYSTATSRESPONSE._serialized_end=336 - _SYSSTATSREQUEST._serialized_start=338 - _SYSSTATSREQUEST._serialized_end=355 - _SYSSTATSRESPONSE._serialized_start=358 - _SYSSTATSRESPONSE._serialized_end=552 - _STATSSERVICE._serialized_start=555 - _STATSSERVICE._serialized_end=863 + DESCRIPTOR._serialized_options = b'\n com.v2ray.core.app.stats.commandP\001Z0github.com/v2fly/v2ray-core/v5/app/stats/command\252\002\034V2Ray.Core.App.Stats.Command' + _CONFIG._options = None + _CONFIG._serialized_options = b'\202\265\030\r\n\013grpcservice\202\265\030\007\022\005stats' + _GETSTATSREQUEST._serialized_start=63 + _GETSTATSREQUEST._serialized_end=109 + _STAT._serialized_start=111 + _STAT._serialized_end=146 + _GETSTATSRESPONSE._serialized_start=148 + _GETSTATSRESPONSE._serialized_end=216 + _QUERYSTATSREQUEST._serialized_start=218 + _QUERYSTATSREQUEST._serialized_end=303 + _QUERYSTATSRESPONSE._serialized_start=305 + _QUERYSTATSRESPONSE._serialized_end=375 + _SYSSTATSREQUEST._serialized_start=377 + _SYSSTATSREQUEST._serialized_end=394 + _SYSSTATSRESPONSE._serialized_start=397 + _SYSSTATSRESPONSE._serialized_end=591 + _CONFIG._serialized_start=593 + _CONFIG._serialized_end=631 + _STATSSERVICE._serialized_start=634 + _STATSSERVICE._serialized_end=984 # @@protoc_insertion_point(module_scope) diff --git a/xtlsapi/singbox_api/stats_pb2_grpc.py b/xtlsapi/singbox_api/stats_pb2_grpc.py index 62870fc..53991a9 100644 --- a/xtlsapi/singbox_api/stats_pb2_grpc.py +++ b/xtlsapi/singbox_api/stats_pb2_grpc.py @@ -2,7 +2,7 @@ """Client and server classes corresponding to protobuf-defined services.""" import grpc -from . import stats_pb2 as stats__pb2 +import stats_pb2 as stats__pb2 class StatsServiceStub(object): @@ -15,17 +15,17 @@ def __init__(self, channel): channel: A grpc.Channel. """ self.GetStats = channel.unary_unary( - '/experimental.v2rayapi.StatsService/GetStats', + '/v2ray.core.app.stats.command.StatsService/GetStats', request_serializer=stats__pb2.GetStatsRequest.SerializeToString, response_deserializer=stats__pb2.GetStatsResponse.FromString, ) self.QueryStats = channel.unary_unary( - '/experimental.v2rayapi.StatsService/QueryStats', + '/v2ray.core.app.stats.command.StatsService/QueryStats', request_serializer=stats__pb2.QueryStatsRequest.SerializeToString, response_deserializer=stats__pb2.QueryStatsResponse.FromString, ) self.GetSysStats = channel.unary_unary( - '/experimental.v2rayapi.StatsService/GetSysStats', + '/v2ray.core.app.stats.command.StatsService/GetSysStats', request_serializer=stats__pb2.SysStatsRequest.SerializeToString, response_deserializer=stats__pb2.SysStatsResponse.FromString, ) @@ -72,7 +72,7 @@ def add_StatsServiceServicer_to_server(servicer, server): ), } generic_handler = grpc.method_handlers_generic_handler( - 'experimental.v2rayapi.StatsService', rpc_method_handlers) + 'v2ray.core.app.stats.command.StatsService', rpc_method_handlers) server.add_generic_rpc_handlers((generic_handler,)) @@ -91,7 +91,7 @@ def GetStats(request, wait_for_ready=None, timeout=None, metadata=None): - return grpc.experimental.unary_unary(request, target, '/experimental.v2rayapi.StatsService/GetStats', + return grpc.experimental.unary_unary(request, target, '/v2ray.core.app.stats.command.StatsService/GetStats', stats__pb2.GetStatsRequest.SerializeToString, stats__pb2.GetStatsResponse.FromString, options, channel_credentials, @@ -108,7 +108,7 @@ def QueryStats(request, wait_for_ready=None, timeout=None, metadata=None): - return grpc.experimental.unary_unary(request, target, '/experimental.v2rayapi.StatsService/QueryStats', + return grpc.experimental.unary_unary(request, target, '/v2ray.core.app.stats.command.StatsService/QueryStats', stats__pb2.QueryStatsRequest.SerializeToString, stats__pb2.QueryStatsResponse.FromString, options, channel_credentials, @@ -125,7 +125,7 @@ def GetSysStats(request, wait_for_ready=None, timeout=None, metadata=None): - return grpc.experimental.unary_unary(request, target, '/experimental.v2rayapi.StatsService/GetSysStats', + return grpc.experimental.unary_unary(request, target, '/v2ray.core.app.stats.command.StatsService/GetSysStats', stats__pb2.SysStatsRequest.SerializeToString, stats__pb2.SysStatsResponse.FromString, options, channel_credentials,