Package connection.peer.secure

Source Code of connection.peer.secure.ClientSideSecurableConnection

package connection.peer.secure;


import handlers.AbstractContextualHandler;
import handlers.sets.ClientSideSecurityHandlerSet;

import java.io.IOException;

import common.connection.AbstractConnection;
import common.handlers.AbstractHandlerSet;
import connection.peer.secure.reconnector.ClientSideReconnector;

import main.PeerProtocol;
import main.settings.Settings;


public class ClientSideSecurableConnection extends AbstractSecurableConnection
{
  private static final ClientSideSecurityHandlerSet HANDLER_SET = new ClientSideSecurityHandlerSet();

  public ClientSideSecurableConnection(ConnectionSecurerInterface requestor)
      throws IOException
  {
    super(requestor);
  }

  protected SecurityAbility determineSecurityAbility()
  {
    if (Settings.connection.security.to_peers)
    {
      return SecurityAbility.WANT;
    }
    else
    {
      return SecurityAbility.CAN;
    }
  }

  public void initializeConnection() throws IOException
  {
    if (getSecurityAbility() == SecurityAbility.WANT)
    {
      requestSecurityLevel(PeerProtocol.Link.OP_SECURE);
    }
    else
    {
      requestSecurityLevel(PeerProtocol.Link.OP_PLAIN);
    }
  }

  private void requestSecurityLevel(int opcode)
  {
    int protocolId = PeerProtocol.PROTOCOL_LINK;
    send(protocolId, opcode);
  }

  protected AbstractHandlerSet getHandlerSet()
  {
    return HANDLER_SET;
  }

  public AbstractContextualHandler getContextualHandler(int protocolId, int opcode)
      throws IOException, ClassNotFoundException
  {
    return ClientSideSecurityHandlerSet.HANDLERS[protocolId][opcode]
        .createContext(this);
  }

  protected AbstractConnection reconnect(ConnectionSecurerInterface securer)
      throws IOException
  {
    return new ClientSideReconnector(this, securer).reconnect();
  }

}
TOP

Related Classes of connection.peer.secure.ClientSideSecurableConnection

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.