Skip to content

Commit

Permalink
fix: singbox
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddify-com committed May 20, 2023
1 parent ba4b400 commit bc73aa2
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 28 deletions.
2 changes: 2 additions & 0 deletions xtlsapi/singbox_api/build.sh
Original file line number Diff line number Diff line change
@@ -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
39 changes: 39 additions & 0 deletions xtlsapi/singbox_api/extensions.proto
Original file line number Diff line number Diff line change
@@ -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;
}
31 changes: 31 additions & 0 deletions xtlsapi/singbox_api/extensions_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions xtlsapi/singbox_api/extensions_pb2_grpc.py
Original file line number Diff line number Diff line change
@@ -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

14 changes: 12 additions & 2 deletions xtlsapi/singbox_api/stats.proto
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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";
}
53 changes: 53 additions & 0 deletions xtlsapi/singbox_api/stats_old.proto
Original file line number Diff line number Diff line change
@@ -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) {}
}
41 changes: 23 additions & 18 deletions xtlsapi/singbox_api/stats_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions xtlsapi/singbox_api/stats_pb2_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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,
)
Expand Down Expand Up @@ -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,))


Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit bc73aa2

Please sign in to comment.