Skip to content

clash-api: Fix flushing FakeIP cache - #13

Merged
reF1nd merged 95 commits into
reF1nd:reF1nd-testing-nextfrom
moonfruit:clash-api-fakeip-flush
Sep 24, 2026
Merged

reF1nd merged 95 commits into
reF1nd:reF1nd-testing-nextfrom
moonfruit:clash-api-fakeip-flush

Conversation

@moonfruit

Copy link
Copy Markdown

POST /cache/fakeip/flush reset the cache file directly instead of going through the FakeIP store:

  • With store_fakeip disabled or without a cache file, mappings live in the in-memory storage and were never cleared.
  • DeleteBucket fails with bucket not found for buckets that were never created (e.g. the IPv6 domain bucket when only IPv4 is used, or all of them with store_fakeip disabled), so the request returned 500 even when the mappings were cleared.

Changes:

  • The handler resets through DNSTransportManager.FakeIP().Store(), so both storages are cleared.
  • Store.Reset (previously unused) now also restarts allocation from the beginning of the ranges and saves the metadata, under the allocation lock.
  • CacheFile.FakeIPReset ignores missing buckets.

Tested with unit tests for the store and the cache file, and manually with no cache file, store_fakeip: false and store_fakeip: true: the flush returns 204 and allocation restarts from 198.18.0.2 in all three cases.

The official anytls code is of poor quality and consumes excessive memory
Changes to the cache file are collected in a write buffer and written in
one transaction when the buffer reaches buffer_size, when the OOM killer
releases memory, or when sing-box is closed. An optional flush_interval
writes the buffer periodically. Previously each DNS response, RDRC entry
and FakeIP mapping was committed in its own transaction.

Also open the database with NoFreelistSync, and mark store_rdrc and
rdrc_timeout as deprecated in the options.
reF1nd and others added 27 commits September 18, 2026 13:17
Co-authored-by: jebbs <[email protected]>
Co-authored-by: PuerNya <[email protected]>
(cherry picked from commit rnetx@e98000c)
makes remote rule-set `path` correct
…elds

Add TCPKeepAliveCount to ListenOptions (inbound) and apply it in
listener_tcp.go, complementing the existing outbound-only support.

Also move TCPKeepAliveCount in DialerOptions to sit next to other
TCP keepalive fields for consistency.
The handler reset the cache file directly, so mappings kept in memory
(store_fakeip disabled or no cache file) were never cleared, and a
missing bucket turned the request into a 500. Reset through the FakeIP
store instead, which now also restarts allocation from the beginning of
the ranges, and ignore missing buckets in the cache file.
@reF1nd
reF1nd force-pushed the reF1nd-testing-next branch from 9e5ea21 to 137440a Compare September 24, 2026 03:32
@reF1nd
reF1nd merged commit 804e1dd into reF1nd:reF1nd-testing-next Sep 24, 2026
Delusions6515 pushed a commit to Delusions6515/sing-box that referenced this pull request Sep 28, 2026
… 6258)

Дефолтный session id — дашед-UUID: 36 символов, hex, дефисы на фиксированных
позициях, а в packet-up к нему приклеивается инкрементный /0, /1, /2. Отпечаток
узнаётся регуляркой. Две новые опции заменяют его случайной строкой заданного
вида: session_table (имя предопределённого алфавита или свой ASCII-набор) +
session_length ("min-max" или "n").

Ручка чисто клиентская: сервер видит session id как непрозрачный ключ
группировки, согласование не нужно, Xray-сервер принимает любую форму. Дефолт
не изменился — без этих полей id остаётся UUID, как и у ненастроенного Xray.

Отход от Xray, осознанный: половинчатую конфигурацию (одна опция из двух)
отвергаем с ошибкой, а не вырождаемся молча в UUID — иначе написавший
session_table без session_length получил бы ровно то, от чего уходил, и заметил
бы только по проводу. Валидация: пол длины > 0, пространство id (len^min) > 2^31,
алфавит ASCII.

Имена полей по нашей конвенции (session_placement/session_key), не по
Xray-camelCase; Xray-имена указаны в доках для поиска.

Вопрос из issue reF1nd#13; апстрим — XTLS/Xray-core#6258.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.