Package convex.api

Class ConvexRemote

java.lang.Object
convex.api.Convex
convex.api.ConvexRemote

public class ConvexRemote extends Convex
  • Field Details

    • connection

      protected Connection connection
      Current Connection to a Peer, may be null or a closed connection.
  • Constructor Details

    • ConvexRemote

      protected ConvexRemote(Address address, AKeyPair keyPair)
  • Method Details

    • getRemoteAddress

      public InetSocketAddress getRemoteAddress()
      Gets the Internet address of the currently connected remote
      Returns:
      Remote socket address
    • connectToPeer

      protected void connectToPeer(InetSocketAddress peerAddress, AStore store) throws IOException, TimeoutException
      Throws:
      IOException
      TimeoutException
    • setConnection

      protected void setConnection(Connection conn)
      Sets the current Connection for this Remote Client
      Parameters:
      conn - Connection value to use
    • getConnection

      public Connection getConnection()
      Gets the underlying Connection instance for this Client. May be null if not connected.
      Returns:
      Connection instance or null
    • isConnected

      public boolean isConnected()
      Checks if this Convex client instance has an open remote connection.
      Specified by:
      isConnected in class Convex
      Returns:
      true if connected, false otherwise
    • closeButMaintainConnection

      public void closeButMaintainConnection()
      Close without affecting the connection
    • acquireState

      public CompletableFuture<State> acquireState() throws TimeoutException
      Gets the consensus state from the connected Peer. The acquired state will be a snapshot of the network global state as calculated by the Peer. SECURITY: Be aware that if this client instance is connected to an untrusted Peer, the Peer may lie about the latest state. If this is a security concern, the client should validate the consensus state independently.
      Specified by:
      acquireState in class Convex
      Returns:
      Future for consensus state
      Throws:
      TimeoutException - If initial status request times out
    • transact

      public CompletableFuture<Result> transact(SignedData<ATransaction> signed) throws IOException
      Description copied from class: Convex
      Submits a signed transaction to the Convex network, returning a Future once the transaction has been successfully queued. Updates cached sequence number on best effort basis.
      Specified by:
      transact in class Convex
      Parameters:
      signed - Signed transaction to execute
      Returns:
      A Future for the result of the transaction
      Throws:
      IOException - If the connection is broken or send buffer is full
    • query

      public CompletableFuture<Result> query(ACell query, Address address) throws IOException
      Description copied from class: Convex
      Submits a query to the Convex network, returning a Future once the query has been successfully queued.
      Specified by:
      query in class Convex
      Parameters:
      query - Query to execute, as a Form or Op
      address - Address to use for the query
      Returns:
      A Future for the result of the query
      Throws:
      IOException - If the connection is broken, or the send buffer is full
    • requestStatus

      public CompletableFuture<Result> requestStatus()
      Description copied from class: Convex
      Submits a status request to the Convex network peer, returning a Future once the request has been successfully queued.
      Specified by:
      requestStatus in class Convex
      Returns:
      A Future for the result of the requestStatus
    • requestChallenge

      public CompletableFuture<Result> requestChallenge(SignedData<ACell> data) throws IOException
      Description copied from class: Convex
      Request a challenge. This is request is made by any peer that needs to find out if another peer can be trusted.
      Specified by:
      requestChallenge in class Convex
      Parameters:
      data - Signed data to send to the peer for the challenge.
      Returns:
      A Future for the result of the requestChallenge
      Throws:
      IOException - if the connection fails.
    • acquire

      public <T extends ACell> CompletableFuture<T> acquire(Hash hash, AStore store)
      Description copied from class: Convex
      Attempts to acquire a complete persistent data structure for the given hash from the connected peer. Uses the store provided as a destination.
      Specified by:
      acquire in class Convex
      Parameters:
      hash - Hash of value to acquire.
      store - Store to acquire the persistent data to.
      Returns:
      Future for the Cell being acquired. May fail exceptionally or timeout if the given data cannot be acquired (most likely missing from the peer's store)
    • close

      public void close()
      Disconnects the client from the network, closing the underlying connection.
      Specified by:
      close in class Convex
    • wrap

      public static ConvexRemote wrap(Connection c)
      Wraps a connection as a Convex client instance
      Parameters:
      c - Connection to wrap
      Returns:
      New Convex client instance using underlying connection
    • toString

      public String toString()
      Specified by:
      toString in class Convex