Repository navigation
feat: add configurable IP egress strategy #1
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -482,18 +482,44 @@ func (s *Server) saveConfig(change func(*model.Config)) error { | |
|
|
||
| func (s *Server) getSettings(w http.ResponseWriter, _ *http.Request) { | ||
| cfg := s.Config.Get() | ||
| writeJSON(w, 200, map[string]any{"domain": cfg.Domain, "panelPort": cfg.PanelPort, "totalBytes": cfg.TotalBytes, "reset": cfg.Reset, "subscriptionURL": subscriptionURL(cfg)}) | ||
| outboundStrategy := cfg.OutboundStrategy | ||
| if outboundStrategy == "" { | ||
| outboundStrategy = model.OutboundStrategyAuto | ||
| } | ||
| writeJSON(w, 200, map[string]any{ | ||
| "domain": cfg.Domain, "panelPort": cfg.PanelPort, "totalBytes": cfg.TotalBytes, "reset": cfg.Reset, | ||
| "outboundStrategy": outboundStrategy, "subscriptionURL": subscriptionURL(cfg), | ||
| }) | ||
| } | ||
| func (s *Server) updateSettings(w http.ResponseWriter, r *http.Request) { | ||
| var input struct { | ||
| TotalBytes int64 `json:"totalBytes"` | ||
| Reset model.ResetConfig `json:"reset"` | ||
| TotalBytes int64 `json:"totalBytes"` | ||
| Reset model.ResetConfig `json:"reset"` | ||
| OutboundStrategy string `json:"outboundStrategy"` | ||
| } | ||
| if decodeJSON(r, &input) != nil { | ||
| writeError(w, 400, "请求格式无效") | ||
| return | ||
| } | ||
| if err := s.saveConfig(func(cfg *model.Config) { cfg.TotalBytes = input.TotalBytes; cfg.Reset = input.Reset }); err != nil { | ||
| if input.OutboundStrategy == "" { | ||
| input.OutboundStrategy = model.OutboundStrategyAuto | ||
| } | ||
| change := func(cfg *model.Config) { | ||
| cfg.TotalBytes = input.TotalBytes | ||
| cfg.Reset = input.Reset | ||
| cfg.OutboundStrategy = input.OutboundStrategy | ||
| } | ||
| currentStrategy := s.Config.Get().OutboundStrategy | ||
| if currentStrategy == "" { | ||
| currentStrategy = model.OutboundStrategyAuto | ||
| } | ||
| var err error | ||
| if currentStrategy != input.OutboundStrategy { | ||
| err = s.mutate(r.Context(), change) | ||
| } else { | ||
| err = s.saveConfig(change) | ||
|
Comment on lines
+517
to
+520
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When two Useful? React with 👍 / 👎. |
||
| } | ||
| if err != nil { | ||
| writeError(w, 400, err.Error()) | ||
| return | ||
| } | ||
|
|
||
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When one settings request both changes the outbound strategy and lowers
totalBytesbelow the already-recorded usage, routing it throughmutatecallsCore.Applyusing the oldQuotaExceededstate. The core is therefore restarted and may serve traffic before the laterReconcileQuotacall notices the new limit and stops it; a quota-only update does not have this window. Compute/reconcile the quota against the new settings before allowing this strategy apply to restart sing-box.Useful? React with 👍 / 👎.