Module convex.peer
Package convex.peer

Class API

java.lang.Object
convex.peer.API

public class API extends Object
Class providing a simple API to operate a peer protocol Server. Suitable for library usage, e.g. if a user application wants to instantiate a local network peer. "If you don't believe it or don't get it , I don't have time to convince you" - Satoshi Nakamoto
  • Field Details

    • log

      protected static final org.slf4j.Logger log
    • STATUS_KEYS

      public static final AVector<Keyword> STATUS_KEYS
  • Constructor Details

    • API

      public API()
  • Method Details

    • launchPeer

      public static Server launchPeer(Map<Keyword,Object> peerConfig) throws LaunchException, InterruptedException, ConfigException

      Launches a Peer Server with a supplied configuration.

      Config keys are:

      • :keypair (required, AKeyPair) - AKeyPair instance.
      • :port (optional, Integer) - Integer port number to use for incoming connections. Zero causes random allocation (also the default).
      • :store (optional, AStore or String filename) - AStore instance. Defaults to the configured global store
      • :keystore (optional, Keystore or string filename) - Keystore instance. Read only, used for key lookup if necessary.
      • :storepass (optional, string) - Integrity password for keystore. If omitted, no integrity check is performed
      • :source (optional, String or Socket Address) - URL for Peer to replicate initial State/Belief from.
      • :state (optional, State) - Genesis state. Defaults to a fresh genesis state for the Peer if neither :source nor :state is specified
      • :restore (optional, Boolean) - Boolean Flag to restore from existing store. Default to true
      • :persist (optional, Boolean) - Boolean flag to determine if peer state should be persisted in store at server close. Default true.
      • :url (optional, String) - public URL for server. If provided, peer will set its public on-chain address based on this.
      • :auto-manage (optional Boolean) - set to true for peer to auto-manage own account. Defaults to true.
      • :bind-address (optional String) - IP address of the ethernet device to bind too.
      Parameters:
      peerConfig - Configuration map for the new Peer
      Returns:
      New peer Server instance
      Throws:
      InterruptedException - in case of interrupt
      ConfigException - if configuration is invalid
      LaunchException
    • launchPeer

      public static Server launchPeer() throws InterruptedException, ConfigException, LaunchException
      Launches a peer with a default configuration. Mainly for testing.
      Returns:
      Newly launched Server instance
      Throws:
      InterruptedException - in case of interrupt
      ConfigException - in case of configuration error
      LaunchException - if launch failed for some reason
    • launchLocalPeers

      public static List<Server> launchLocalPeers(List<AKeyPair> keyPairs, State genesisState) throws InterruptedException, ConfigException, LaunchException
      Launch a local set of peers. Intended mainly for testing / development. The Peers will have a unique genesis State, i.e. an independent network
      Parameters:
      keyPairs - List of keypairs for peers
      genesisState - genesis state for local network
      Returns:
      List of Servers launched
      Throws:
      InterruptedException - in case of interrupt
      ConfigException - in case of configuration error
      LaunchException - if launch failed for some reason
    • launchLocalPeers

      public static List<Server> launchLocalPeers(List<AKeyPair> keyPairs, State genesisState, int[] peerPorts) throws InterruptedException, ConfigException, LaunchException
      Launch a local set of peers. Intended mainly for testing / development. The Peers will have a unique genesis State, i.e. an independent network
      Parameters:
      keyPairs - List of keypairs for peers
      genesisState - Genesis state for local network
      peerPorts - Array of ports to use for each peer, if == null then randomly assign port numbers
      Returns:
      List of Servers launched
      Throws:
      InterruptedException - in case of interrupt
      ConfigException - in case of configuration error
      LaunchException - if launch failed for some reason
    • listPeers

      public static ArrayList<AccountKey> listPeers(AStore store) throws IOException
      Gets the list of peers registered in the given Etch Store
      Parameters:
      store - Store from which to read peers
      Returns:
      A new ArrayList of keys, or null if peer list not present
      Throws:
      IOException - in case of IO error reading peers from store
    • ensureStatusMap

      public static AMap<Keyword,ACell> ensureStatusMap(ACell statusValue)
      Converts a status map or value vector to a status map
      Parameters:
      statusValue -
      Returns:
      Map containing status values