Package convex.peer
Class Server
java.lang.Object
convex.peer.Server
- All Implemented Interfaces:
Closeable
,AutoCloseable
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 Summary
FieldsModifier and TypeFieldDescriptionstatic int
protected ConnectionManager
Connection manager 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 PeerServerlong
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 this Server.Gets the Peer controller AddressGets the public key of the peer accountint
getPort()
Gets the port that this Server is currently accepting connections ongetStore()
Gets the Store configured for this Server.boolean
isLive()
void
launch()
Launch the Peer Server, including all main server threadsprotected boolean
Checks for mergeable remote beliefs, and if found merge and update own belief.protected boolean
Checks for pending transactions, and if found propose them as a new Block.protected boolean
Handle general Belief update, taking belief registered in newBeliefsvoid
Writes the Peer data to the configured store.void
queueEvent(SignedData<?> event)
Adds an event to the inbound server event queue.void
queueMessage(Message m)
Queues a message for processing by this Server.void
raiseServerChange(String reason)
Reports a server change event to the registered hook, if anyvoid
setHostname(String string)
Sets the desired host name for this Servervoid
Sets the Peer controller Address
-
Field Details
-
DEFAULT_PORT
public static final int DEFAULT_PORT- See Also:
- Constant Field Values
-
manager
Connection manager instance.
-
-
Method Details
-
create
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 PeerTimeoutException
- If Peer creation timed out
-
getBelief
Gets the current Belief held by this PeerServer- Returns:
- Current Belief
-
getPeer
Gets the current Peer data structure for this Server.- Returns:
- Current Peer
-
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
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
Gets the Peer controller Address- Returns:
- Peer controller Address
-
setPeerController
Sets the Peer controller Address- Parameters:
a
- Peer Controller Address to set
-
queueEvent
Adds an event to the inbound server event queue. May block.- Parameters:
event
- Signed event to add to inbound event queue- Throws:
InterruptedException
-
queueMessage
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() -
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 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.- Returns:
- Store instance
-
raiseServerChange
Reports a server change event to the registered hook, if any- Parameters:
reason
- Message for server change
-
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()
-