- All Implemented Interfaces:
IncomingConnectionFilter, StatefulConnectionFilter
Tracks known destinations (defined in access lists) and unknown destinations (recently attempted connections). Reloads access lists from disk when modified to allow user edits. Writes recorder data to disk at intervals when new threshold breaches occur.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classTimer purging the expired entries.(package private) static final classParsed recorder file plus the(lastModified, length)signature it was read under.private classTimer writing the filter to disk.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final I2PAppContextThe app context.private final FilterDefinitionThe definition the filter was built from.private static final ExecutorServiceAll disk i/o from all instances of this filter happen on this thread (apart from initial load).private final Map<Hash, DestTracker> Trackers for known destinations defined in access lists.private static final intDestinations remembered between the writes.private static final longInterval between the expired entry purges.private final Map<File, AccessFilter.RecorderFileState> Per-recorder file read cache; keyed by the persisted breach file and only touched on the single DISK_WRITER thread insiderecord(), so no locking is required.private static final longInterval between the writes to disk.private AccessFilter.SyncerThe timer writing the filter to disk.private final AtomicBooleanTrue while the purge and sync timers run.private final Map<Hash, DestTracker> Trackers for unknown destinations not defined in access lists.Fields inherited from interface IncomingConnectionFilter
ALLOW, DENYModifier and TypeFieldDescriptionstatic final IncomingConnectionFilterUtility implementation that allows all incoming connections.static final IncomingConnectionFilterUtility implementation that denies all incoming connections.Constructor Summary
ConstructorsConstructorDescriptionAccessFilter(I2PAppContext context, FilterDefinition definition) Create a new access filter.Method Summary
Modifier and TypeMethodDescriptionbooleanDetermines if a connection to the given destination should be allowed.private voidpurge()Drops the expired entries from the filter.(package private) static AccessFilter.RecorderFileStatereadRecorderFile(File file) Read the persisted breached-b32 set for a recorder file, capturing its(lastModified, length)signature at read time.private voidrecord()Writes the recorded connections to disk.(package private) static booleanrecorderFileUnchanged(AccessFilter.RecorderFileState cached, File file) Whether a recorder file's on-disk signature still matches the one captured whencachedwas read, i.e.private voidreload()Re-reads the filter definitions from disk.private static voidStops the timer writing the filter to disk.voidstart()Starts the filter's background tasks.voidstop()Stops the filter's background tasks.
Field Details
PURGE_INTERVAL
private static final long PURGE_INTERVALInterval between the expired entry purges.- See Also:
SYNC_INTERVAL
private static final long SYNC_INTERVALInterval between the writes to disk.- See Also:
MAX_STORED_DESTS
private static final int MAX_STORED_DESTSDestinations remembered between the writes.- See Also:
DISK_WRITER
All disk i/o from all instances of this filter happen on this thread (apart from initial load).definition
The definition the filter was built from.context
The app context.timersRunning
True while the purge and sync timers run.recorderFiles
Per-recorder file read cache; keyed by the persisted breach file and only touched on the single DISK_WRITER thread insiderecord(), so no locking is required.knownDests
Trackers for known destinations defined in access lists.unknownDests
Trackers for unknown destinations not defined in access lists.syncer
The timer writing the filter to disk.
Constructor Details
AccessFilter
AccessFilter(I2PAppContext context, FilterDefinition definition) throws IOException Create a new access filter.- Parameters:
context- the context, used for scheduling and timer purposesdefinition- definition of this filter- Throws:
IOException- if an I/O error occurs
Method Details
shutdownDiskWriter
private static void shutdownDiskWriter()Stops the timer writing the filter to disk.start
public void start()Starts the filter's background tasks.Initializes the purger and syncer timers to begin tracking connection attempts and periodically saving state to disk.
- Specified by:
startin interfaceStatefulConnectionFilter
stop
public void stop()Stops the filter's background tasks.Halts the purger and syncer timers. Existing connection data is retained until the next purge cycle.
- Specified by:
stopin interfaceStatefulConnectionFilter
allowDestination
Determines if a connection to the given destination should be allowed.Checks the destination against known and unknown destination trackers. If the destination has exceeded its threshold for the current time window, the connection is denied. Unknown destinations start with the default threshold.
- Specified by:
allowDestinationin interfaceIncomingConnectionFilter- Parameters:
d- the destination to check- Returns:
- true if the connection should be allowed, false if denied
reload
Re-reads the filter definitions from disk.- Throws:
IOException- if the definitions cannot be read
record
Writes the recorded connections to disk.- Throws:
IOException- if the records cannot be written
readRecorderFile
Read the persisted breached-b32 set for a recorder file, capturing its(lastModified, length)signature at read time.The set is the plain set of lines in the file (raw b32 strings); no parsing is done, matching the historic reader. A missing or non-file yields an empty set with
valid == falseso a later appearance of the file is detected as a change.- Parameters:
file- the breach recorder file- Returns:
- the read set plus its signature
- Throws:
IOException- on an error reading the file
recorderFileUnchanged
Whether a recorder file's on-disk signature still matches the one captured whencachedwas read, i.e. whether the cached breached set can be reused without opening the file again.The recorder file is almost always written only by this filter, so on the 5-second sync cycle the file is unchanged and the set is reused. External edits (recreating the file) change the signature and force a re-read, so user changes are still picked up. Misses on a missing file are reported as unchanged so an absent file does not re-read either.
- Parameters:
cached- the previousAccessFilter.RecorderFileState, or null on first usefile- the breach recorder file- Returns:
- true if
cached.breachedis still current
purge
private void purge()Drops the expired entries from the filter.