java.lang.Object
net.i2p.i2pcontrol.servlets.jsonrpc2handlers.AdvancedSettingsHandler
All Implemented Interfaces:
RequestHandler

public class AdvancedSettingsHandlerextends Object implements RequestHandler
JSON-RPC handler for advanced router settings.
  • Field Details

    • _context

      private final RouterContext _context
      The router whose settings are read and written.
    • _helper

      private final JSONRPC2Helper _helper
      Validates requests and formats replies.
    • requiredArgs

      private static final String[] requiredArgs
      No method here requires arguments.
  • Constructor Details

    • AdvancedSettingsHandler

      public AdvancedSettingsHandler(RouterContext ctx, JSONRPC2Helper helper)
      Constructor for advanced settings handler.
      Parameters:
      ctx - router context the settings are read from
      helper - JSON-RPC helper instance
  • Method Details

    • handledRequests

      public String[] handledRequests()
      Requests handled by this handler.
      Specified by:
      handledRequests in interface RequestHandler
      Returns:
      method names handled by this handler
    • process

      public JSONRPC2Response process(JSONRPC2Request req, MessageContext ctx)
      Process an AdvancedSettings request
      Specified by:
      process in interface RequestHandler
      Parameters:
      req - A valid JSON-RPC 2.0 request instance. Must not be null.
      ctx - Context information about the request message, may be null if undefined.
      Returns:
      The resulting JSON-RPC 2.0 response. It indicates success or an error, such as METHOD_NOT_FOUND.
    • getAdvancedSetting

      private String getAdvancedSetting(String key)
      Reads one router config setting.
      Parameters:
      key - the config parameter name
      Returns:
      the value, null if unset
    • getAdvancedSettings

      private Map<String,String> getAdvancedSettings()
      Reads the whole router config map.
      Returns:
      every setting, by name
    • checkTypes

      private boolean checkTypes(Map<String,Object> newSettings)
      Checks every supplied value is a string.
      Parameters:
      newSettings - the values from the request
      Returns:
      true if all the values are strings
    • setAdvancedSettings

      private boolean setAdvancedSettings(Map<String,String> newSettings, boolean clearConfig)
      Writes the new settings to the router config.
      Parameters:
      newSettings - the values to write
      clearConfig - true to unset every setting not in newSettings
      Returns:
      true if the settings were written