Example #1
0
    @Override
    public final void run() {
      try {
        final TcpPipe enclosing = TcpPipe.this;
        Log.log("startup send endpoint for %s @ ", enclosing, soport);

        Socket so = new Socket();
        so.setKeepAlive(true);
        so.setPerformancePreferences(SO_CONNTIME_PREF, SO_LATENCY_PREF, SO_BANDWIDTH_PREF);
        so.setTcpNoDelay(true);
        so.setSendBufferSize(SO_SND_BUFF_SIZE);

        Log.log("... connecting to port %d", soport);
        final InetAddress localhost = InetAddress.getLocalHost();
        SocketAddress endpoint = new InetSocketAddress(localhost, soport);

        so.connect(endpoint);
        Log.log("client connected to %s", so.getRemoteSocketAddress());

        if (!sndsocket_ref.compareAndSet(null, so))
          throw new IllegalStateException("sendInUpdater");

        Log.log("-- SND endpoint connected to remote endpoint %s", so.getRemoteSocketAddress());

      } catch (Exception e) {
        throw new RuntimeException("SND bootstrap failed", e);
      } finally {
        Log.log("SND endpoint established");
      }
    }
Example #2
0
  // Client constructor
  public Messenger(InetAddress server, int port) {
    try {
      // No server socket in use
      serverSocket = null;

      // Connect to server instead
      clientSocket = new Socket();
      configureClientSocket();
      clientSocket.setPerformancePreferences(0, 1, 0); // Prioritize latency
      clientSocket.connect(new InetSocketAddress(server, port), SOCKET_CONNECT_TIMEOUT);
      configureOutbox();
    } catch (IOException ex) {
      throw new ProcessCommunicationException(ex);
    }
  }
Example #3
0
    @Override
    public final void run() {
      try {
        final TcpPipe enclosing = TcpPipe.this;
        Log.log("startup reciever endpoint for %s", enclosing);

        ServerSocket server = new ServerSocket(0);
        server.setPerformancePreferences(SO_CONNTIME_PREF, SO_LATENCY_PREF, SO_BANDWIDTH_PREF);
        server.setReceiveBufferSize(SO_RCV_BUFF_SIZE);

        int soport = server.getLocalPort();

        Log.log("-- RCV endpoint server socket opened on port %d", soport);

        if (!port_ref.compareAndSet(INIT_PORT, soport))
          throw new IllegalStateException("portUpdater");

        Log.log("-- RCV endpoint port set to %d", port_ref.get());

        Log.log("-- RCV endpoint now accepting connection ..");
        latch.countDown();
        Socket socket = server.accept();
        socket.setKeepAlive(true);
        socket.setPerformancePreferences(SO_CONNTIME_PREF, SO_LATENCY_PREF, SO_BANDWIDTH_PREF);
        socket.setTcpNoDelay(true);
        socket.setSendBufferSize(SO_RCV_BUFF_SIZE);
        SocketAddress remsoaddr = socket.getRemoteSocketAddress();

        Log.log("-- RCV endpoint accepted connection from %s", remsoaddr);

        if (!rcvsocket_ref.compareAndSet(null, socket))
          throw new IllegalStateException("recvInUpdater");

      } catch (IOException e) {
        e.printStackTrace();
      } finally {
        Log.log("server endpoint established");
      }
    }
 @Override
 public void setPerformancePreferences(int connectionTime, int latency, int bandwidth) {
   sock.setPerformancePreferences(connectionTime, latency, bandwidth);
 }
  @Override
  public void run() {
    try {
      while (active) {
        try {
          // listen for and accept a client connection to serverSocket
          final Socket socket = serverSocket.accept();

          if (server.getDistributedManager() != null) {
            final ODistributedServerManager.NODE_STATUS nodeStatus =
                server.getDistributedManager().getNodeStatus();
            if (nodeStatus != ODistributedServerManager.NODE_STATUS.ONLINE) {
              OLogManager.instance()
                  .warn(
                      this,
                      "Distributed server is not yet ONLINE (status=%s), reject incoming connection from %s. If you are trying to shutdown the server, please kill the process",
                      nodeStatus,
                      socket.getRemoteSocketAddress());
              socket.close();

              // PAUSE CURRENT THREAD TO SLOW DOWN ANY POSSIBLE ATTACK
              Thread.sleep(100);
              continue;
            }
          }

          final int max = OGlobalConfiguration.NETWORK_MAX_CONCURRENT_SESSIONS.getValueAsInteger();

          int conns = server.getClientConnectionManager().getTotal();
          if (conns >= max) {
            server.getClientConnectionManager().cleanExpiredConnections();
            conns = server.getClientConnectionManager().getTotal();
            if (conns >= max) {
              // MAXIMUM OF CONNECTIONS EXCEEDED
              OLogManager.instance()
                  .warn(
                      this,
                      "Reached maximum number of concurrent connections (max=%d, current=%d), reject incoming connection from %s",
                      max,
                      conns,
                      socket.getRemoteSocketAddress());
              socket.close();

              // PAUSE CURRENT THREAD TO SLOW DOWN ANY POSSIBLE ATTACK
              Thread.sleep(100);
              continue;
            }
          }

          socket.setPerformancePreferences(0, 2, 1);
          socket.setSendBufferSize(socketBufferSize);
          socket.setReceiveBufferSize(socketBufferSize);

          // CREATE A NEW PROTOCOL INSTANCE
          ONetworkProtocol protocol = protocolType.newInstance();

          // CONFIGURE THE PROTOCOL FOR THE INCOMING CONNECTION
          protocol.config(this, server, socket, configuration);

        } catch (Throwable e) {
          if (active) OLogManager.instance().error(this, "Error on client connection", e);
        } finally {
        }
      }
    } finally {
      try {
        if (serverSocket != null && !serverSocket.isClosed()) serverSocket.close();
      } catch (IOException ioe) {
      }
    }
  }