Class RouterContext


  • public class RouterContext
    extends I2PAppContext
    Build off the core I2P context to provide a root for a router instance to coordinate its resources. Router instances themselves should be sure to have their own RouterContext, and rooting off of it will allow multiple routers to operate in the same JVM without conflict (e.g. sessionTags wont get intermingled, nor will their netDbs, jobQueues, or bandwidth limiters).
    • Constructor Detail

      • RouterContext

        public RouterContext​(Router router)
        Caller MUST call initAll() after instantiation.
        Parameters:
        router - may be null for unit tests if you are careful
      • RouterContext

        public RouterContext​(Router router,
                             Properties envProps)
        Caller MUST call initAll() after instantiation.
        Parameters:
        router - may be null for unit tests if you are careful
      • 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 careful
        doInit - 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 call setGlobalContext() afterwards.
        Since:
        0.9.33
    • Method Detail

      • setGlobalContext

        static boolean setGlobalContext​(RouterContext ctx)
        Sets 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)
        Since:
        0.9.33
      • setProperty

        @Deprecated
        public void setProperty​(String propName,
                                String value)
        Deprecated.
        Use Router.saveConfig()
        Modify the configuration attributes of this context, changing one of the properties provided during the context construction.
        Parameters:
        propName - The name of the property.
        value - The new value for the property.
        Since:
        0.8.4
      • removeProperty

        void removeProperty​(String propName)
        Remove a property provided during the context construction. Only for use by the router. Others use Router.saveConfig()
        Parameters:
        propName - The name of the property.
        Since:
        0.9
      • addPropertyCallback

        public void addPropertyCallback​(I2PProperties.I2PPropertyCallback callback)
        Description copied from class: I2PAppContext
        Add a callback, which will fire upon changes in the property given in the specific callback. Unimplemented in I2PAppContext: this only makes sense in a router context.
        Overrides:
        addPropertyCallback in class I2PAppContext
        Parameters:
        callback - The implementation of the callback.
      • 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

        public static List<RouterContext> 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

        static List<RouterContext> getContexts()
        Same as listContexts() but package private and modifiable. The list should only be modified when a new context is created or a router is shut down.
        Since:
        0.8.8
      • 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.
        Since:
        0.8.8
      • router

        public Router router()
        what router is this context working for?
      • routerHash

        public Hash routerHash()
        Convenience method for getting the router hash. Equivalent to context.router().getRouterInfo().getIdentity().getHash() Warning - risk of deadlock - do not call while holding locks
        Returns:
        may be null if called very early
      • clientManager

        public ClientManagerFacade clientManager()
        How are we coordinating clients for the router?
      • clientMessagePool

        public ClientMessagePool clientMessagePool()
        Where do we toss messages for the clients (and where do we get client messages to forward on from)?
      • inNetMessagePool

        public InNetMessagePool inNetMessagePool()
        Where do we get network messages from (aka where does the comm system dump what it reads)?
      • outNetMessagePool

        public OutNetMessagePool outNetMessagePool()
        Where do we put messages that the router wants to forwards onto the network?
      • messageHistory

        public MessageHistory 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.
      • messageRegistry

        public OutboundMessageRegistry messageRegistry()
        The registry is used by outbound messages to wait for replies.
      • jobQueue

        public JobQueue jobQueue()
        The actual driver of the router, where all jobs are enqueued and processed.
      • keyManager

        public KeyManager keyManager()
        Coordinates the router's ElGamal and DSA keys, as well as any keys given to it by clients as part of a LeaseSet.
      • commSystem

        public CommSystemFacade commSystem()
        How do we pass messages from our outNetMessagePool to another router
      • profileOrganizer

        public ProfileOrganizer profileOrganizer()
        Organize the peers we know about into various tiers, profiling their performance and sorting them accordingly.
      • peerManager

        public PeerManagerFacade 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).
      • profileManager

        public ProfileManager 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).
      • bandwidthLimiter

        public FIFOBandwidthLimiter bandwidthLimiter()
        Coordinate this router's bandwidth limits
      • tunnelManager

        public TunnelManagerFacade tunnelManager()
        Coordinate this router's tunnels (its pools, participation, backup, etc). Any configuration for the tunnels is rooted from the context's properties
      • tunnelDispatcher

        public TunnelDispatcher tunnelDispatcher()
        Handle tunnel messages, as well as coordinate the gateways
      • statPublisher

        public StatisticsManager 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.
      • banlist

        public Banlist banlist()
        who does this peer hate?
      • messageValidator

        public MessageValidator messageValidator()
        The router keeps track of messages it receives to prevent duplicates, as well as other criteria for "validity".
      • throttle

        public RouterThrottle throttle()
        Component to coordinate our accepting/rejecting of requests under load
      • getProperty

        public String getProperty​(String propName)
        Tie in the router's config as properties, as well as whatever the I2PAppContext says.
        Overrides:
        getProperty in class I2PAppContext
      • getProperty

        public String getProperty​(String propName,
                                  String defaultVal)
        Tie in the router's config as properties, as well as whatever the I2PAppContext says.
        Overrides:
        getProperty in class I2PAppContext
      • getProperty

        public int getProperty​(String propName,
                               int defaultVal)
        Return an int with an int default
        Overrides:
        getProperty in class I2PAppContext
      • getProperty

        public long getProperty​(String propName,
                                long defaultVal)
        Return a long with a long default
        Overrides:
        getProperty in class I2PAppContext
        Since:
        0.9.4
      • getProperties

        public Properties getProperties()
        Description copied from class: I2PAppContext
        Access the configuration attributes of this context, listing the properties provided during the context construction, as well as the ones included in System.getProperties.
        Overrides:
        getProperties in class I2PAppContext
        Returns:
        new Properties with system and context properties
        Since:
        0.8.4
      • removeShutdownTasks

        void removeShutdownTasks()
        Since:
        0.8.8
      • addFinalShutdownTask

        public void addFinalShutdownTask​(Runnable task)
        The last thing to be called before router shutdown. No context resources, including logging, will be available. Only for external threads in the same JVM needing to know when the shutdown is complete, like Android.
        Since:
        0.8.8
      • getFinalShutdownTasks

        Set<Runnable> getFinalShutdownTasks()
        Returns:
        the Set
        Since:
        0.8.8
      • isRouterContext

        public boolean isRouterContext()
        Use this instead of context instanceof RouterContext
        Overrides:
        isRouterContext in class I2PAppContext
        Returns:
        true
        Since:
        0.7.9
      • routerAppManager

        public RouterAppManager routerAppManager()
        The RouterAppManager. For convenience, same as clientAppManager(), no cast required
        Returns:
        the manager
        Since:
        0.9.11
      • initializeSessionKeyManager

        protected void initializeSessionKeyManager()
        As of 0.9.15, this returns a dummy SessionKeyManager in I2PAppContext. Overridden in RouterContext to return the full TransientSessionKeyManager or MuxedSKM, depending on configured router encryption type.
        Overrides:
        initializeSessionKeyManager in class I2PAppContext
        Since:
        0.9.15
      • routingKeyGenerator

        public RoutingKeyGenerator 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:
        routingKeyGenerator in class I2PAppContext
        Returns:
        non-null
        Since:
        0.9.16 Overrides I2PAppContext. Returns non-null in RouterContext and null in I2PAppcontext.
      • routerKeyGenerator

        public RouterKeyGenerator routerKeyGenerator()
        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 routingKeyGenerator()
        Returns:
        non-null
        Since:
        0.9.16
      • garlicMessageParser

        public GarlicMessageParser garlicMessageParser()
        Since we only need one.
        Returns:
        non-null after initAll()
        Since:
        0.9.20
      • elGamalAESEngine

        public ElGamalAESEngine 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).
        Since:
        0.9.38 moved from superclass (app context)
      • eciesEngine

        public ECIESAEADEngine 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.
        Since:
        0.9.44
      • 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:
        getEstimatedDowntime in class I2PAppContext
        Returns:
        downtime in ms or 0 if unknown
        Since:
        0.0.47