public void close() { if (!closed) { closed = true; logger.fine("closing incoming connection"); connection.close(); } }
@Override public boolean messageReceived(Message message) { logger.finest("incoming speed packet: " + message.getDescription()); lastMessageTime = System.currentTimeMillis(); if (incomingHandshake == null) { if (message instanceof OSF2FHandshake) { incomingHandshake = (OSF2FHandshake) message; } else { logger.warning("incoming connection not started with handshake"); close(); } } else if (message instanceof OSF2FChannelReset) { OSF2FChannelReset m = (OSF2FChannelReset) message; if (remoteLocalEstimate == -1) { remoteLocalEstimate = m.getChannelId(); } else { remoteRemoteEstimate = m.getChannelId(); logger.finer( "estimate of " + getRemoteIp() + " remote_local_estimate=" + remoteLocalEstimate + " remote_remote=" + remoteRemoteEstimate); close(); } } else if ((message instanceof OSF2FChannelMsg)) { OSF2FChannelMsg m = (OSF2FChannelMsg) message; if (packetSize == 0) { packetSize = m.getMessageSize(); } if (m.getMessageSize() != packetSize) { logger.warning("got different size payload packet"); close(); return true; } /* * ok all is good, send back a timestamp to the other side */ int relTime = (int) (System.currentTimeMillis() - startTime); messageTimes.add(relTime); /* * we only need to send an int over, channel reset is the * smallest message (5+4 bytes), a bit of a hack but wth... */ connection .getOutgoingMessageQueue() .addMessage(new OSF2FChannelReset(OSF2FMessage.CURRENT_VERSION, relTime), false); } else { logger.warning("incoming speed check connection unknown packet"); close(); return true; } return true; }
public IncomingSpeedCheckConnection(GlobalManagerStats stats, NetworkConnection conn) { this.startTime = System.currentTimeMillis(); this.connection = conn; this.stats = stats; /* * register for notifications about incoming messages */ connection.getIncomingMessageQueue().registerQueueListener(this); connection.connect( true, new ConnectionListener() { @Override public void connectFailure(Throwable failureMsg) { connection.close(); } @Override public void connectStarted() {} @Override public void connectSuccess(ByteBuffer remainingInitialData) { NetworkManager.getSingleton().upgradeTransferProcessing(connection, null); logger.finest("incoming speed check connected: " + getRemoteIp()); } @Override public void exceptionThrown(Throwable error) { logger.warning("got exception in incoming speed test: " + error.getMessage()); error.printStackTrace(); connection.close(); } @Override public String getDescription() { return "speed connection listener"; } }); NetworkManager.getSingleton().startTransferProcessing(connection); }
public static Connection wrap(NetworkConnection connection) { return (new ConnectionImpl(connection, connection.isIncoming())); }
public String getRemoteIp() { return connection.getEndpoint().getNotionalAddress().getAddress().getHostAddress(); }