java.lang.Object
i2p.susi.dns.BaseBean
i2p.susi.dns.BlacklistBean

public class BlacklistBeanextends BaseBean
Bean for managing address book blacklist entries. Supports hostnames, b32, and b64 addresses.
  • Field Details

    • fileName

      private String fileName
      Path of the blacklist file.
    • content

      private String content
      The blacklist contents read from the file.
    • cachedContent

      private static String cachedContent
      Contents shared between requests until the file changes.
    • lastModified

      private static long lastModified
      Modification time of the file the cache was read at.
    • _lines

      private List<String> _lines
      Trimmed lines of the current content, rebuilt when content changes.
    • BLACKLIST_FILE

      private static final String BLACKLIST_FILE
      Name of the blacklist file in the router directory.
      See Also:
    • _log

      private static final Log _log
      Logger for this class.
    • I2P_ADDRESS_PATTERN

      private static final Pattern I2P_ADDRESS_PATTERN
      Pattern to validate I2P addresses (hostnames, b32, b64). b64 destinations vary with key type: EdDSA ~128 chars, DSA 516 chars.
  • Constructor Details

    • BlacklistBean

      public BlacklistBean()
      Blacklist bean for address blacklisting.
  • Method Details

    • getFileName

      public String getFileName()
      Blacklist file path.
      Returns:
      the absolute path to the blacklist file
    • blacklistFile

      private File blacklistFile()
      The file holding the host blacklist.
      Returns:
      blacklist.txt in the addressbook directory
    • reloadBlacklist

      private void reloadBlacklist()
      Reload blacklist from file.
    • locked_reloadBlacklist

      private void locked_reloadBlacklist()
      Reload blacklist from file (synchronized wrapper).
    • save

      private void save()
      Save blacklist to file.
    • locked_save

      private void locked_save()
      Save blacklist to file (synchronized wrapper).
    • isValidI2PAddress

      private boolean isValidI2PAddress(String address)
      Check if an address is a valid I2P address.
      Parameters:
      address - the string to test for I2P address format
      Returns:
      true if the address is a valid I2P address format, false otherwise
    • isBlacklisted

      public boolean isBlacklisted(String address)
      Check if an address is blacklisted.
      Parameters:
      address - the b32 address to look up, compared case-insensitively
      Returns:
      true if the address is in the blacklist, false otherwise
    • isHostnameBlacklisted

      public boolean isHostnameBlacklisted(String hostname)
      Check if a hostname is blacklisted (exact match).
      Parameters:
      hostname - the hostname to look for an exact match on
      Returns:
      true if the hostname is in the blacklist, false otherwise
    • isB32Blacklisted

      public boolean isB32Blacklisted(String b32)
      Check if a b32 address is blacklisted (exact match or hostname match).
      Parameters:
      b32 - the b32 address to check
      Returns:
      true if the b32 address or its resolved hostname is in the blacklist, false otherwise
    • isB64Blacklisted

      public boolean isB64Blacklisted(String b64)
      Check if a b64 address is blacklisted (exact match or hostname/b32 match).
      Parameters:
      b64 - the b64 address to check
      Returns:
      true if the b64 address or its resolved names are in the blacklist, false otherwise
    • isBlacklistedByAnyForm

      public boolean isBlacklistedByAnyForm(String address)
      Enhanced blacklist check that tries hostname, b32, and b64 variations.
      Parameters:
      address - the address to try as hostname, b32 and b64 in turn
      Returns:
      true if the address is found in the blacklist in any form, false otherwise
    • getMessages

      public String getMessages()
      Status messages for the UI.
      Returns:
      HTML formatted status message
    • setContent

      public void setContent(String content)
      Set the blacklist content.
      Parameters:
      content - the new blacklist content
    • getContent

      public String getContent()
      Current blacklist content.
      Returns:
      the blacklist content, or empty string if not loaded
    • addEntries

      public int addEntries(List<String> entries)
      Add entries to the blacklist.
      Parameters:
      entries - List of hostnames or addresses to add to the blacklist
      Returns:
      Number of entries successfully added
    • loadContentFromFile

      private String loadContentFromFile()
      Load content directly from file, bypassing cache.
      Returns:
      the file contents as a string, or empty string if file doesn't exist
    • isEntryInContent

      private boolean isEntryInContent(String entry, String content)
      Check if an entry exists in the given content string.
      Parameters:
      entry - the entry to search for
      content - the newline-separated blacklist text to scan
      Returns:
      true if the entry is found, false otherwise
    • appendEntriesToFile

      private void appendEntriesToFile(List<String> newEntries, String currentContent)
      Append new entries to file.
      Parameters:
      newEntries - the entries to add
      currentContent - the current content of the file