Package convex.peer

Class ConnectionManager

java.lang.Object
convex.peer.AThreadedComponent
convex.peer.ConnectionManager

public class ConnectionManager extends AThreadedComponent
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
  • Constructor Details

    • ConnectionManager

      public ConnectionManager(Server server)
  • Method Details

    • maintainConnections

      protected void maintainConnections()
    • closeConnection

      public void closeConnection(AccountKey peerKey)
      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

      public HashMap<AccountKey,Connection> getConnections()
      Gets the current set of outbound peer connections from this server
      Returns:
      Set of connections
    • isConnected

      public boolean isConnected(AccountKey peerKey)
      Return true if a specified Peer is connected
      Parameters:
      peerKey - Public Key of Peer
      Returns:
      True if connected
    • getConnection

      public Connection getConnection(AccountKey peerKey)
      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

      public void processChallenge(Message m, Peer thisPeer)
    • requestChallenge

      public void requestChallenge(AccountKey toPeerKey, Connection connection, Peer thisPeer)
      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 connection
      thisPeer - Source peer that the challenge is issued from
    • broadcast

      public void broadcast(Message msg) throws InterruptedException
      Broadcasts a Message to all connected Peers
      Parameters:
      msg - Message to broadcast
      Throws:
      InterruptedException - If broadcast is interrupted
    • connectToPeer

      public Connection connectToPeer(InetSocketAddress hostAddress)
      Connects explicitly to a Peer at the given host address
      Parameters:
      hostAddress - Address to connect to
      Returns:
      new Connection, or null if attempt fails
    • close

      public void close()
      Description copied from class: AThreadedComponent
      Close this threaded component, including interrupting any running thread(s). Subclasses may override, but should call `super.close()` to close the main thread
      Overrides:
      close in class AThreadedComponent
    • start

      public void start()
      Description copied from class: AThreadedComponent
      Start the threaded component
      Overrides:
      start in class AThreadedComponent
    • loop

      protected void loop() throws InterruptedException
      Specified by:
      loop in class AThreadedComponent
      Throws:
      InterruptedException
    • getThreadName

      protected String getThreadName()
      Specified by:
      getThreadName in class AThreadedComponent