🗽 Sync 2026-11-11 15:31:38

This commit is contained in:
github-actions[bot] committed 2026-11-11 15:31:38 +08:00
1 parent da9e4bea36
commit 2e3c0a9b33
189 files changed
+29797 -10433

No files matched your search

@@ -123,6 +123,7 @@ sync_hosts() {
mkdir -p "$(dirname "$HOSTS_FILE")"
> "$hosts_tmp"
echo "# Auto-generated by cf-optimizer sync on $(date '+%Y-%m-%d %H:%M:%S')" >> "$hosts_tmp"
local d
for d in $domains; do
echo "$current_ip $d" >> "$hosts_tmp"
done
@@ -146,18 +147,19 @@ load_candidate_ips() {
if [ "$ip_source" = "custom" ] || [ "$ip_source" = "mixed" ]; then
append_custom_ip() {
local item="$1"
[ -z "$item" ] && return
local _item="$1"
local _base_prefix _host
[ -z "$_item" ] && return
# 若为 CIDR 简单网段 (如 /24),取前 3 个 IP
case "$item" in
case "$_item" in
*/*)
local base_prefix=$(echo "$item" | cut -d'/' -f1 | cut -d'.' -f1-3)
for host in 1 2 3; do
echo "$base_prefix.$host" >> "$out_file"
_base_prefix=$(echo "$_item" | cut -d'/' -f1 | cut -d'.' -f1-3)
for _host in 1 2 3; do
echo "$_base_prefix.$_host" >> "$out_file"
done
;;
*)
echo "$item" | grep -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$' >> "$out_file"
echo "$_item" | grep -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$' >> "$out_file"
;;
esac
}
@@ -225,14 +227,15 @@ run_optimization() {
local target_colos=""
append_target_colo() {
local item="$1"
[ -z "$item" ] && return
for c in $item; do
local clean_c=$(echo "$c" | tr 'a-z' 'A-Z' | tr -d ' \t\r\n')
if [ -n "$clean_c" ]; then
local _item="$1"
local _colo _clean_colo
[ -z "$_item" ] && return
for _colo in $_item; do
_clean_colo=$(echo "$_colo" | tr 'a-z' 'A-Z' | tr -d ' \t\r\n')
if [ -n "$_clean_colo" ]; then
case " $target_colos " in
*" $clean_c "*) ;;
*) target_colos="$target_colos $clean_c" ;;
*" $_clean_colo "*) ;;
*) target_colos="$target_colos $_clean_colo" ;;
esac
fi
done
@@ -246,22 +249,23 @@ run_optimization() {
fi
check_colo_allowed() {
local colo="$1"
[ -z "$colo" ] && return 0
local _colo="$1"
[ -z "$_colo" ] && return 0
[ "$colo_filter_mode" = "none" ] && return 0
local match=0
for c in $target_colos; do
if [ "$c" = "$colo" ]; then
match=1
local _match=0
local _tc
for _tc in $target_colos; do
if [ "$_tc" = "$_colo" ]; then
_match=1
break
fi
done
if [ "$colo_filter_mode" = "exclude" ]; then
[ "$match" -eq 1 ] && return 1 || return 0
[ "$_match" -eq 1 ] && return 1 || return 0
elif [ "$colo_filter_mode" = "include" ]; then
[ "$match" -eq 1 ] && return 0 || return 1
[ "$_match" -eq 1 ] && return 0 || return 1
fi
return 0
}
@@ -339,6 +343,7 @@ run_optimization() {
# 阶段二:轮询交叉时序采样(跨越完整测试时段,精准捕获阶段性丢包与网络毛刺)
mkdir -p "$TMP_DIR/samples"
local seq
for seq in $(seq 1 "$sample_count"); do
while read -r ip; do
[ -z "$ip" ] && continue
@@ -518,6 +523,7 @@ run_optimization() {
mkdir -p "$(dirname "$HOSTS_FILE")"
> "$hosts_tmp"
echo "# Auto-generated by cf-optimizer on $(date '+%Y-%m-%d %H:%M:%S')" >> "$hosts_tmp"
local d
for d in $domains; do
echo "$final_ip $d" >> "$hosts_tmp"
done
@@ -609,6 +615,7 @@ apply_fast_failover() {
mkdir -p "$(dirname "$HOSTS_FILE")"
> "$hosts_tmp"
echo "# Auto-generated by cf-optimizer failover on $(date '+%Y-%m-%d %H:%M:%S')" >> "$hosts_tmp"
local d
for d in $domains; do
echo "$target_ip $d" >> "$hosts_tmp"
done
@@ -758,8 +765,9 @@ check_health_and_failover() {
}
daemon_loop() {
mkdir -p "$RUN_DIR"
echo $$ > "$PID_FILE"
trap 'rm -f "$PID_FILE"; exit 0' INT TERM EXIT
trap 'rm -f "$PID_FILE"; [ -f "$RUN_DIR/task.lock/pid" ] && [ "$(cat "$RUN_DIR/task.lock/pid" 2>/dev/null)" = "$$" ] && rm -rf "$RUN_DIR/task.lock"; exit 0' INT TERM EXIT
log "守护进程启动 [PID: $$]"