feat(routing): preset packs [T1] + schedule rules [T3]
build / aarch64_cortex-a53 (push) Successful in 3m4s
build / x86_64 (push) Successful in 3m3s

Preset packs: `config preset` toggles (block-ads / ru-bypass / private) inject
synthetic rules ahead of user rules (by low Order, first-match). They flow
through the same geoStrip pipeline, so geo-only packs degrade gracefully.

Empty-matcher guard (fixes a block-everything trap): a rule that HAD dst matchers
but lost them ALL to the geo-strip and has no other selector is now DROPPED — not
promoted to a tcp,udp catch-all. So a geo-only block-ads with no geodata fails
open (ads unblocked) instead of blackholing the LAN.

Schedule rules: xray has no time match, so buildRoutingRules consults
ruleActiveNow(timeNow()) and skips out-of-window rules — a plain gen/reconcile at
any instant emits the correct ruleset. `xrayctl schedule due` (shater-cron hook)
reconciles only at window boundaries. Wrap-around windows + day-of-week + optional
tz supported; malformed windows fail open.

- model.go: Preset + Rule.Sched* fields; uci.go parses config preset + sched_*.
- preset.go, schedule.go (new); generate.go: preset injection + schedule gate +
  empty-matcher guard; main.go: `schedule due`. timeNow seam (SHATER_FAKE_NOW).
- shater-cron: reconcile on schedule boundary; uci-defaults seeds the 3 presets.
- rules.js: Preset packs panel + per-rule schedule fields.
- tests: schedule_test.go, preset_test.go (windows/wrap/dow/fail-open, preset
  inject/override/drop, scheduled-rule inclusion).

Verified live on the 512M VM: block-ads→geosite rule, private→10.0.0.0/8 direct;
geodata-absent drops block-ads (0 matches, no block-all); example.com scheduled
rule absent@12:00 present@22:30; schedule due fires at boundary; xray -test OK. r12.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
omarandClaude Opus 4.8 committed 2026-07-09 15:41:36 +03:00
1 parent a08aac62e6
commit 3449ff32fc
15 files changed
+656 -20

No files matched your search

+6 -1
View File
@@ -118,7 +118,12 @@ shater_run_due() {
loop() {
mkdir -p "$STAMP_DIR"
while shater_enabled; do
if [ -n "$(shater_run_due)" ]; then
changed=$(shater_run_due)
# Schedule boundary: `schedule due` prints "1" only when the set of active
# time-scheduled rules changed since the last tick, so we reconcile a few
# times a day at window edges — not every minute.
sched=$("$XRAYCTL" schedule due 2>/dev/null)
if [ -n "$changed" ] || [ -n "$sched" ]; then
"$XRAYCTL" reconcile >/dev/null 2>&1
fi
sleep "$TICK"