Package monero.common

Class MoneroRpcConnection

java.lang.Object
monero.common.MoneroRpcConnection

public class MoneroRpcConnection extends Object
Maintains a connection and sends requests to a Monero RPC API. Equality compares URI, credentials, proxy, ZMQ URI, and TLS verification. Do not mutate these settings while using a connection as a hash key. TODO: refactor MoneroRpcConnection extends MoneroConnection?
  • Field Details

    • MAPPER

      public static com.fasterxml.jackson.databind.ObjectMapper MAPPER
    • client

      protected org.apache.hc.client5.http.impl.classic.CloseableHttpClient client
    • credsProvider

      protected org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider credsProvider
    • proxyClient

      protected org.apache.hc.client5.http.impl.classic.CloseableHttpClient proxyClient
    • proxyClientConfig

      protected List<Object> proxyClientConfig
    • uri

      protected String uri
    • username

      protected String username
    • password

      protected String password
    • zmqUri

      protected String zmqUri
    • proxyUri

      protected String proxyUri
    • priority

      protected int priority
    • timeoutMs

      protected Long timeoutMs
    • isOnline

      protected Boolean isOnline
    • isAuthenticated

      protected Boolean isAuthenticated
    • responseTime

      protected Long responseTime
    • printStackTrace

      protected boolean printStackTrace
    • sslVerify

      protected boolean sslVerify
    • attributes

      protected Map<String,Object> attributes
  • Constructor Details

    • MoneroRpcConnection

      public MoneroRpcConnection(URI uri)
    • MoneroRpcConnection

      public MoneroRpcConnection(String uri)
    • MoneroRpcConnection

      public MoneroRpcConnection(String uri, String username, String password)
    • MoneroRpcConnection

      public MoneroRpcConnection(URI uri, String username, String password)
    • MoneroRpcConnection

      public MoneroRpcConnection(String uri, String username, String password, String zmqUri, String proxyUri)
    • MoneroRpcConnection

      public MoneroRpcConnection(URI uri, String username, String password, URI zmqUri, URI proxyUri)
    • MoneroRpcConnection

      public MoneroRpcConnection(MoneroRpcConnection connection)
  • Method Details

    • getUri

      public String getUri()
    • setUri

      public MoneroRpcConnection setUri(String uri)
    • setUri

      public MoneroRpcConnection setUri(URI uri)
    • isOnion

      public boolean isOnion()
    • setCredentials

      public MoneroRpcConnection setCredentials(String username, String password)
    • getUsername

      public String getUsername()
    • getPassword

      public String getPassword()
    • getZmqUri

      public String getZmqUri()
    • setZmqUri

      public MoneroRpcConnection setZmqUri(String zmqUri)
    • getProxyUri

      public String getProxyUri()
    • setProxyUri

      public MoneroRpcConnection setProxyUri(String proxyUri)
    • getSslVerify

      public boolean getSslVerify()
    • setSslVerify

      public MoneroRpcConnection setSslVerify(boolean sslVerify)
      Enable or disable TLS certificate and hostname verification for HTTPS connections. Verification is enabled by default. Disabling it allows connecting to daemons with self-signed certificates or certificates whose subject alternative names do not match the address (e.g. connecting by raw IP). Requests sent through this connection still fail if Java cannot parse the certificate, as with the certificate monerod generates by default, which has no issuer name.
      Parameters:
      sslVerify - true to verify certificates (default), false to allow insecure connections
      Returns:
      this connection
    • setPriority

      public MoneroRpcConnection setPriority(int priority)
      Set the connection's priority relative to other connections. Priority 1 is highest, then priority 2, etc. The default priority of 0 is lowest priority.
      Parameters:
      priority - is the connection priority (default 0)
      Returns:
      this connection
    • getPriority

      public int getPriority()
    • setTimeout

      public MoneroRpcConnection setTimeout(Long timeoutMs)
      Set the RPC request timeout in milliseconds.
      Parameters:
      timeoutMs - is the timeout in milliseconds, 0 to disable timeout, or null to use default
      Returns:
      this connection
    • getTimeout

      public Long getTimeout()
    • setAttribute

      public MoneroRpcConnection setAttribute(String key, Object value)
    • getAttribute

      public Object getAttribute(String key)
    • checkConnection

      public boolean checkConnection(long timeoutMs)
      Check the connection and update online, authentication, and response time status.
      Parameters:
      timeoutMs - the maximum response time before considered offline
      Returns:
      true if there is a change in status, false otherwise
    • isConnected

      public Boolean isConnected()
      Indicates if the connection is connected, which is set automatically by calling checkConnection().
      Returns:
      true or false to indicate if connected, or null if checkConnection() has not been called
    • isOnline

      public Boolean isOnline()
      Indicates if the connection is online, which is set automatically by calling checkConnection().
      Returns:
      true or false to indicate if online, or null if checkConnection() has not been called
    • setOnline

      public void setOnline(Boolean isOnline)
      Set the connection's online status.
      Parameters:
      isOnline - sets if the connection is online
    • isAuthenticated

      public Boolean isAuthenticated()
      Indicates if the connection is authenticated, which is set automatically by calling checkConnection().
      Returns:
      true if authenticated or no authentication, false if not authenticated, or null if not set
    • setAuthenticated

      public void setAuthenticated(Boolean isAuthenticated)
      Set the connection's authentication status.
      Parameters:
      isAuthenticated - sets if the connection is authenticated
    • getResponseTime

      public Long getResponseTime()
      Get the response time, which is set automatically by calling checkConnection().
      Returns:
      the response time of this connection in milliseconds
    • setResponseTime

      public void setResponseTime(Long responseTimeMs)
      Set the connection's response time.
      Parameters:
      responseTimeMs - is the response time in milliseconds
    • sendJsonRequest

      public Map<String,Object> sendJsonRequest(String method)
      Send a request to the RPC API.
      Parameters:
      method - specifies the method to request
      Returns:
      the RPC API response as a map
    • sendJsonRequest

      public Map<String,Object> sendJsonRequest(String method, Object params)
      Send a request to the RPC API.
      Parameters:
      method - is the method to request
      params - are the request's input parameters (supports <Map<String, Object>, List<Object></code>, String, etc)
      Returns:
      the RPC API response as a map
    • sendJsonRequest

      public Map<String,Object> sendJsonRequest(String method, Object params, Long timeoutMs)
      Send a request to the RPC API.
      Parameters:
      method - is the method to request
      params - are the request's input parameters (supports <Map<String, Object>, List<Object></code>, String, etc)
      timeoutMs - overrides the request timeout in milliseconds
      Returns:
      the RPC API response as a map
    • sendPathRequest

      public Map<String,Object> sendPathRequest(String path)
      Send a RPC request to the given path and with the given paramters. E.g. "/get_transactions" with params
      Parameters:
      path - is the url path of the request to invoke
      Returns:
      the request's deserialized response
    • sendPathRequest

      public Map<String,Object> sendPathRequest(String path, Map<String,Object> params)
      Send a RPC request to the given path and with the given paramters. E.g. "/get_transactions" with params
      Parameters:
      path - is the url path of the request to invoke
      params - are request parameters sent in the body
      Returns:
      the request's deserialized response
    • sendPathRequest

      public Map<String,Object> sendPathRequest(String path, Map<String,Object> params, Long timeoutMs)
      Send a RPC request to the given path and with the given paramters. E.g. "/get_transactions" with params
      Parameters:
      path - is the url path of the request to invoke
      params - are request parameters sent in the body
      timeoutMs - overrides the request timeout in milliseconds
      Returns:
      the request's deserialized response
    • sendBinaryRequest

      public byte[] sendBinaryRequest(String path, Map<String,Object> params)
      Send a binary RPC request.
      Parameters:
      path - is the path of the binary RPC method to invoke
      params - are the request parameters
      Returns:
      byte[] is the binary response
    • sendBinaryRequest

      public byte[] sendBinaryRequest(String path, Map<String,Object> params, Long timeoutMs)
      Send a binary RPC request.
      Parameters:
      path - is the path of the binary RPC method to invoke
      params - are the request parameters
      timeoutMs - overrides the request timeout in milliseconds
      Returns:
      byte[] is the binary response
    • setPrintStackTrace

      public void setPrintStackTrace(boolean printStackTrace)
      Enable or disable printing a stack trace on each request for debug.
      Parameters:
      printStackTrace - sets if the stack trace should be printed
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object