class ConnectionManager extends Object
| Modifier and Type | Class and Description |
|---|---|
static interface | ConnectionManager.PingNotifierThe callback interface for a pong. |
| Modifier and Type | Field and Description |
|---|---|
static String | PROP_BLACKLISTBlacklist property for streaming. |
(package private) static String | PROP_MAX_PONG_DELAYProperty: maximum pong delay in ms. |
| Constructor and Description |
|---|
ConnectionManager(I2PAppContext context,
I2PSession session,
ConnectionOptions defaultOptions,
IncomingConnectionFilter connectionFilter)Manage all conns for this session |
| Modifier and Type | Method and Description |
|---|---|
boolean | answerPings()Do we respond to pings that aren't on an existing connection? |
(package private) void | cleanupPool()Periodic pool cleanup — evicts stale connections. |
Connection | connect(Destination peer,
ConnectionOptions opts,
I2PSession session)Build a new connection to the given peer. |
void | disconnectAllHard()Something b0rked hard, so kill all of our connections without mercy. |
boolean | getAllowIncomingConnections()Whether incoming connections are accepted. |
(package private) Connection | getConnectionByInboundId(long id)Look up a connection by its inbound stream ID. |
(package private) Connection | getConnectionByOutboundId(long id)Look up a connection by its outbound stream ID. |
ConnectionHandler | getConnectionHandler()Connection handler for this manager. |
MessageHandler | getMessageHandler()Message handler for this manager. |
PacketHandler | getPacketHandler()Packet handler for this manager. |
PacketQueue | getPacketQueue()Outbound packet queue. |
I2PSession | getSession()This is the primary session only |
long | getSoTimeout()Socket accept() timeout. |
Set<Connection> | listConnections()Connections currently managed. |
boolean | ping(Destination peer,
int fromPort,
int toPort,
long timeoutMs)Ping the destination and wait for a pong. |
boolean | ping(Destination peer,
int fromPort,
int toPort,
long timeoutMs,
boolean blocking)Ping the destination, optionally waiting for a pong. |
boolean | ping(Destination peer,
int fromPort,
int toPort,
long timeoutMs,
boolean blocking,
ConnectionManager.PingNotifier notifier)Ping the destination, optionally waiting for a pong. |
byte[] | ping(Destination peer,
int fromPort,
int toPort,
long timeoutMs,
byte[] payload)Ping the destination with a payload and wait for the pong. |
boolean | ping(Destination peer,
long timeoutMs)Ping the destination and wait for a pong. |
Connection | receiveConnection(Packet synPacket)Create a new connection based on the SYN packet we received. |
boolean | receivePing(Connection con,
Packet ping)Process a ping by checking for throttling, etc., then sending a pong. |
(package private) void | receivePong(long pingId,
ByteArray payload)Process a received pong response. |
(package private) void | registerOutboundId(Connection con)Register outbound id. |
void | removeConnection(Connection con)Remove a connection from the manager. |
void | setAllowIncomingConnections(boolean allow)Enable or disable acceptance of incoming connections. |
void | setSoTimeout(long x)Socket accept() timeout. |
void | shutdown()Kill all connections and the timers. |
String | toString() |
void | updateOptions()Update the throttler options |
void | updateOptsFromShare(Connection con)Update opts from share. |
void | updateShareOpts(Connection con)Update share opts. |
boolean | wasRecentlyClosed(long inboundID)Was this conn recently closed? |
public static final String PROP_BLACKLIST
static final String PROP_MAX_PONG_DELAY
public ConnectionManager(I2PAppContext context, I2PSession session, ConnectionOptions defaultOptions, IncomingConnectionFilter connectionFilter)
context - the I2P app contextsession - the primary session, packets may come in on subsessions alsodefaultOptions - the default connection optionsconnectionFilter - the incoming connection filterpublic boolean answerPings()
void cleanupPool()
public Connection connect(Destination peer, ConnectionOptions opts, I2PSession session)
peer - Destination to contact, non-nullopts - Connection's optionssession - generally the session from the constructor, but could be a subsessionpublic void disconnectAllHard()
public boolean getAllowIncomingConnections()
Connection getConnectionByInboundId(long id)
id - the inbound stream IDConnection getConnectionByOutboundId(long id)
id - the outbound stream IDpublic ConnectionHandler getConnectionHandler()
public MessageHandler getMessageHandler()
public PacketHandler getPacketHandler()
public PacketQueue getPacketQueue()
public I2PSession getSession()
public long getSoTimeout()
public Set<Connection> listConnections()
public boolean ping(Destination peer, int fromPort, int toPort, long timeoutMs)
peer - the destinationfromPort - the source porttoPort - the destination porttimeoutMs - greater than zeropublic boolean ping(Destination peer, int fromPort, int toPort, long timeoutMs, boolean blocking)
peer - the destinationfromPort - the source porttoPort - the destination porttimeoutMs - greater than zeroblocking - true to block until pongpublic boolean ping(Destination peer, int fromPort, int toPort, long timeoutMs, boolean blocking, ConnectionManager.PingNotifier notifier)
peer - the destinationfromPort - the source porttoPort - the destination porttimeoutMs - greater than zeroblocking - true to block until pongnotifier - may be nullpublic byte[] ping(Destination peer, int fromPort, int toPort, long timeoutMs, byte[] payload)
peer - the destinationfromPort - the source porttoPort - the destination porttimeoutMs - greater than zeropayload - non-null, include in packet, up to 32 bytes may be returned in pong
not copied, do not modifypublic boolean ping(Destination peer, long timeoutMs)
peer - the destinationtimeoutMs - greater than zeropublic Connection receiveConnection(Packet synPacket)
synPacket - SYN packet to processpublic boolean receivePing(Connection con, Packet ping)
con - null if unknownping - Ping packet to process, must have From and Sig fields,
with signature already verified, only if answerPings() returned truevoid receivePong(long pingId,
ByteArray payload)pingId - the ping stream ID to matchpayload - the pong payload, may be nullvoid registerOutboundId(Connection con)
public void removeConnection(Connection con)
con - Connection to drop.public void setAllowIncomingConnections(boolean allow)
allow - true to accept incoming connectionspublic void setSoTimeout(long x)
x -public void shutdown()
public void updateOptions()
public void updateOptsFromShare(Connection con)
con - the connectionpublic void updateShareOpts(Connection con)
con - the connectionpublic boolean wasRecentlyClosed(long inboundID)