## net.i2p.router
Class Router

    java.lang.Object
      net.i2p.router.Router

    public class Router

extends Object

Main driver for the router.

Field Summary
`static char` `CAPABILITY_BW12`
`static char` `CAPABILITY_BW128`
`static char` `CAPABILITY_BW256`
`static char` `CAPABILITY_BW32`
`static char` `CAPABILITY_BW64`
`static char` `CAPABILITY_NEW_TUNNEL` Deprecated. unused
`static char` `CAPABILITY_REACHABLE`
`static char` `CAPABILITY_UNREACHABLE`
`static long` `CLOCK_FUDGE_FACTOR` let clocks be off by 1 minute
`static int` `DEFAULT_SHARE_PERCENTAGE`
`static String` `DNS_CACHE_TIME`

`static int`

`EXIT_GRACEFUL`
private static final void testAppendLog() { StringBuilder buf = new StringBuilder(1024); Router.appendLogMessage(buf, "hi\nhow are you\nh0h0h0"); System.out.println("line: [" + buf.toString() + "]"); buf.setLength(0); Router.appendLogMessage(buf, "\nfine thanks\nh0h0h0"); System.out.println("line: [" + buf.toString() + "]"); buf.setLength(0); Router.appendLogMessage(buf, "liar\nblah blah\n"); System.out.println("line: [" + buf.toString() + "]"); buf.setLength(0); Router.appendLogMessage(buf, "\n"); System.out.println("line: [" + buf.toString() + "]"); buf.setLength(0); Router.appendLogMessage(buf, ""); System.out.println("line: [" + buf.toString() + "]"); buf.setLength(0); Router.appendLogMessage(buf, ".........10........20........30........40........50........6"); System.out.println("line: [" + buf.toString() + "]"); buf.setLength(0); Router.appendLogMessage(buf, ".........10........\n20........30........40........50........6"); System.out.println("line: [" + buf.toString() + "]"); buf.setLength(0); Router.appendLogMessage(buf, ".........10........20\n........30........40........50........6"); System.out.println("line: [" + buf.toString() + "]"); buf.setLength(0); Router.appendLogMessage(buf, ".........10.......\n.20........30........40........50........6"); System.out.println("line: [" + buf.toString() + "]"); buf.setLength(0); Router.appendLogMessage(buf, "\n.........10........20........30........40........50........6"); System.out.println("line: [" + buf.toString() + "]"); buf.setLength(0); }

`static int` `EXIT_GRACEFUL_RESTART`
`static int` `EXIT_HARD`
`static int` `EXIT_HARD_RESTART`
`static int` `EXIT_OOM`
`(package private) static String` `IDENTLOG`
`(package private) static long` `LIVELINESS_DELAY`
`static int` `NETWORK_ID` used to differentiate routerInfo files on different networks
`static String` `PROP_BANDWIDTH_SHARE_PERCENTAGE`
`static String` `PROP_CONFIG_FILE`
`static String` `PROP_DYNAMIC_KEYS`
`static String` `PROP_FORCE_BWCLASS`
`static String` `PROP_FORCE_UNREACHABLE`
`static String` `PROP_HIDDEN` this puts an 'H' in your routerInfo
`static String` `PROP_HIDDEN_HIDDEN` this does not put an 'H' in your routerInfo
`static String` `PROP_INFO_FILENAME`
`static String` `PROP_INFO_FILENAME_DEFAULT`
`static String` `PROP_KEYS_FILENAME`
`static String` `PROP_KEYS_FILENAME_DEFAULT`
`static String` `PROP_SHUTDOWN_IN_PROGRESS`
`Object` `routerInfoFileLock`
`static String` `UPDATE_FILE`

Constructor Summary
`Router()`
`Router(Properties envProps)`
`Router(String configFilename)`
`Router(String configFilename, Properties envProps)`

Method Summary
`void` `addCapabilities(RouterInfo ri)`
`void` `cancelGracefulShutdown()` Cancel any prior request to shut the router down gracefully.
`Certificate` `createCertificate()`
`int` `get15sRate()`
`int` `get15sRate(boolean outboundOnly)`
`int` `get15sRateIn()`
`int` `get1mRate()`
`int` `get1mRate(boolean outboundOnly)`
`int` `get1mRateIn()`
`int` `get1sRate()`
`int` `get1sRate(boolean outboundOnly)`
`int` `get1sRateIn()`
`int` `get5mRate()`
`int` `get5mRate(boolean outboundOnly)`
`String` `getConfigFilename()`
`Properties` `getConfigMap()`
`String` `getConfigSetting(String name)`
`Set` `getConfigSettings()`
`RouterContext` `getContext()`
`boolean` `getHigherVersionSeen()` True if the router has tried to communicate with another router who is running a higher incompatible protocol version.
`boolean` `getKillVMOnEnd()` Deprecated. unused
`RouterInfo` `getRouterInfo()`
`double` `getSharePercentage()` What fraction of the bandwidth specified in our bandwidth limits should we allow to be consumed by participating tunnels?
`long` `getShutdownTimeRemaining()` How long until the graceful shutdown will kill us?
`long` `getUptime()` wall clock uptime
`long` `getWhenStarted()`
`boolean` `gracefulShutdownInProgress()`
`boolean` `isAlive()`
`boolean` `isHidden()`
`void` `killKeys()`
`static void` `main(String[] args)`
`void` `readConfig()` This updates the config with all settings found in the file.
`void` `rebuildNewIdentity()` Rebuild a new identity the hard way - delete all of our old identity files, then reboot the router.
`void` `rebuildRouterInfo()` Rebuild and republish our routerInfo since something significant has changed.
`void` `rebuildRouterInfo(boolean blockingRebuild)`
`void` `removeConfigSetting(String name)`
`void` `renderStatusHTML(Writer out)` this is for oldconsole.jsp, pretty much unused except as a way to get memory info, so let's comment out the rest, it is available elsewhere, and we don't really want to spend a minute rendering a multi-megabyte page in memory.
`void` `restart()` A "soft" restart, primarily of the comm system, after a port change or large step-change in system time.
`(package private) void` `runRouter()`
`boolean` `saveConfig()` Save the current config options (returning true if save was successful, false otherwise) Note that unlike DataHelper.storeProps(), this does escape the \r or \n that are unescaped in DataHelper.loadProps().
`int` `scheduledGracefulExitCode()` What exit code do we plan on using when we shut down (or -1, if there isn't a graceful shutdown planned)
`void` `setConfigFilename(String filename)`
`void` `setConfigSetting(String name, String value)`
`void` `setHigherVersionSeen(boolean seen)`
`void` `setKillVMOnEnd(boolean shouldDie)` Configure the router to kill the JVM when the router shuts down, as well as whether to explicitly halt the JVM during the hard fail process.
`void` `setRouterInfo(RouterInfo info)` Caller must ensure info is valid - no validation done here
`void` `shutdown(int exitCode)`
`void` `shutdownGracefully()` Call this if we want the router to kill itself as soon as we aren't participating in any more tunnels (etc).
`void` `shutdownGracefully(int exitCode)` Call this with EXIT_HARD or EXIT_HARD_RESTART for a non-blocking, hard, non-graceful shutdown with a brief delay to allow a UI response

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### routerInfoFileLock

    public final Object routerInfoFileLock

### PROP_CONFIG_FILE

    public static final String PROP_CONFIG_FILE

See Also:
  Constant Field Values

### CLOCK_FUDGE_FACTOR

    public static final long CLOCK_FUDGE_FACTOR

  let clocks be off by 1 minute

  See Also:
    Constant Field Values

### NETWORK_ID

    public static final int NETWORK_ID

  used to differentiate routerInfo files on different networks

  See Also:
    Constant Field Values

### PROP_HIDDEN

    public static final String PROP_HIDDEN

  this puts an 'H' in your routerInfo

  See Also:
    Constant Field Values

### PROP_HIDDEN_HIDDEN

    public static final String PROP_HIDDEN_HIDDEN

  this does not put an 'H' in your routerInfo

  See Also:
    Constant Field Values

### PROP_DYNAMIC_KEYS

    public static final String PROP_DYNAMIC_KEYS

See Also:
  Constant Field Values

### PROP_INFO_FILENAME

    public static final String PROP_INFO_FILENAME

See Also:
  Constant Field Values

### PROP_INFO_FILENAME_DEFAULT

    public static final String PROP_INFO_FILENAME_DEFAULT

See Also:
  Constant Field Values

### PROP_KEYS_FILENAME

    public static final String PROP_KEYS_FILENAME

See Also:
  Constant Field Values

### PROP_KEYS_FILENAME_DEFAULT

    public static final String PROP_KEYS_FILENAME_DEFAULT

See Also:
  Constant Field Values

### PROP_SHUTDOWN_IN_PROGRESS

    public static final String PROP_SHUTDOWN_IN_PROGRESS

See Also:
  Constant Field Values

### DNS_CACHE_TIME

    public static final String DNS_CACHE_TIME

See Also:
  Constant Field Values

### CAPABILITY_BW12

    public static final char CAPABILITY_BW12

See Also:
  Constant Field Values

### CAPABILITY_BW32

    public static final char CAPABILITY_BW32

See Also:
  Constant Field Values

### CAPABILITY_BW64

    public static final char CAPABILITY_BW64

See Also:
  Constant Field Values

### CAPABILITY_BW128

    public static final char CAPABILITY_BW128

See Also:
  Constant Field Values

### CAPABILITY_BW256

    public static final char CAPABILITY_BW256

See Also:
  Constant Field Values

### PROP_FORCE_BWCLASS

    public static final String PROP_FORCE_BWCLASS

See Also:
  Constant Field Values

### CAPABILITY_REACHABLE

    public static final char CAPABILITY_REACHABLE

See Also:
  Constant Field Values

### CAPABILITY_UNREACHABLE

    public static final char CAPABILITY_UNREACHABLE

See Also:
  Constant Field Values

### PROP_FORCE_UNREACHABLE

    public static final String PROP_FORCE_UNREACHABLE

See Also:
  Constant Field Values

### CAPABILITY_NEW_TUNNEL

    public static final char CAPABILITY_NEW_TUNNEL

  Deprecated. unused
  See Also:
    Constant Field Values

### IDENTLOG

    static final String IDENTLOG

See Also:
  Constant Field Values

### EXIT_GRACEFUL

    public static final int EXIT_GRACEFUL

  private static final void testAppendLog() { StringBuilder buf = new StringBuilder(1024); Router.appendLogMessage(buf, "hi\nhow are you\nh0h0h0"); System.out.println("line: [" + buf.toString() + "]"); buf.setLength(0); Router.appendLogMessage(buf, "\nfine thanks\nh0h0h0"); System.out.println("line: [" + buf.toString() + "]"); buf.setLength(0); Router.appendLogMessage(buf, "liar\nblah blah\n"); System.out.println("line: [" + buf.toString() + "]"); buf.setLength(0); Router.appendLogMessage(buf, "\n"); System.out.println("line: [" + buf.toString() + "]"); buf.setLength(0); Router.appendLogMessage(buf, ""); System.out.println("line: [" + buf.toString() + "]"); buf.setLength(0); Router.appendLogMessage(buf, ".........10........20........30........40........50........6"); System.out.println("line: [" + buf.toString() + "]"); buf.setLength(0); Router.appendLogMessage(buf, ".........10........\n20........30........40........50........6"); System.out.println("line: [" + buf.toString() + "]"); buf.setLength(0); Router.appendLogMessage(buf, ".........10........20\n........30........40........50........6"); System.out.println("line: [" + buf.toString() + "]"); buf.setLength(0); Router.appendLogMessage(buf, ".........10.......\n.20........30........40........50........6"); System.out.println("line: [" + buf.toString() + "]"); buf.setLength(0); Router.appendLogMessage(buf, "\n.........10........20........30........40........50........6"); System.out.println("line: [" + buf.toString() + "]"); buf.setLength(0); }

  See Also:
    Constant Field Values

### EXIT_HARD

    public static final int EXIT_HARD

See Also:
  Constant Field Values

### EXIT_OOM

    public static final int EXIT_OOM

See Also:
  Constant Field Values

### EXIT_HARD_RESTART

    public static final int EXIT_HARD_RESTART

See Also:
  Constant Field Values

### EXIT_GRACEFUL_RESTART

    public static final int EXIT_GRACEFUL_RESTART

See Also:
  Constant Field Values

### UPDATE_FILE

    public static final String UPDATE_FILE

See Also:
  Constant Field Values

### LIVELINESS_DELAY

    static final long LIVELINESS_DELAY

See Also:
  Constant Field Values

### PROP_BANDWIDTH_SHARE_PERCENTAGE

    public static final String PROP_BANDWIDTH_SHARE_PERCENTAGE

See Also:
  Constant Field Values

### DEFAULT_SHARE_PERCENTAGE

    public static final int DEFAULT_SHARE_PERCENTAGE

See Also:
  Constant Field Values

Constructor Detail

### Router

    public Router()

### Router

    public Router(Properties envProps)

### Router

    public Router(String configFilename)

### Router

    public Router(String configFilename,
                  Properties envProps)

Method Detail

### setKillVMOnEnd

    public void setKillVMOnEnd(boolean shouldDie)

  Configure the router to kill the JVM when the router shuts down, as well as whether to explicitly halt the JVM during the hard fail process.

### getKillVMOnEnd

    public boolean getKillVMOnEnd()

  Deprecated. unused

### getConfigFilename

    public String getConfigFilename()

### setConfigFilename

    public void setConfigFilename(String filename)

### getConfigSetting

    public String getConfigSetting(String name)

### setConfigSetting

    public void setConfigSetting(String name,
                                 String value)

### removeConfigSetting

    public void removeConfigSetting(String name)

### getConfigSettings

    public Set getConfigSettings()

### getConfigMap

    public Properties getConfigMap()

### getRouterInfo

    public RouterInfo getRouterInfo()

### setRouterInfo

    public void setRouterInfo(RouterInfo info)

  Caller must ensure info is valid - no validation done here

### getHigherVersionSeen

    public boolean getHigherVersionSeen()

  True if the router has tried to communicate with another router who is running a higher incompatible protocol version.

### setHigherVersionSeen

    public void setHigherVersionSeen(boolean seen)

### getWhenStarted

    public long getWhenStarted()

### getUptime

    public long getUptime()

  wall clock uptime

### getContext

    public RouterContext getContext()

### runRouter

    void runRouter()

### readConfig

    public void readConfig()

  This updates the config with all settings found in the file. It does not clear the config first, so settings not found in the file will remain in the config. This is synchronized with saveConfig()

### isAlive

    public boolean isAlive()

### rebuildRouterInfo

    public void rebuildRouterInfo()

  Rebuild and republish our routerInfo since something significant has changed.

### rebuildRouterInfo

    public void rebuildRouterInfo(boolean blockingRebuild)

### addCapabilities

    public void addCapabilities(RouterInfo ri)

### isHidden

    public boolean isHidden()

### createCertificate

    public Certificate createCertificate()

  Returns:
    the certificate for a new RouterInfo - probably a null cert.

### killKeys

    public void killKeys()

### rebuildNewIdentity

    public void rebuildNewIdentity()

  Rebuild a new identity the hard way - delete all of our old identity files, then reboot the router.

### renderStatusHTML

    public void renderStatusHTML(Writer out)
                          throws IOException

  this is for oldconsole.jsp, pretty much unused except as a way to get memory info, so let's comment out the rest, it is available elsewhere, and we don't really want to spend a minute rendering a multi-megabyte page in memory.

  Throws:
    `IOException`

### shutdown

    public void shutdown(int exitCode)

### shutdownGracefully

    public void shutdownGracefully()

  Call this if we want the router to kill itself as soon as we aren't participating in any more tunnels (etc). This will not block and doesn't guarantee any particular time frame for shutting down. To shut the router down immediately, use `shutdown(int)`. If you want to cancel the graceful shutdown (prior to actual shutdown ;), call `cancelGracefulShutdown()`.

### shutdownGracefully

    public void shutdownGracefully(int exitCode)

  Call this with EXIT_HARD or EXIT_HARD_RESTART for a non-blocking, hard, non-graceful shutdown with a brief delay to allow a UI response

### cancelGracefulShutdown

    public void cancelGracefulShutdown()

  Cancel any prior request to shut the router down gracefully.

### scheduledGracefulExitCode

    public int scheduledGracefulExitCode()

  What exit code do we plan on using when we shut down (or -1, if there isn't a graceful shutdown planned)

### gracefulShutdownInProgress

    public boolean gracefulShutdownInProgress()

### getShutdownTimeRemaining

    public long getShutdownTimeRemaining()

  How long until the graceful shutdown will kill us?

### saveConfig

    public boolean saveConfig()

  Save the current config options (returning true if save was successful, false otherwise) Note that unlike DataHelper.storeProps(), this does escape the \r or \n that are unescaped in DataHelper.loadProps(). Note that the escaping of \r or \n was probably a mistake and should be taken out. Synchronized with file read in getConfig()

### restart

    public void restart()

  A "soft" restart, primarily of the comm system, after a port change or large step-change in system time. Does not stop the whole JVM, so it is safe even in the absence of the wrapper. This is not a graceful restart - all peer connections are dropped.

### main

    public static void main(String[] args)

### getSharePercentage

    public double getSharePercentage()

  What fraction of the bandwidth specified in our bandwidth limits should we allow to be consumed by participating tunnels?

  Returns:
    a number less than one, not a percentage!

### get1sRate

    public int get1sRate()

### get1sRate

    public int get1sRate(boolean outboundOnly)

### get1sRateIn

    public int get1sRateIn()

### get15sRate

    public int get15sRate()

### get15sRate

    public int get15sRate(boolean outboundOnly)

### get15sRateIn

    public int get15sRateIn()

### get1mRate

    public int get1mRate()

### get1mRate

    public int get1mRate(boolean outboundOnly)

### get1mRateIn

    public int get1mRateIn()

### get5mRate

    public int get5mRate()

### get5mRate

    public int get5mRate(boolean outboundOnly)