java.lang.Object
net.i2p.router.web.helpers.BanlistRenderer
Renders HTML display of banned routers for the router console. Displays banlist entries including expiration times, reasons, and provides management interface for router bans. Moved from Banlist.java for separation of concerns.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classEntry for IP-only bans from sessionbans.txt.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final RouterContextThe router context.private static final PatternPattern normalizing an IP or hostname for display.private static final intLength of the truncated base64 hash used as a per-row data-key in fragment mode; 16 chars = 96 bits, collision-free at 10K-20K rows.private static final intRender rows in a single write up to this count; above it, flush everySTREAM_BATCHrows so the page paints progressively.private static final PatternPattern splitting a ban record on the pipes.private static final intRows rendered per flush when streaming a large table.private static final PatternPattern extracting the version numbers from a string.private static final PatternPattern matching the local update suffix of a version.private static final PatternPattern matching the leading junk of a version string.private static final PatternPattern matching the trailing junk of a version string.Constructor Summary
ConstructorsConstructorDescriptionBanlistRenderer(RouterContext context) Stores the router context used to reach the banlist and network database.Method Summary
Modifier and TypeMethodDescriptionprivate StringTranslate a string.private StringTranslate a string with a parameter This is a lot more expensive than _t(s), so use sparingly.private StringcleanReason(String reason, String routerVersion) Rewrites a ban reason for display.intCount active bans of floodfill-capable peers, matching the banFF classification used byrenderBanlist(Writer, boolean): caps from the session log or netdb, or a "floodfill" cause.private StringExtract IP address from IP:PORT format.private StringextractPort(String ipPort) Extract port from IP:PORT format.private StringgetRouterCaps(Hash hash) Get router capabilities string from NetDB.private StringgetRouterVersion(Hash hash, String reason) Router version for a banned hash, from NetDB or parsed out of the ban reason.private longparseDuration(String durationStr, long now) Parse duration string to expiration timestamp.private Object[]Read sessionbans.txt once and build all three data structures in a single pass.private voidrenderBanlist(Writer out, boolean fragmentKeys) Render the compact banlist table; bothrenderBanlistCompact(Writer)andrenderBanlistFragment(Writer)delegate here.voidRender the compact banlist HTML table.voidRender only the<tbody id=sessionBanlist>for the contentonly fragment mode, with a data-key per row for the worker-side row diff.private StringreverseLookup(String ip) Looks up the hostname for a banned IP.
Field Details
_context
The router context.IP_HOSTNAME_NORMALIZE
Pattern normalizing an IP or hostname for display.PIPE_SPLIT
Pattern splitting a ban record on the pipes.VERSION_LU_SUFFIX
Pattern matching the local update suffix of a version.VERSION_SUFFIX
Pattern matching the trailing junk of a version string.VERSION_PREFIX
Pattern matching the leading junk of a version string.VERSION_EXTRACT
Pattern extracting the version numbers from a string.MAX_BEFORE_STREAMING
private static final int MAX_BEFORE_STREAMINGRender rows in a single write up to this count; above it, flush everySTREAM_BATCHrows so the page paints progressively.- See Also:
STREAM_BATCH
private static final int STREAM_BATCHRows rendered per flush when streaming a large table.- See Also:
KEY_LEN
private static final int KEY_LENLength of the truncated base64 hash used as a per-row data-key in fragment mode; 16 chars = 96 bits, collision-free at 10K-20K rows.- See Also:
Constructor Details
BanlistRenderer
Stores the router context used to reach the banlist and network database.- Parameters:
context- the router context
Method Details
reverseLookup
readSessionBans
Read sessionbans.txt once and build all three data structures in a single pass. Replaces the three separate readSessionBans* methods that each opened the file independently.- Returns:
- array of [Map<String,String> ipMap, Map<String,String> hostnameMap, List<IPBanEntry> ipOnlyBans]
extractIP
extractPort
parseDuration
Parse duration string to expiration timestamp.- Parameters:
durationStr- the duration to parse, e.g. "7d", "12h", "30m", "500ms" or "FOREVER"now- the current time in ms the expiration is based on- Returns:
- the expiration time in ms; FOREVER means 180 days out, an unparseable or unit-less value means now
renderBanlistCompact
Render the compact banlist HTML table.- Parameters:
out- the writer to render to- Throws:
IOException- if writing fails
countBannedFloodfills
public int countBannedFloodfills()Count active bans of floodfill-capable peers, matching the banFF classification used byrenderBanlist(Writer, boolean): caps from the session log or netdb, or a "floodfill" cause.- Returns:
- how many active bans are floodfills
renderBanlistFragment
Render only the<tbody id=sessionBanlist>for the contentonly fragment mode, with a data-key per row for the worker-side row diff. The full page keeps the wrapper div, thead, and tfoot.- Parameters:
out- the writer to render to- Throws:
IOException- if writing fails
renderBanlist
Render the compact banlist table; bothrenderBanlistCompact(Writer)andrenderBanlistFragment(Writer)delegate here.- Parameters:
out- the writer to render tofragmentKeys- when true, emit only the tbody with data-key rows- Throws:
IOException- if writing fails
_t
_t
Translate a string with a parameter This is a lot more expensive than _t(s), so use sparingly.- Parameters:
s- string to be translated containing {0} The {0} will be replaced by the parameter. Single quotes must be doubled, i.e. ' -> '' in the string.o- parameter, not translated. To translate parameter also, use _t("foo {0} bar", _t("baz")) Do not double the single quotes in the parameter. Use autoboxing to call with ints, longs, floats, etc.- Returns:
- the translated string with the first {0} replaced by the parameter
getRouterVersion
Router version for a banned hash, from NetDB or parsed out of the ban reason.- Parameters:
hash- the router hash to look up, null yields no versionreason- the ban reason string, searched for a version pattern- Returns:
- the version string, or null if neither source carries one
getRouterCaps
cleanReason