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 server that can be launched with a config. Server creates the following threads: - A ReceiverThread that processes message from the Server's receive Queue - An UpdateThread that handles Belief updates and transaction processing - A ConnectionManager thread, via the ConnectionManager "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

  • 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.
      event - Event interface where the server will send information about the peer
      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 Server
      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
    • maybeUpdateBelief

      protected boolean maybeUpdateBelief() throws InterruptedException
      Handle general Belief update, taking belief registered in newBeliefs
      Returns:
      true if Peer Belief changed, false otherwise
      Throws:
      InterruptedException
    • getBroadcastCount

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

      protected boolean maybePublishBlock()
      Checks for pending transactions, and if found propose them as a new Block.
      Returns:
      True if a new block is published, false otherwise.
    • 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
    • queueEvent

      public void queueEvent(SignedData<?> event) throws InterruptedException
      Adds an event to the inbound server event queue. May block.
      Parameters:
      event - Signed event to add to inbound event queue
      Throws:
      InterruptedException
    • queueMessage

      public void queueMessage(Message m) throws InterruptedException
      Queues a message for processing by this Server. May block briefly.
      Parameters:
      m - Message to queue
      Throws:
      InterruptedException
    • maybeMergeBeliefs

      protected boolean maybeMergeBeliefs()
      Checks for mergeable remote beliefs, and if found merge and update own belief.
      Returns:
      True if Peer Belief Order was changed, false otherwise.
    • 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 void persistPeerData()
      Writes the Peer data to the configured store. This will overwrite any previously persisted peer data.
    • 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.
      Returns:
      Store instance
    • raiseServerChange

      public void raiseServerChange(String reason)
      Reports a server change event to the registered hook, if any
      Parameters:
      reason - Message for server change
    • getConnectionManager

      public ConnectionManager getConnectionManager()
    • getConfig

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

      public Consumer<Message> getReceiveAction()
    • 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()