Package convex.peer
Class Server
java.lang.Object
convex.peer.Server
- All Implemented Interfaces:
Closeable
,AutoCloseable
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final int
protected final CVMExecutor
Transaction handler instance.protected final ConnectionManager
Connection manager instance.protected final BeliefPropagator
Connection manager instance.protected final QueryHandler
Query handler instance.protected final TransactionHandler
Transaction handler instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
static Server
Creates a new (unlaunched) Server with a given config.void
finalize()
Gets the current Belief held by this Peerlong
Gets the number of beliefs received by this Peerlong
Gets the number of belief broadcasts made by this PeerGets the host address for this Server (including port), or null if closedGets the desired host name for this PeerReturns the Keypair for this peer server SECURITY: Be careful with this!getPeer()
Gets the current Peer data structure for thisServer
.Gets the Peer controller AddressGets the public key of the peer accountint
getPort()
Gets the port that this Server is currently accepting connections onGets the action to perform for an incoming client messageGets 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 8 = consensus point vectorgetStore()
Gets the Store configured for this Server.protected void
Respond to a request for missing data, on a best-efforts basis.boolean
isLive()
Checks is the server is Live, i.e.boolean
Checks if the Server threads are runningvoid
launch()
Launch the Peer Server, including all main server threadsWrites the Peer data to the configured store.protected void
Process an incoming message that represents a Beliefprotected void
Called by a remote peer to close connections to the remote peer.protected void
Process a message received from a peer or client.protected void
protected void
protected void
protected void
boolean
queueBelief
(Message event) Adds an event to the inbound server event queue.void
setHostname
(String string) Sets the desired host name for this Servervoid
setMessageReceiveObserver
(Consumer<Message> observer) void
shutdown()
Shut down the Server, as gracefully as possible.void
updateBelief
(Belief belief) Triggers CVM Executor Belief update
-
Field Details
-
DEFAULT_PORT
public static final int DEFAULT_PORT- See Also:
-
manager
Connection manager instance. -
propagator
Connection manager instance. -
transactionHandler
Transaction handler instance. -
executor
Transaction handler instance. -
queryHandler
Query handler instance.
-
-
Method Details
-
create
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 PeerTimeoutException
- If Peer creation timed out
-
setMessageReceiveObserver
-
getBelief
-
getPeer
-
getHostname
-
launch
public void launch()Launch the Peer Server, including all main server threads -
processMessage
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- Parameters:
m
-
-
handleDataRequest
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
-
processClose
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
Gets the Peer controller Address- Returns:
- Peer controller Address
-
queueBelief
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
-
getStatusVector
-
processResponse
-
processQuery
-
processBelief
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
-
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:
- Updater Peer value with persisted data
- Throws:
IOException
- In case of any IO Error
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
getHostAddress
Gets the host address for this Server (including port), or null if closed- Returns:
- Host Address
-
getKeyPair
Returns the Keypair for this peer server SECURITY: Be careful with this!- Returns:
- Key pair for Peer
-
getPeerKey
Gets the public key of the peer account- Returns:
- AccountKey of this Peer
-
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
-
getConfig
-
getReceiveAction
-
setHostname
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:
-
isRunning
public boolean isRunning()Checks if the Server threads are running- Returns:
-
getTransactionHandler
-
getBeliefPropagator
-
updateBelief
Triggers CVM Executor Belief update- Parameters:
belief
- New Belief
-
getCVMExecutor
-
getQueryProcessor
-
shutdown
Shut down the Server, as gracefully as possible.- Throws:
TimeoutException
- If shitdown attempt times outIOException
- In case of IO Error
-