Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API - Add | Remove Routing Rules #3189

Merged
merged 7 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions app/router/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ func (s *routingServer) OverrideBalancerTarget(ctx context.Context, request *Ove
return nil, newError("unsupported router implementation")
}

func (s *routingServer) AddRule(ctx context.Context, request *AddRuleRequest) (*AddRuleResponse, error) {
if bo, ok := s.router.(routing.Router); ok {
return &AddRuleResponse{}, bo.AddRule(request.Config)
}
return nil, newError("unsupported router implementation")

}
func (s *routingServer) RemoveRule(ctx context.Context, request *RemoveRuleRequest) (*RemoveRuleResponse, error) {
if bo, ok := s.router.(routing.Router); ok {
return &RemoveRuleResponse{}, bo.RemoveRule(request.RuleTag)
}
return nil, newError("unsupported router implementation")
}

// NewRoutingServer creates a statistics service with statistics manager.
func NewRoutingServer(router routing.Router, routingStats stats.Channel) RoutingServiceServer {
return &routingServer{
Expand Down
520 changes: 387 additions & 133 deletions app/router/command/command.pb.go

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions app/router/command/command.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ option java_package = "com.xray.app.router.command";
option java_multiple_files = true;

import "common/net/network.proto";
import "common/serial/typed_message.proto";

// RoutingContext is the context with information relative to routing process.
// It conforms to the structure of xray.features.routing.Context and
Expand Down Expand Up @@ -88,13 +89,27 @@ message OverrideBalancerTargetRequest {

message OverrideBalancerTargetResponse {}

message AddRuleRequest {
xray.common.serial.TypedMessage config = 1;
}
message AddRuleResponse {}

message RemoveRuleRequest {
string ruleTag = 1;
}

message RemoveRuleResponse {}

service RoutingService {
rpc SubscribeRoutingStats(SubscribeRoutingStatsRequest)
returns (stream RoutingContext) {}
rpc TestRoute(TestRouteRequest) returns (RoutingContext) {}

rpc GetBalancerInfo(GetBalancerInfoRequest) returns (GetBalancerInfoResponse){}
rpc OverrideBalancerTarget(OverrideBalancerTargetRequest) returns (OverrideBalancerTargetResponse) {}

rpc AddRule(AddRuleRequest) returns (AddRuleResponse) {}
rpc RemoveRule(RemoveRuleRequest) returns (RemoveRuleResponse) {}
}

message Config {}
76 changes: 75 additions & 1 deletion app/router/command/command_grpc.pb.go

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

5 changes: 3 additions & 2 deletions app/router/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

type Rule struct {
Tag string
RuleTag string
Balancer *Balancer
Condition Condition
}
Expand Down Expand Up @@ -150,7 +151,7 @@ func (br *BalancingRule) Build(ohm outbound.Manager, dispatcher routing.Dispatch
leastLoadStrategy := NewLeastLoadStrategy(s)
return &Balancer{
selectors: br.OutboundSelector,
ohm: ohm,
ohm: ohm,
fallbackTag: br.FallbackTag,
strategy: leastLoadStrategy,
}, nil
Expand All @@ -159,7 +160,7 @@ func (br *BalancingRule) Build(ohm outbound.Manager, dispatcher routing.Dispatch
case "":
return &Balancer{
selectors: br.OutboundSelector,
ohm: ohm,
ohm: ohm,
fallbackTag: br.FallbackTag,
strategy: &RandomStrategy{},
}, nil
Expand Down
Loading