java.lang.Object
convex.peer.API
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 Summary
FieldsModifier and TypeFieldDescriptionprotected static final org.slf4j.Logger
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionensureStatusMap
(ACell statusValue) Converts a status map or value vector to a status maplaunchLocalPeers
(List<AKeyPair> keyPairs, State genesisState) Launch a local set of peers.launchLocalPeers
(List<AKeyPair> keyPairs, State genesisState, int[] peerPorts) Launch a local set of peers.static Server
Launches a peer with a default configuration.static Server
launchPeer
(Map<Keyword, Object> peerConfig) Launches a Peer Server with a supplied configuration.static ArrayList
<AccountKey> Gets the list of peers registered in the given Etch Store
-
Field Details
-
log
protected static final org.slf4j.Logger log -
STATUS_KEYS
-
-
Constructor Details
-
API
public API()
-
-
Method Details
-
launchPeer
public static Server launchPeer(Map<Keyword, Object> peerConfig) throws LaunchException, InterruptedException, ConfigExceptionLaunches 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 interruptConfigException
- if configuration is invalidLaunchException
-
launchPeer
Launches a peer with a default configuration. Mainly for testing.- Returns:
- Newly launched Server instance
- Throws:
InterruptedException
- in case of interruptConfigException
- in case of configuration errorLaunchException
- 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 peersgenesisState
- genesis state for local network- Returns:
- List of Servers launched
- Throws:
InterruptedException
- in case of interruptConfigException
- in case of configuration errorLaunchException
- 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 peersgenesisState
- Genesis state for local networkpeerPorts
- 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 interruptConfigException
- in case of configuration errorLaunchException
- if launch failed for some reason
-
listPeers
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
Converts a status map or value vector to a status map- Parameters:
statusValue
-- Returns:
- Map containing status values
-