Module convex.peer
Package convex.peer

Class Server

java.lang.Object
convex.peer.Server
All Implemented Interfaces:
Closeable, AutoCloseable

public class Server extends Object implements Closeable
A self contained Peer Server that can be launched with a config. The primary role for the Server is to respond to incoming messages and maintain network consensus. Components contained within the Server handle specific tasks, e.g: - Client transaction handling - CPoS Belief merges - Belief Propagation - CVM Execution "Programming is a science dressed up as art, because most of us don't understand the physics of software and it's rarely, if ever, taught. The physics of software is not algorithms, data structures, languages, and abstractions. These are just tools we make, use, and throw away. The real physics of software is the physics of people. Specifically, it's about our limitations when it comes to complexity and our desire to work together to solve large problems in pieces. This is the science of programming: make building blocks that people can understand and use easily, and people will work together to solve the very largest problems." ― Pieter Hintjens
  • Field Details

    • DEFAULT_PORT

      public static final int DEFAULT_PORT
      See Also:
    • manager

      protected final ConnectionManager manager
      Connection manager instance.
    • propagator

      protected final BeliefPropagator propagator
      Connection manager instance.
    • transactionHandler

      protected final TransactionHandler transactionHandler
      Transaction handler instance.
    • executor

      protected final CVMExecutor executor
      Transaction handler instance.
    • queryHandler

      protected final QueryHandler queryHandler
      Query handler instance.
    • sTATUS_KEYS

      public static final AVector<Keyword> sTATUS_KEYS
  • Method Details

    • syncPeer

      public Peer syncPeer(AKeyPair keyPair, Convex convex) throws LaunchException, InterruptedException
      Throws:
      LaunchException
      InterruptedException
    • create

      public static Server create(HashMap<Keyword,Object> config) throws ConfigException
      Creates a new (unlaunched) Server with a given config.
      Parameters:
      config - Server configuration map. Will be defensively copied.
      Returns:
      New Server instance
      Throws:
      ConfigException - If Peer configuration failed, possible multiple causes
    • setMessageReceiveObserver

      public void setMessageReceiveObserver(Consumer<Message> observer)
    • getBelief

      public Belief getBelief()
      Gets the current Belief held by this Peer
      Returns:
      Current Belief
    • getPeer

      public Peer getPeer()
      Gets the current Peer data structure for this Server.
      Returns:
      Current Peer data
    • getHostname

      public String getHostname()
      Gets the desired host name for this Peer
      Returns:
      Hostname String
    • launch

      public void launch() throws LaunchException, InterruptedException
      Launch the Peer Server, including all main server threads
      Throws:
      InterruptedException
      LaunchException
    • processMessage

      protected void processMessage(Message m)
      Process a message received from a peer or client. We know at this point that the message decoded successfully, not much else..... SECURITY: Should anticipate malicious messages Runs on receiver thread, so we want to offload to a queue ASAP, never block
      Parameters:
      m -
    • processTransact

      protected void processTransact(Message m)
    • processClose

      protected void processClose(Message m)
      Called by a remote peer to close connections to the remote peer.
    • getBroadcastCount

      public long getBroadcastCount()
      Gets the number of belief broadcasts made by this Peer
      Returns:
      Count of broadcasts from this Server instance
    • getBeliefReceivedCount

      public long getBeliefReceivedCount()
      Gets the number of beliefs received by this Peer
      Returns:
      Count of the beliefs received by this Server instance
    • getPeerController

      public Address getPeerController()
      Gets the Peer controller Address
      Returns:
      Peer controller Address, or null if peer is not registered
    • queueBelief

      public boolean queueBelief(Message event)
      Adds an event to the inbound server event queue.
      Parameters:
      event - Signed event to add to inbound event queue
      Returns:
      True if Belief was successfullly queued, false otherwise
    • processStatus

      protected void processStatus(Message m)
    • getStatusData

      public AVector<ACell> getStatusData()
      Gets the status vector for the Peer 0 = latest belief hash 1 = states vector hash 2 = genesis state hash 3 = peer key 4 = consensus state hash 5 = consensus point 6 = proposal point 7 = ordering length 8 = consensus point vector
      Returns:
      Status vector
    • getStatusMap

      public AMap<Keyword,ACell> getStatusMap()
    • processResponse

      protected void processResponse(Message m)
    • processQuery

      protected void processQuery(Message m)
    • processBelief

      protected void processBelief(Message m)
      Process an incoming message that represents a Belief
      Parameters:
      m -
    • getPort

      public Integer getPort()
      Gets the port that this Server is currently accepting connections on
      Returns:
      Port number
    • persistPeerData

      public Peer persistPeerData() throws IOException
      Writes the Peer data to the configured store. Note: Does not flush buffers to disk. This will overwrite any previously persisted peer data.
      Returns:
      Updated Peer value with persisted data
      Throws:
      IOException - In case of any IO Error
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • getHostAddress

      public InetSocketAddress getHostAddress()
      Gets the host address for this Server (including port), or null if closed
      Returns:
      Host Address
    • getKeyPair

      public AKeyPair getKeyPair()
      Returns the Keypair for this peer server SECURITY: Be careful with this!
      Returns:
      Key pair for Peer
    • getPeerKey

      public AccountKey getPeerKey()
      Gets the public key of the peer account
      Returns:
      AccountKey of this Peer
    • getControllerKey

      public AKeyPair getControllerKey()
      Gets the peer controller key for the Server, if available
      Returns:
      Keypair for controller
    • getStore

      public AStore getStore()
      Gets the Store configured for this Server. A server must consistently use the same store instance for all Server threads, as values may be shared.
      Returns:
      Store instance
    • getConnectionManager

      public ConnectionManager getConnectionManager()
    • getConfig

      public HashMap<Keyword,Object> getConfig()
    • getReceiveAction

      public Consumer<Message> getReceiveAction()
      Gets the action to perform for an incoming client message
      Returns:
      Message consumer
    • setHostname

      public void setHostname(String string)
      Sets the desired host name for this Server
      Parameters:
      string - Desired host name String, e.g. "my-domain.com:12345"
    • isLive

      public boolean isLive()
      Checks is the server is Live, i.e. currently syncing successfully with network
      Returns:
      True if live, false otherwise
    • isRunning

      public boolean isRunning()
      Checks if the Server threads are running
      Returns:
      True if running, false otherwise
    • getTransactionHandler

      public TransactionHandler getTransactionHandler()
    • getBeliefPropagator

      public BeliefPropagator getBeliefPropagator()
    • updateBelief

      public void updateBelief(Belief belief)
      Triggers CVM Executor Belief update
      Parameters:
      belief - New Belief
    • getCVMExecutor

      public CVMExecutor getCVMExecutor()
    • getQueryProcessor

      public QueryHandler getQueryProcessor()
    • shutdown

      public void shutdown()
      Shut down the Server, as gracefully as possible.
    • waitForShutdown

      public void waitForShutdown() throws InterruptedException
      Throws:
      InterruptedException
    • fromPeerData

      public static Server fromPeerData(AKeyPair kp, AMap<Keyword,ACell> peerData) throws LaunchException, ConfigException, InterruptedException
      Throws:
      LaunchException
      ConfigException
      InterruptedException