Package convex.peer
Class ConnectionManager
java.lang.Object
convex.peer.ConnectionManager
Class for managing the outbound 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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
close()
void
Close all outgoing connections from this Peervoid
closeConnection(AccountKey peerKey)
Close and remove a connectionconnectToPeer(InetSocketAddress hostAddress)
Connects explicitly to a Peer at the given host addressvoid
connectToPeerAsync(InetSocketAddress hostAddress)
Schedules a request to connect to a Peer at the given host addressgetConnection(AccountKey peerKey)
Gets a connection based on the peers public keyint
Returns the number of active connectionsGets the current set of outbound peer connections from this serverint
Returns the number of trusted connectionsboolean
isConnected(AccountKey peerKey)
Return true if a specified Peer is connectedprotected void
void
processChallenge(Message m, Peer thisPeer)
void
requestChallenge(AccountKey toPeerKey, Connection connection, Peer thisPeer)
Sends out a challenge to a connection that is not trusted.void
setConnection(AccountKey peerKey, Connection peerConnection)
void
start()
-
Field Details
-
server
-
-
Constructor Details
-
ConnectionManager
-
-
Method Details
-
maintainConnections
protected void maintainConnections() -
setConnection
-
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
-
getTrustedConnectionCount
public int getTrustedConnectionCount()Returns the number of trusted connections- Returns:
- Number of trusted 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
- Parameters:
msg
- Message to broadcastrequireTrusted
- If true, only broadcast to trusted peers
-
connectToPeer
Connects explicitly to a Peer at the given host address- Parameters:
hostAddress
- Address to connect to- Returns:
- new Connection, or null if attempt fails
-
connectToPeerAsync
Schedules a request to connect to a Peer at the given host address- Parameters:
hostAddress
- Address to connect to
-
start
public void start() -
close
public void close()
-