Repository navigation
feat(utilities): one config module for the tunable limits (PCAPKIT_* environment variables), and one home per duplicated protocol constant #1726
Copy link
Copy link
Closed
Labels
breakingBreaks public-facing behaviour or API (apply alongside the type label)Breaks public-facing behaviour or API (apply alongside the type label)featPull requests that add a new capability (feat: subject prefix)Pull requests that add a new capability (feat: subject prefix)
Description
Is your feature request related to a problem? Please describe.
The last four weeks added eight tunable limits and about 27 protocol constants, many duplicated across modules (asked in chat). Measured on main (6aeba80e8):
- Tunables:
FRAME_LAYER_LIMIT(64),EXTENSION_HEADER_LIMIT(32),IPV6_TCP_WARNED_LIMIT(32),dumpkit.common.FALLBACK_LIMIT,chardet.DETECT_CACHE_SIZE,corekit.io._READ_CHUNK, and the zero-pad guards incorekit/fields/field.py. OnlyPCAPKIT_DEVMODE,_VERBOSEand_SPHINXare environment variables today.PCAPKIT_VENDOR_RETRY(which crashes the import on a non-integer) andPCAPKIT_CI_MODEare undocumented. - Overrides don't propagate:
ipv6.py:38-40,toolkit/dpkt.py,scapy.pyandpypcapfile.pycopy the two layer limits withfrom ... import. Changing the defining module therefore leaves those readers on the old value. - Duplicates: about 25 bare µs/ns resolution literals across four packages; the IPv4 (20), IPv6 (40) and TCP (20) header lengths in up to four places each, including a bare
20intoolkit/pcap.py:178; PCAP and PCAP-NG magics; and two overlapping PCAP-NG minimum-block tables.
Describe the solution you'd like
- New module: a stdlib-only
pcapkit/utilities/config.py. It reads everyPCAPKIT_*variable once at import, validates each one, and holds the tunables.utilitiesis the only cycle-free home:corekit.fields.stringsimportsutilities.chardet, so acorekitmodule would loop. - Readers: consumers read
config.<NAME>at call time, with nofrom ... importcopies, so one value reaches every engine. - Naming and docs: variables are named
PCAPKIT_<NAME>, with one.. envvar::list in the docs. - Protocol constants: they stay fixed. Each moves to its owning protocol module (IPv4/IPv6/TCP lengths, PCAP and PCAP-NG magics), or to a single resolution pair.
- Sequencing: this comes after the refactor(toolkit): revert the cross-engine agreement tests and the adapter code that only mirrors the default engine #1708 dpkt and scapy reverts, which delete about ten of the duplicates.
Describe alternatives you've considered
- A runtime
config.configure(), likelogging.configure, as a follow-up. - Per-
Extractorarguments.context.py:20-29avoided protocol-specific keyword arguments.
Additional context, the decisions I need from you:
- No re-export: does the refactor(corekit)!: move the byte-order field helpers into corekit (#1711) #1715 no-re-export rule apply? Moving a constant would remove names such as
pcapkit.protocols.protocol.FRAME_LAYER_LIMIT. That is a breaking change with a!. The alternative is to keep each definition where it is and centralise only the environment read. - Raising a limit: raising
FRAME_LAYER_LIMITpast 64 reopens fix(protocols): deep layer nesting of any protocol exhausts the recursion limit and loses TCP silently #1610'sRecursionError. Should a higher value be refused, capped, or allowed with a documented risk? - Bad values: should an invalid value warn and fall back to the default, or raise at import?
- Vendor variables: should
PCAPKIT_VENDOR_RETRY,_CI_MODEand_HTTP(S)_PROXYmove into the module too?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
breakingBreaks public-facing behaviour or API (apply alongside the type label)Breaks public-facing behaviour or API (apply alongside the type label)featPull requests that add a new capability (feat: subject prefix)Pull requests that add a new capability (feat: subject prefix)
Projects
- StatusShow more project fieldsDone
Activity
JarryShaw commentedon Oct 14, 2026
-1as no limit. add document for the risks.JarryShaw commentedon Oct 14, 2026
Recorded:
!.-1means no limit. The docs state the risk: past the default, a deep frame can hit Python's recursion limit, as in fix(protocols): deep layer nesting of any protocol exhausts the recursion limit and loses TCP silently #1610.warningsmodule, because pcapkit's ownwarnimportsloggingand would cycle back into the config module.PCAPKIT_VENDOR_RETRY,_CI_MODEand_HTTP(S)_PROXYmove, and each one gets documented.This is blocked until the #1708 dpkt and scapy reverts merge: #1724, and the dpkt PR that follows it. Both rewrite the limit readers in
toolkit/dpkt.pyandscapy.pythat this change has to switch toconfig.<NAME>.JarryShaw commentedon Oct 14, 2026
-1and values over64as wellJarryShaw commentedon Oct 14, 2026
Recorded for 2: setting a limit to
-1, or above its default (64 for the frame-layer limit), also warns, and the warning names theRecursionErrorrisk.For 3, yes, with one layout constraint.
pcapkit.utilities.warningsimports onlyexceptionsandlogging(warnings.py:64-65), soconfigcan import it as long asloggingdoes not importconfig. So:PCAPKIT_DEVMODE,_VERBOSEand_SPHINXstay inutilities/logging.py.warningsneeds them while it is still loading.warnoncewarningshas finished loading.test_logging.py:60-69pins that. That test would change.utilities/config.py, which importspcapkit.utilities.warningsdirectly: the limits, the caches and the vendor variables. Each bad or risky value warns through a newConfigWarning(BaseWarning, RuntimeWarning), so devmode and the existing filters apply as usual.Say if the three logging flags should move into
configas well. That works too, but only if every warning is deferred untilpcapkit/__init__.pyfinishes importing.JarryShaw commentedon Oct 14, 2026
whats your recommendation?
14 remaining items
JarryShaw commentedon Oct 14, 2026
take all defaults.
JarryShaw commentedon Oct 14, 2026
Recorded: all three defaults stand. Scapy's
_READ_CHUNKstays unconfigurable. The proxy variables are still read on every call. Every limit raised above its default, or set to-1, warns about its own risk. Round 2, already running, implements exactly these.docs(toolkit): drop agreement claims from adapter docstrings (#1708) (#…
feat(utilities)!: one config module for the tunable limits (#1726) (#…
JarryShaw commentedon Oct 14, 2026
actually, on second thoughts,
vendor's envvars keep invendor, they dont move toutilities.configJarryShaw commentedon Oct 14, 2026
Recorded: the vendor variables stay in
pcapkit.vendor. #1743 has already merged with them inconfig, so a follow-up PR moves them back. Defaults below, unless you say otherwise:pcapkit.vendor.default.MAX_RETRY(PCAPKIT_VENDOR_RETRY) andCI_MODE(PCAPKIT_CI_MODE) return under their original names. This undoes feat(utilities)!: one config module for the tunable limits (#1726) #1743's removal of those two names, along with itsversionremovednotes.get_proxies()readsPCAPKIT_HTTP_PROXYandPCAPKIT_HTTPS_PROXYitself, on every call, as before.ConfigWarningand falls back. The parsing helpers become public inconfigsovendorcan reuse them without reaching into private names.config.VENDOR_RETRY,config.CI_MODE,config.http_proxyandconfig.https_proxyare removed outright. They never shipped in a release, so they get noversionremoved.config.rstlinks there.Ruling 7 (#1739) is unaffected and is in progress.
refactor(vendor): keep the vendor variables in pcapkit.vendor (#1726)
refactor(vendor): keep the vendor variables in pcapkit.vendor (#1726) (…
JarryShaw commentedon Oct 15, 2026
All of this has now landed:
pcapkit.vendor(the 22:28Z reversal): refactor(vendor): keep the vendor variables in pcapkit.vendor (#1726) #1745.mainas3946bf527.Closing.
docs(foundation): second pass over engines, toolkit and reassembly (#…