java.lang.Object
convex.peer.AThreadedComponent
convex.peer.ConnectionManager
Class for managing the outbound Peer connections from a Peer Server.
Outbound connections need special handling: - Should be trusted connections
to known peers - Should be targets for broadcast of belief updates - Should
be limited in number
-
Field Summary
Fields inherited from class convex.peer.AThreadedComponent
server, thread -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddConnection(AccountKey peerKey, Convex convex) voidalertBadMessage(Message m, String reason) Called to signal a bad / corrupt message from a Peer.voidalertMissing(Message m, MissingDataException e, AccountKey peerKey) Called to signal missing data in a Belief / OrdervoidBroadcasts a Message to all connected Peersvoidclose()Close this threaded component, including interrupting any running thread(s).voidClose all outgoing connections from this PeervoidcloseConnection(AccountKey peerKey, String reason) Close and remove a connectionconnectToPeer(InetSocketAddress hostAddress) Connects explicitly to a Peer at the given host addressgetConnection(AccountKey peerKey) Gets a connection based on the peers public keyintReturns the number of active connectionsGets the current set of outbound peer connections from this serverprotected StringbooleanisConnected(AccountKey peerKey) Return true if a specified Peer is connectedprotected voidloop()protected voidvoidprocessChallenge(Message m, Peer thisPeer) voidrequestChallenge(AccountKey toPeerKey, AConnection connection, Peer thisPeer) Sends out a challenge to a connection that is not trusted.voidstart()Start the threaded componentMethods inherited from class convex.peer.AThreadedComponent
getLoad
-
Constructor Details
-
ConnectionManager
-
-
Method Details
-
maintainConnections
- Throws:
InterruptedException
-
closeConnection
Close and remove a connection- Parameters:
peerKey- Peer key linked to the connection to close and remove.
-
closeAllConnections
public void closeAllConnections()Close all outgoing connections from this Peer -
getConnections
Gets the current set of outbound peer connections from this server- Returns:
- Set of connections
-
isConnected
Return true if a specified Peer is connected- Parameters:
peerKey- Public Key of Peer- Returns:
- True if connected
-
getConnection
Gets a connection based on the peers public key- Parameters:
peerKey- Public key of Peer- Returns:
- Connection instance, or null if not found
-
getConnectionCount
public int getConnectionCount()Returns the number of active connections- Returns:
- Number of connections
-
processChallenge
-
requestChallenge
Sends out a challenge to a connection that is not trusted.- Parameters:
toPeerKey- Peer key that we need to send the challenge too.connection- untrusted connectionthisPeer- Source peer that the challenge is issued from
-
broadcast
Broadcasts a Message to all connected Peers- Parameters:
msg- Message to broadcast
-
connectToPeer
public Convex connectToPeer(InetSocketAddress hostAddress) throws InterruptedException, IOException, TimeoutException Connects explicitly to a Peer at the given host address- Parameters:
hostAddress- Address to connect to- Returns:
- new Convex connection, or null if attempt fails
- Throws:
InterruptedExceptionTimeoutExceptionIOException
-
addConnection
-
close
public void close()Description copied from class:AThreadedComponentClose this threaded component, including interrupting any running thread(s). Subclasses may override, but should call `super.close()` to close the main thread- Overrides:
closein classAThreadedComponent
-
start
public void start()Description copied from class:AThreadedComponentStart the threaded component- Overrides:
startin classAThreadedComponent
-
loop
- Specified by:
loopin classAThreadedComponent- Throws:
InterruptedException
-
getThreadName
- Specified by:
getThreadNamein classAThreadedComponent
-
alertBadMessage
Called to signal a bad / corrupt message from a Peer.- Parameters:
m- Message of concernreason- Reason message considered bad
-
alertMissing
Called to signal missing data in a Belief / Order- Parameters:
m- Message which caused alerte- Missing data exception encounteredpeerKey- Peer key which triggered missing data
-