Successfully integrated RustRay-native gRPC API into rustray for compatibility with rr-ui panel.
Created the following .proto files in rustray/proto/:
common.proto: Network type definitions (TCP, UDP, UNIX)common_serial.proto: TypedMessage for serialized proto messagescommon_protocol.proto: User message definitionrustray.proto: Core RustRay configuration (InboundHandlerConfig, OutboundHandlerConfig)stats.proto: StatsService with methods for querying traffic statisticsproxyman.proto: HandlerService for dynamic inbound/outbound management
Updated build.rs to compile all proto files using tonic-build:
tonic_build::configure()
.build_server(true)
.build_client(false)
.compile_protos(&rustray_protos, &["proto"])?;Implements dynamic inbound/outbound management:
add_inbound: Converts proto InboundHandlerConfig to internal Inbound struct, sends ConfigEventremove_inbound: Removes inbound by tag, sends ConfigEventalter_inbound: Dynamically modifies inbound users (AddUser, RemoveUser) for VLESS/VMess/Trojanlist_inbounds: Returns list of configured inboundsget_inbound_users: Enumerates users for a specific inbound with email filteringget_inbound_users_count: Returns the count of users for a specific inboundadd_outbound: Adds new outbound configurationremove_outbound: Removes outbound by tagalter_outbound: Dynamically updates outbound settingslist_outbounds: Returns list of configured outbounds
Implements traffic statistics queries:
get_stats: Get single counter value (with optional reset)query_stats: Query counters using regex patternget_sys_stats: Get system statistics (uptime, memory)get_stats_online_ip_list: Get online IPs per user/inbound (placeholder)
Created run_grpc_server function that:
- Binds to
0.0.0.0:[port](default: 10085) - Registers HandlerServiceServer and StatsServiceServer
- Runs standalone tonic::transport::Server
- Spawns gRPC server as background tokio task
- Shares StatsManager instance between proxy core and gRPC API
- Runs independently from actix-web metrics server
Added Serialize derive to all config structs for proto serialization:
- InboundSettings and OutboundSettings enums
- All protocol-specific settings structs
- Maintains
#[serde(rename = "streamSettings")]for camelCase compatibility
Add API section to config.json:
{
"api": {
"tag": "api",
"services": ["HandlerService", "StatsService"],
"port": 10085,
"listen": "0.0.0.0"
}
}The server exposes two services:
rustray.app.proxyman.command.HandlerService- Inbound/outbound managementrustray.app.stats.command.StatsService- Traffic statistics
# List services
grpcurl -plaintext localhost:10085 list
# Query stats
grpcurl -plaintext -d '{"pattern": ".*"}' localhost:10085 \
rustray.app.stats.command.StatsService/QueryStats
# List inbounds
grpcurl -plaintext -d '{}' localhost:10085 \
rustray.app.proxyman.command.HandlerService/ListInboundsFor developers building panels or automation tools:
import grpc
import stats_pb2_grpc as stats_rpc
import stats_pb2 as stats_msg
with grpc.insecure_channel('localhost:10085') as channel:
stub = stats_rpc.StatsServiceStub(channel)
response = stub.QueryStats(stats_msg.QueryStatsRequest(pattern=".*", reset=False))
for stat in response.stat:
print(f"{stat.name}: {stat.value}")conn, _ := grpc.Dial("localhost:10085", grpc.WithInsecure())
client := proxyman.NewHandlerServiceClient(conn)
resp, _ := client.ListInbounds(context.Background(), &proxyman.ListInboundsRequest{})
for _, inbound := range resp.Inbound {
fmt.Printf("Active Inbound: %s\n", inbound.Tag)
}-
Proto-to-Internal Conversion: The
proto_to_inboundandproto_to_outboundfunctions handle conversion between RustRay protobuf format and rustray's internal config structs. -
ConfigEvent Broadcasting: Changes made via gRPC API are broadcast to StatsManager via the
config_event_txchannel for potential hot-reload support. -
Serialization: All config structs now implement both
DeserializeandSerializefor bidirectional proto conversion. -
Port Configuration: gRPC server uses the port from
config.api.port, defaulting to 10085 if not specified.
- IP Tracking:
get_stats_online_ip_listneeds connection tracking implementation - Hot Reload: ConfigEvent handlers need to trigger actual inbound/outbound reconfiguration
- PQC Handshake: Support for post-quantum key exchange in gRPC signaling
proto/common.protoproto/common_serial.protoproto/common_protocol.protoproto/rustray.protoproto/stats.protoproto/proxyman.protosrc/api/handler.rssrc/api/stats.rs
build.rs- Added proto compilationsrc/api/mod.rs- Enabled proto includes, added handler/stats modulessrc/api/server.rs- Implemented run_grpc_serversrc/lib.rs- Spawned gRPC server tasksrc/config.rs- Added Serialize derives to all structs
✅ Successfully compiles with 56 warnings (mostly unused imports in Flow-J modules) ✅ gRPC services properly registered and exposed ✅ Compatible with RustRay protocol buffer definitions