Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classCleanup task to remove this context from the static contexts list.Field Summary
FieldsModifier and TypeFieldDescriptionprivate RouterAppManagerManager of the router's internal apps.private FIFOBandwidthLimiterThe bandwidth limiter for transports.private BanlistThe banlist of bad routers.private BlocklistThe blocklist of bad networks.private ClientManagerFacadeManager of the I2CP client connections.private ClientMessagePoolPool of reusable client messages.private CommSystemFacadeThe transport and message comm system.private static final List<RouterContext> All live router contexts.private ECIESAEADEngineEngine for the ratchet encryption types.private ElGamalAESEngineEngine for the legacy ElGamal-AES encryption.Tasks run at the end of final shutdown.private GarlicMessageParserParser of garlic messages.private booleanTrue once the context components are built.private InNetMessagePoolPool of inbound network messages.private InternalClientManagerManager of the router's internal clients.private JobQueueQueue of scheduled router jobs.private KeyManagerManager of our session keys.private final ObjectLock for the first group of components.private final ObjectLock for the second group of components.private final ObjectLock for the third group of components.private MessageHistoryRecent message ids for duplicate detection.private OutboundMessageRegistryRegistry of outbound message handlers.private MessageValidatorValidator of inbound messages.private SegmentedNetworkDatabaseFacadeThe router's network database.private OutNetMessagePoolPool of outbound network messages.private PeerManagerFacadeManager of peer connections and tests.private ProfileManagerManager of the peer profiles.private ProfileOrganizerOrganizer of the peer profiles.private final RouterThe router object that created this context.private RouterKeyGeneratorGenerator of our routing keys.private StatisticsManagerPublisher of the router statistics.private RouterThrottleThe router's connection throttle.private TunnelDispatcherDispatcher of messages through tunnels.private TunnelManagerFacadeManager of the tunnel pools.Fields inherited from class I2PAppContext
_clock, _clockInitialized, _globalAppContext, _keyRing, _keyRingInitialized, _overrideProps, _sessionKeyManager, _sessionKeyManagerInitialized, _shutdownTasksModifier and TypeFieldDescriptionprotected ClockThe context clock, overridden in RouterContext.protected booleanWhether the clock is initialized, used in RouterContext.protected static I2PAppContextThe context that components without explicit root are bound.protected KeyRingThe key ring, overridden in RouterContext.protected booleanWhether the key ring is initialized, used in RouterContext.protected final I2PPropertiesOverride properties for this context.protected SessionKeyManagerThe session key manager.protected booleanWhether the session key manager has been initialized.Shutdown tasks to run on context shutdown.Constructor Summary
ConstructorsConstructorDescriptionRouterContext(Router router) Caller MUST callinitAll()after instantiation.RouterContext(Router router, Properties envProps) Caller MUST call initAll() after instantiation.RouterContext(Router router, Properties envProps, boolean doInit) Caller MUST call initAll() after instantiation.Method Summary
Modifier and TypeMethodDescriptionvoidaddFinalShutdownTask(Runnable task) Add a task to be run during final shutdown.voidAdd a callback for property changes.Coordinate this router's bandwidth limits.banlist()The banlist for managing banned peers.The blocklist for managing blocked peers.The RouterAppManager.How are we coordinating clients for the router?Where do we toss messages for the clients (and where do we get client messages to forward on from)?clientNetDb(Hash id) The client netDb for the given id.How do we pass messages from our outNetMessagePool to another router.Access the ECIES/AEAD engine for this context.Access the ElGamal/AES+SessionTag engine for this context.private static final PropertiesfilterProps(Properties envProps) Properties where the defaults must be different from those inI2PAppContext.The garlic message parser for this context.(package private) static List<RouterContext> Same aslistContexts()but package private and modifiable.longHow long this router was down before it started, or 0 if unknown.The set of final shutdown tasks.New Properties with system and context properties.getProperty(String propName) Tie in the router's config as properties, as well as whatever the I2PAppContext says.intgetProperty(String propName, int defaultVal) Return an int with an int default.longgetProperty(String propName, long defaultVal) Return a long with a long default.getProperty(String propName, String defaultVal) Tie in the router's config as properties, as well as whatever the I2PAppContext says.voidinitAll()The following properties may be used to replace various parts of the context with dummy implementations for testing, by setting the property to "true":protected voidInitialize the clock.protected voidInitialize the key ring.protected voidCreate the session key manager for the router, picking the implementation from the router's configured encryption type: a RatchetSKM for an ECIES_X25519 key, otherwise a TransientSessionKeyManager.Where do we get network messages from (aka where does the comm system dump what it reads)?Use this to connect to the router in the same JVM.booleanUse this instead of context instanceof RouterContext.jobQueue()The actual driver of the router, where all jobs are enqueued and processed.Coordinates the router's ElGamal and DSA keys, as well as any keys given to it by clients as part of a LeaseSet.keyRing()Override to support storage inrouter.config.(package private) static voidKill the global I2PAppContext, so it isn't still around when we restart in the same JVM (Android).static List<RouterContext> Retrieve the list of router contexts currently instantiated in this JVM.Tracker component for monitoring what messages are wrapped in what containers and how they proceed through the network.The registry is used by outbound messages to wait for replies.The router keeps track of messages it receives to prevent duplicates, as well as other criteria for "validity".netDb()The main network database facade for standard database operations.The network database segmentor for advanced database access.Where do we put messages that the router wants to forwards onto the network?Minimal interface for selecting peers for various tasks based on given criteria.Expose a simple API for various router components to take note of particular events that a peer enacts (sends us a message, agrees to participate in a tunnel, etc).Organize the peers we know about into various tiers, profiling their performance and sorting them accordingly.(package private) voidremoveProperty(String propName) Remove a property provided during the context construction.(package private) voidRemove all shutdown tasks from the context.router()What router is this context working for?The RouterAppManager.Convenience method for getting the router hash.The routing key generator for this context.Determine how much do we want to mess with the keys to turn them into something we can route.(package private) static booleanThe default context, unless there is one already.If the router is configured to, gather up some particularly tasty morsels regarding the stats managed and offer to publish them into the routerInfo.throttle()The router throttle controller for managing load.toString()Handle tunnel messages, as well as coordinate the gateways.Coordinate this router's tunnels (its pools, participation, backup, etc).Methods inherited from class I2PAppContext
addShutdownTask, aes, clock, deleteTempDir, dsa, elGamalEngine, getAppDir, getBaseDir, getBooleanProperty, getBooleanPropertyDefaultTrue, getConfigDir, getCurrentContext, getGlobalContext, getLibDir, getLogDir, getPIDDir, getProperty, getProperty, getPropertyNames, getRouterDir, getShutdownTasks, getTempDir, hasWrapper, hmac256, keyGenerator, logManager, namingService, portMapper, random, removeShutdownTask, sessionKeyManager, setGlobalContext, setLogManager, sha, simpleTimer2, statManagerModifier and TypeMethodDescriptionvoidaddShutdownTask(Runnable task) WARNING - Shutdown tasks are not executed in an I2PAppContext.aes()Ok, I'll admit it, there is no good reason for having a context specific AES engine.clock()The context's synchronized clock, which is kept context specific only to enable simulators to play with clock skew among different instances.voidDon't rely on deleteOnExit().dsa()Our DSA engine (see HMAC and SHA above).This is the ElGamal engine used within this context.Where applications may store data.This is the installation dir, often referred to as $I2P.booleangetBooleanProperty(String propName) Default false.booleangetBooleanPropertyDefaultTrue(String propName) Boolean property, defaulting to true if not set.The base dir for config files.static I2PAppContextPull the default context, WITHOUT creating a new one.static I2PAppContextPull the default context, creating a new one if necessary, else using the first one created.This is the library dir, which is usually $I2P/lib.Where the router keeps its log directory.Whererouter.pinggoes.final booleangetProperty(String propName, boolean defaultVal) Return a boolean with a boolean default.final floatgetProperty(String propName, float defaultVal) Return a float with a float default.Access the configuration attributes of this context, listing the properties provided during the context construction, as well as the ones included in System.getProperties.Where the router keeps its files.List of shutdown tasks.final FileWhere anybody may store temporary data.booleanIs the wrapper present?hmac256()Un-deprecated in 0.9.38.Component to generate ElGamal, DSA, and Session keys.Query the log manager for this context, which may in turn have its own set of configuration settings (loaded from the context's properties).Pull up the naming service used in this context.Basic mapping from service names to ports.random()The random source for this context, created on first use.voidremoveShutdownTask(Runnable task) Remove a shutdown task.The session key manager which coordinates the sessionKey / sessionTag data.protected static booleanDefault context, unless there is one already.voidsetLogManager(LogManager logManager) Overwrites the LogManager instance to be used by the router.sha()Our SHA256 instance (see the hmac discussion for why its context specific).Use instead ofSimpleTimer2.getInstance().The statistics component with which we can track various events over time.
Field Details
_router
The router object that created this context._clientManagerFacade
Manager of the I2CP client connections._internalClientManager
Manager of the router's internal clients._clientMessagePool
Pool of reusable client messages._jobQueue
Queue of scheduled router jobs._inNetMessagePool
Pool of inbound network messages._outNetMessagePool
Pool of outbound network messages._messageHistory
Recent message ids for duplicate detection._messageRegistry
Registry of outbound message handlers._netDb
The router's network database._keyManager
Manager of our session keys._commSystem
The transport and message comm system._profileOrganizer
Organizer of the peer profiles._peerManagerFacade
Manager of peer connections and tests._profileManager
Manager of the peer profiles._bandwidthLimiter
The bandwidth limiter for transports._tunnelManager
Manager of the tunnel pools._tunnelDispatcher
Dispatcher of messages through tunnels._statPublisher
Publisher of the router statistics._banlist
The banlist of bad routers._blocklist
The blocklist of bad networks._messageValidator
Validator of inbound messages._throttle
The router's connection throttle._appManager
Manager of the router's internal apps._routingKeyGenerator
Generator of our routing keys._garlicMessageParser
Parser of garlic messages._elGamalAESEngine
Engine for the legacy ElGamal-AES encryption._eciesEngine
Engine for the ratchet encryption types._finalShutdownTasks
_initialized
private volatile boolean _initializedTrue once the context components are built._lock1
Lock for the first group of components._lock2
Lock for the second group of components._lock3
Lock for the third group of components._contexts
All live router contexts.
Constructor Details
RouterContext
RouterContext
Caller MUST call initAll() after instantiation.- Parameters:
router- may be null for unit tests if you are carefulenvProps- configuration properties to override the defaults, or null to use none
RouterContext
RouterContext(Router router, Properties envProps, boolean doInit) Caller MUST call initAll() after instantiation. NOT a public API, for use by Router only, NOT for external use.- Parameters:
router- may be null for unit tests if you are carefulenvProps- configuration properties to override the defaults, or null to use nonedoInit- should this context be used as the global one (if necessary)? Will only apply if there is no global context now. If false, caller should callsetGlobalContext(RouterContext)afterwards.
Method Details
setGlobalContext
The default context, unless there is one already. NOT a public API, for use by Router only, NOT for external use.- Parameters:
ctx- context constructed with doInit = false- Returns:
- success (false if previously set)
filterProps
Properties where the defaults must be different from those inI2PAppContext.Unless we are explicitly disabling the timestamper, we want to use it. We need this now as the new timestamper default is disabled (so we don't have each I2PAppContext creating their own SNTP queries all the time)
Set more PRNG buffers, as the default is now small for the I2PAppContext.
- Parameters:
envProps- the properties to filter, may be null- Returns:
- the same properties with the router defaults added, never null
removeProperty
Remove a property provided during the context construction. Only for use by the router. Others useRouter.saveConfig().- Parameters:
propName- The name of the property.
addPropertyCallback
Add a callback for property changes.- Overrides:
addPropertyCallbackin classI2PAppContext- Parameters:
callback- the callback to be notified of property changes
initAll
public void initAll()The following properties may be used to replace various parts of the context with dummy implementations for testing, by setting the property to "true":i2p.dummyClientFacade i2p.dummyNetDb i2p.dummyPeerManager i2p.dummyTunnelManager i2p.vmCommSystem (transport)
listContexts
Retrieve the list of router contexts currently instantiated in this JVM. This will always contain only one item (except when a simulation per the MultiRouter is going on).- Returns:
- an unmodifiable list (as of 0.8.8). May be empty.
getContexts
Same aslistContexts()but package private and modifiable. The list should only be modified when a new context is created or a router is shut down.- Returns:
- the modifiable list of router contexts registered in this JVM
killGlobalContext
static void killGlobalContext()Kill the global I2PAppContext, so it isn't still around when we restart in the same JVM (Android). Only do this if there are no other routers in the JVM.router
What router is this context working for?- Returns:
- the Router instance, or null when constructed for unit tests
routerHash
clientManager
How are we coordinating clients for the router?- Returns:
- the ClientManagerFacade instance
clientMessagePool
Where do we toss messages for the clients (and where do we get client messages to forward on from)?- Returns:
- the ClientMessagePool instance
inNetMessagePool
Where do we get network messages from (aka where does the comm system dump what it reads)?- Returns:
- the InNetMessagePool instance
outNetMessagePool
Where do we put messages that the router wants to forwards onto the network?- Returns:
- the OutNetMessagePool instance
messageHistory
Tracker component for monitoring what messages are wrapped in what containers and how they proceed through the network. This is fully for debugging, as when a large portion of the network tracks their messages through this messageHistory and submits their logs, we can correlate them and watch as messages flow from hop to hop.- Returns:
- the MessageHistory instance
messageRegistry
The registry is used by outbound messages to wait for replies.- Returns:
- the OutboundMessageRegistry instance
netDbSegmentor
The network database segmentor for advanced database access.- Returns:
- the SegmentedNetworkDatabaseFacade instance
netDb
The main network database facade for standard database operations.- Returns:
- the NetworkDatabaseFacade for the main network
clientNetDb
The client netDb for the given id. Will return the main netDb if the dbid is null or the client db is not found.- Parameters:
id- may be null- Returns:
- non-null
jobQueue
The actual driver of the router, where all jobs are enqueued and processed.- Returns:
- the JobQueue instance
keyManager
Coordinates the router's ElGamal and DSA keys, as well as any keys given to it by clients as part of a LeaseSet.- Returns:
- the KeyManager instance
commSystem
How do we pass messages from our outNetMessagePool to another router.- Returns:
- the CommSystemFacade instance
profileOrganizer
Organize the peers we know about into various tiers, profiling their performance and sorting them accordingly.- Returns:
- the ProfileOrganizer instance
peerManager
Minimal interface for selecting peers for various tasks based on given criteria. This is kept seperate from the profile organizer since this logic is independent of how the peers are organized (or profiled even).- Returns:
- the PeerManagerFacade instance
profileManager
Expose a simple API for various router components to take note of particular events that a peer enacts (sends us a message, agrees to participate in a tunnel, etc).- Returns:
- the ProfileManager instance
bandwidthLimiter
Coordinate this router's bandwidth limits.- Returns:
- the FIFOBandwidthLimiter instance
tunnelManager
Coordinate this router's tunnels (its pools, participation, backup, etc). Any configuration for the tunnels is rooted from the context's properties.- Returns:
- the TunnelManagerFacade instance
tunnelDispatcher
Handle tunnel messages, as well as coordinate the gateways.- Returns:
- the TunnelDispatcher instance
statPublisher
If the router is configured to, gather up some particularly tasty morsels regarding the stats managed and offer to publish them into the routerInfo.- Returns:
- the StatisticsManager instance
banlist
blocklist
messageValidator
The router keeps track of messages it receives to prevent duplicates, as well as other criteria for "validity".- Returns:
- the MessageValidator instance
throttle
The router throttle controller for managing load.- Returns:
- the RouterThrottle instance
toString
getProperty
Tie in the router's config as properties, as well as whatever the I2PAppContext says.- Overrides:
getPropertyin classI2PAppContext- Parameters:
propName- the property name- Returns:
- the value of the named property, taken from
router.configwhen set and otherwise from the app context, or null if neither defines it
getProperty
Tie in the router's config as properties, as well as whatever the I2PAppContext says.- Overrides:
getPropertyin classI2PAppContext- Parameters:
propName- the property namedefaultVal- the default value- Returns:
- the value of the named property, taken from
router.configwhen set and otherwise from the app context, or defaultVal if neither defines it
getProperty
Return an int with an int default.- Overrides:
getPropertyin classI2PAppContext- Parameters:
propName- the property namedefaultVal- the default value- Returns:
- the value of the named property parsed as an int, or defaultVal if it is unset or does not parse as an integer
getProperty
Return a long with a long default.- Overrides:
getPropertyin classI2PAppContext- Parameters:
propName- the property namedefaultVal- the default value- Returns:
- the value of the named property parsed as a long, or defaultVal if it is unset or does not parse as a long
getProperties
New Properties with system and context properties.- Overrides:
getPropertiesin classI2PAppContext- Returns:
- a fresh copy, never null
initializeClock
protected void initializeClock()Description copied from class:I2PAppContextInitialize the clock.- Overrides:
initializeClockin classI2PAppContext
keyRing
Override to support storage inrouter.config.- Overrides:
keyRingin classI2PAppContext- Returns:
- the key ring
initializeKeyRing
protected void initializeKeyRing()Description copied from class:I2PAppContextInitialize the key ring.- Overrides:
initializeKeyRingin classI2PAppContext
removeShutdownTasks
void removeShutdownTasks()Remove all shutdown tasks from the context. Used during router shutdown to clear pending tasks.addFinalShutdownTask
Add a task to be run during final shutdown. This is called after all context resources have been cleaned up. No logging or context resources will be available during task execution.- Parameters:
task- the Runnable to execute during final shutdown
getFinalShutdownTasks
isRouterContext
public boolean isRouterContext()Use this instead of context instanceof RouterContext.- Overrides:
isRouterContextin classI2PAppContext- Returns:
- true always, as this class is the router's own context
internalClientManager
Use this to connect to the router in the same JVM.- Overrides:
internalClientManagerin classI2PAppContext- Returns:
- the client manager
clientAppManager
The RouterAppManager.- Overrides:
clientAppManagerin classI2PAppContext- Returns:
- the RouterAppManager holding this router's client applications
routerAppManager
The RouterAppManager. For convenience, same asclientAppManager(), no cast required.- Returns:
- the same RouterAppManager that clientAppManager() returns, already typed as the router-specific subclass
initializeSessionKeyManager
protected void initializeSessionKeyManager()Create the session key manager for the router, picking the implementation from the router's configured encryption type: a RatchetSKM for an ECIES_X25519 key, otherwise a TransientSessionKeyManager. Overridden here because I2PAppContext returns a dummy SessionKeyManager.- Overrides:
initializeSessionKeyManagerin classI2PAppContext
routingKeyGenerator
Determine how much do we want to mess with the keys to turn them into something we can route. This is context specific because we may want to test out how things react when peers don't agree on how to skew.Returns same thing as
routerKeyGenerator(). Overrides I2PAppContext, returns non-null in RouterContext and null in I2PAppContext.- Overrides:
routingKeyGeneratorin classI2PAppContext- Returns:
- non-null
routerKeyGenerator
The routing key generator for this context.- Returns:
- the RouterKeyGenerator instance
garlicMessageParser
The garlic message parser for this context. Since we only need one parser instance, this is lazily initialized.- Returns:
- the GarlicMessageParser instance
elGamalAESEngine
Access the ElGamal/AES+SessionTag engine for this context. The algorithm makes use of the context's sessionKeyManager to coordinate transparent access to the sessionKeys and sessionTags, as well as the context's elGamal engine (which in turn keeps stats, etc).- Returns:
- the ElGamalAESEngine instance
eciesEngine
Access the ECIES/AEAD engine for this context. The algorithm makes use of the sessionKeyManager to coordinate transparent access to the sessionKeys and sessionTags.- Returns:
- the ECIESAEADEngine instance
getEstimatedDowntime
public long getEstimatedDowntime()How long this router was down before it started, or 0 if unknown.This may be used for a determination of whether to regenerate keys, for example. We use the timestamp of the previous ping file left behind on crash, as set by isOnlyRouterRunning(), if present. Otherwise, the last STOPPED entry in the event log.
May take a while to run the first time, if it has to go through the event log. Once called, the result is cached.
- Overrides:
getEstimatedDowntimein classI2PAppContext- Returns:
- downtime in ms or 0 if unknown