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 responf 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.
  • Method Details

    • create

      public static Server create(HashMap<Keyword,Object> config) throws TimeoutException, IOException
      Creates a new (unlaunched) Server with a given config.
      Parameters:
      config - Server configuration map. Will be defensively copied.
      Returns:
      New Server instance
      Throws:
      IOException - If an IO Error occurred establishing the Peer
      TimeoutException - If Peer creation timed out
    • 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()
      Launch the Peer Server, including all main server threads
    • 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 If the message is partial, will be queued pending delivery of missing data. Runs on receiver thread
      Parameters:
      m -
    • handleMissingData

      protected void handleMissingData(Message m)
      Respond to a request for missing data, on a best-efforts basis. Requests for missing data we do not hold are ignored.
      Parameters:
      m -
      Throws:
      BadFormatException
    • 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
    • setPeerController

      public void setPeerController(Address a)
      Sets the Peer controller Address
      Parameters:
      a - Peer Controller Address to set
    • queueBelief

      public boolean queueBelief(Message event)
      Adds an event to the inbound server event queue. May block.
      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)
    • getStatusVector

      public AVector<ACell> getStatusVector()
      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 5 = consensus point 6 = proposal point 7 = ordering length
      Returns:
      Status vector
    • 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 int getPort()
      Gets the port that this Server is currently accepting connections on
      Returns:
      Port number
    • finalize

      public void finalize()
      Overrides:
      finalize in class Object
    • persistPeerData

      public boolean persistPeerData()
      Writes the Peer data to the configured store. Note: Does not flush buffers to disk. This will overwrite any previously persisted peer data.
      Returns:
      True if successfully persisted, false in case of any 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
    • 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()
    • getTransactionHandler

      public TransactionHandler getTransactionHandler()
    • getBeliefPropagator

      public BeliefPropagator getBeliefPropagator()
    • updateBelief

      public void updateBelief(Belief belief)
    • getCVMExecutor

      public CVMExecutor getCVMExecutor()
    • getQueryProcessor

      public QueryHandler getQueryProcessor()