public class I2PTunnelHTTPServer extends I2PTunnelServer
Extends I2PTunnelServer to filter HTTP headers from client to server, replacing the Host header with configured value. Compresses HTTP message body and sets Content-Encoding: x-i2p-gzip when browser requests Accept-Encoding: x-i2p-gzip.
Features include POST/PUT rate limiting, referer and user-agent rejection, inproxy detection, HTTP blocklist support, keepalive management, and response header security filtering.
| Modifier and Type | Field and Description |
|---|---|
static int | DEFAULT_POST_BAN_TIMEPost throttle window (seconds). |
static int | DEFAULT_POST_MAXDefault max posts per window. |
static int | DEFAULT_POST_TOTAL_BAN_TIMEDefault total ban time for excessive posts. |
static int | DEFAULT_POST_TOTAL_MAXDefault max total posts before ban. |
static int | DEFAULT_POST_WINDOWDefault post rate-limit window (seconds). |
(package private) static String | ERR_FORBIDDEN403 Forbidden error response |
(package private) static String | ERR_NOT_FOUND404 Not Found error response |
protected static String | ERR_REQUEST_TIMEOUTHTTP 408 Request Timeout error response. |
static String | OPT_ADD_RESPONSE_HEADER_ALLOWConfig key to add Allow response header. |
static String | OPT_ADD_RESPONSE_HEADER_CACHE_CONTROLConfig key to add Cache-Control response header. |
static String | OPT_ADD_RESPONSE_HEADER_NOSNIFFConfig key to add X-Content-Type-Options: nosniff. |
static String | OPT_ADD_RESPONSE_HEADER_REFERRER_POLICYConfig key to add Referrer-Policy response header. |
static String | OPT_KEEPALIVEConfig key to enable keepalive. |
static String | OPT_POST_BAN_TIMEConfig key for post ban time. |
static String | OPT_POST_MAXConfig key for max posts. |
static String | OPT_POST_TOTAL_BAN_TIMEConfig key for post total ban time. |
static String | OPT_POST_TOTAL_MAXConfig key for max total posts. |
static String | OPT_POST_WINDOWConfig key for post check time window. |
static String | OPT_REJECT_INPROXYConfig key to reject requests from inproxy. |
static String | OPT_REJECT_REFERERConfig key to reject requests with Referer header. |
static String | OPT_REJECT_USER_AGENTSConfig key to reject specific User-Agents. |
static String | OPT_USER_AGENTSConfig key for User-Agent reject list. |
__serverId, _clientExecutor, _log, bidir, i2pss, l, localPort, PROP_ALT_PKF, PROP_UNIQUE_LOCAL, PROP_USE_SSL, readTimeout, remoteHost, remotePort, slock, sockMgr, sslLock, taskopen, tunnel| Constructor and Description |
|---|
I2PTunnelHTTPServer(InetAddress host,
int port,
File privkey,
String privkeyname,
String spoofHost,
Logging l,
EventDispatcher notifyThis,
I2PTunnel tunnel)Create an HTTP tunnel server from a private key file. |
I2PTunnelHTTPServer(InetAddress host,
int port,
InputStream privData,
String privkeyname,
String spoofHost,
Logging l,
EventDispatcher notifyThis,
I2PTunnel tunnel)Create an HTTP tunnel server from a private key stream. |
I2PTunnelHTTPServer(InetAddress host,
int port,
String privData,
String spoofHost,
Logging l,
EventDispatcher notifyThis,
I2PTunnel tunnel)Create an HTTP tunnel server with a private key string. |
| Modifier and Type | Method and Description |
|---|---|
(package private) static void | addEntry(Map<String,List<String>> headers,
String key,
String value)Add an entry to the multimap. |
protected void | blockingHandle(I2PSocket socket)Called by the thread pool of I2PSocket handlers. |
boolean | close(boolean forced)Close the tunnel and stop the POST throttler. |
protected static String | formatHeaders(Map<String,List<String>> headers,
StringBuilder command)Format headers as a string for transmission to the server. |
protected static String | formatHeadersCompact(Map<String,List<String>> headers,
StringBuilder command)Format headers as a compact string for logging. |
void | optionsUpdated(I2PTunnel tunnel)Called when tunnel options are updated. |
static Map<String,List<String>> | readHeaders(I2PSocket socket,
InputStream in,
StringBuilder command,
Set<String> skipHeaders,
I2PAppContext ctx,
long initialTimeout)From I2P to server: socket non-null, in null. |
static Map<String,List<String>> | readHeaders(I2PSocket socket,
InputStream in,
StringBuilder command,
String[] skipHeaders,
I2PAppContext ctx,
long initialTimeout)Read headers from the input stream, using an array of skip headers. |
(package private) static void | setEntry(Map<String,List<String>> headers,
String key,
String value)Remove the other matching entries and set this entry as the only one. |
void | startRunning()Start the tunnel and initialize timing and throttling. |
destroy, getReadTimeout, getSocket, getSocket, getSocketManager, getSocketString, run, setReadTimeoutconnected, disconnected, errorOccurred, getBooleanOption, getId, getTunnel, isOpen, reportAbuse, routerDisconnected, setId, setName, setTunnel, toStringattachEventDispatcher, detachEventDispatcher, getEventDispatcher, getEvents, getEventValue, ignoreEvents, notifyEvent, unIgnoreEvents, waitEventValuepublic static final int DEFAULT_POST_BAN_TIME
public static final int DEFAULT_POST_MAX
public static final int DEFAULT_POST_TOTAL_BAN_TIME
public static final int DEFAULT_POST_TOTAL_MAX
public static final int DEFAULT_POST_WINDOW
static final String ERR_FORBIDDEN
static final String ERR_NOT_FOUND
protected static final String ERR_REQUEST_TIMEOUT
public static final String OPT_ADD_RESPONSE_HEADER_ALLOW
public static final String OPT_ADD_RESPONSE_HEADER_CACHE_CONTROL
public static final String OPT_ADD_RESPONSE_HEADER_NOSNIFF
public static final String OPT_ADD_RESPONSE_HEADER_REFERRER_POLICY
public static final String OPT_KEEPALIVE
public static final String OPT_POST_BAN_TIME
public static final String OPT_POST_MAX
public static final String OPT_POST_TOTAL_BAN_TIME
public static final String OPT_POST_TOTAL_MAX
public static final String OPT_POST_WINDOW
public static final String OPT_REJECT_INPROXY
public static final String OPT_REJECT_REFERER
public static final String OPT_REJECT_USER_AGENTS
public static final String OPT_USER_AGENTS
public I2PTunnelHTTPServer(InetAddress host, int port, File privkey, String privkeyname, String spoofHost, Logging l, EventDispatcher notifyThis, I2PTunnel tunnel)
host - the local address to bind toport - the local portprivkey - the private key fileprivkeyname - the name for the private keyspoofHost - the hostname to spoof in the Host header, or nulll - the logging instancenotifyThis - the event dispatcher for notificationstunnel - the parent tunnel configurationpublic I2PTunnelHTTPServer(InetAddress host, int port, InputStream privData, String privkeyname, String spoofHost, Logging l, EventDispatcher notifyThis, I2PTunnel tunnel)
host - the local address to bind toport - the local portprivData - the input stream containing the private key dataprivkeyname - the name for the private keyspoofHost - the hostname to spoof in the Host header, or nulll - the logging instancenotifyThis - the event dispatcher for notificationstunnel - the parent tunnel configurationpublic I2PTunnelHTTPServer(InetAddress host, int port, String privData, String spoofHost, Logging l, EventDispatcher notifyThis, I2PTunnel tunnel)
host - the local address to bind toport - the local portprivData - the private key data as a Base64 stringspoofHost - the hostname to spoof in the Host header, or nulll - the logging instancenotifyThis - the event dispatcher for notificationstunnel - the parent tunnel configurationstatic void addEntry(Map<String,List<String>> headers, String key, String value)
headers - the header multimap to modifykey - the header namevalue - the header value to addprotected void blockingHandle(I2PSocket socket)
blockingHandle in class I2PTunnelServersocket - the incoming I2P socket from the clientI2PTunnelServer.getSocket(Hash, int),
I2PTunnelRunnerpublic boolean close(boolean forced)
close in class I2PTunnelServerforced - true to force closeprotected static String formatHeaders(Map<String,List<String>> headers, StringBuilder command)
headers - the header multimapcommand - the request line (e.g. "GET / HTTP/1.1")protected static String formatHeadersCompact(Map<String,List<String>> headers, StringBuilder command)
headers - the header multimapcommand - the request line (e.g. "GET / HTTP/1.1")public void optionsUpdated(I2PTunnel tunnel)
optionsUpdated in class I2PTunnelServertunnel - the tunnelpublic static Map<String,List<String>> readHeaders(I2PSocket socket, InputStream in, StringBuilder command, Set<String> skipHeaders, I2PAppContext ctx, long initialTimeout) throws IOException
socket - if null, use in as InputStreamin - if null, use socket.getInputStream() as InputStreamcommand - out parameter, first lineskipHeaders - MUST be lower caseSocketTimeoutException - if timeout is reached before newlineEOFException - if EOF is reached before newlineLineTooLongException - if one header too long, or too many headers, or total size too bigRequestTooLongException - if too longBadRequestException - on bad headersIOException - on other errors in the underlying streampublic static Map<String,List<String>> readHeaders(I2PSocket socket, InputStream in, StringBuilder command, String[] skipHeaders, I2PAppContext ctx, long initialTimeout) throws IOException
socket - if non-null, read from socket; otherwise read from inin - if non-null and socket is null, read from this streamcommand - output buffer for the first request lineskipHeaders - array of lower-case header names to filter outctx - I2P app context for clock and timeoutinitialTimeout - timeout for the first line readIOException - on I/O errorsstatic void setEntry(Map<String,List<String>> headers, String key, String value)
headers - the header multimap to modifykey - the header namevalue - the header value to set (replaces all existing values for this key)public void startRunning()
startRunning in class I2PTunnelServer