From 768951b8c25abf34f6045cf2f352c64f7d2ecc37 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 8 May 2016 03:55:47 +0300 Subject: fix connection in --- src/main/java/com/juick/xmpp/s2s/ConnectionIn.java | 47 +++++++++++----------- .../com/juick/xmpp/s2s/ConnectionListener.java | 2 +- 2 files changed, 24 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/main/java/com/juick/xmpp/s2s/ConnectionIn.java b/src/main/java/com/juick/xmpp/s2s/ConnectionIn.java index 85c64db3..8fa773b7 100644 --- a/src/main/java/com/juick/xmpp/s2s/ConnectionIn.java +++ b/src/main/java/com/juick/xmpp/s2s/ConnectionIn.java @@ -24,7 +24,7 @@ import java.util.logging.Logger; * * @author ugnich */ -public class ConnectionIn extends Connection { +public class ConnectionIn extends Connection implements Runnable { private static final Logger LOGGER = Logger.getLogger(ConnectionIn.class.getName()); @@ -36,14 +36,13 @@ public class ConnectionIn extends Connection { super(); this.socket = socket; streamID = UUID.randomUUID().toString(); + restartParser(); } - public void parseStream() { + @Override + public void run() { LOGGER.info("STREAM FROM ? " + streamID + " START"); try { - parser.setInput(new InputStreamReader(socket.getInputStream())); - writer = new OutputStreamWriter(socket.getOutputStream()); - parser.next(); // stream:stream updateTsRemoteData(); if (!parser.getName().equals("stream") @@ -106,25 +105,6 @@ public class ConnectionIn extends Connection { sendStanza(""); LOGGER.warning("STREAM FROM " + vfrom + " " + streamID + " DIALBACK VERIFY INVALID"); } - } else if (!isSecured() && tag.equals("starttls")) { - LOGGER.info("STREAM " + streamID + " SECURING"); - sendStanza(""); - try { - socket = sc.getSocketFactory().createSocket(socket, socket.getInetAddress().getHostAddress(), - socket.getPort(), true); - ((SSLSocket) socket).setUseClientMode(false); - ((SSLSocket) socket).startHandshake(); - setSecured(true); - LOGGER.info("STREAM " + streamID + " SECURED"); - restartParser(); - } catch (SSLException sex) { - LOGGER.warning("STREAM " + streamID + " SSL ERROR"); - sendStanza(""); - XMPPComponent.removeConnectionIn(this); - closeConnection(); - } - } else if (isSecured() && tag.equals("stream") && parser.getNamespace().equals(NS_STREAM)) { - sendOpenStream(true); } else if (tag.equals("presence") && checkFromTo(parser)) { Presence p = Presence.parse(parser, null); if (p != null && (p.type == null || !p.type.equals(Presence.Type.error))) { @@ -147,6 +127,25 @@ public class ConnectionIn extends Connection { LOGGER.info("STREAM " + streamID + ": " + xml); XMPPComponent.connRouter.sendStanza(xml); } + } else if (!isSecured() && tag.equals("starttls")) { + LOGGER.info("STREAM " + streamID + " SECURING"); + sendStanza(""); + try { + socket = sc.getSocketFactory().createSocket(socket, socket.getInetAddress().getHostAddress(), + socket.getPort(), true); + ((SSLSocket) socket).setUseClientMode(false); + ((SSLSocket) socket).startHandshake(); + setSecured(true); + LOGGER.info("STREAM " + streamID + " SECURED"); + restartParser(); + } catch (SSLException sex) { + LOGGER.warning("STREAM " + streamID + " SSL ERROR"); + sendStanza(""); + XMPPComponent.removeConnectionIn(this); + closeConnection(); + } + } else if (isSecured() && tag.equals("stream") && parser.getNamespace().equals(NS_STREAM)) { + sendOpenStream(true); } else { LOGGER.info("STREAM " + streamID + ": " + XmlUtils.parseToString(parser, true)); } diff --git a/src/main/java/com/juick/xmpp/s2s/ConnectionListener.java b/src/main/java/com/juick/xmpp/s2s/ConnectionListener.java index 094fbd4f..569d3db0 100644 --- a/src/main/java/com/juick/xmpp/s2s/ConnectionListener.java +++ b/src/main/java/com/juick/xmpp/s2s/ConnectionListener.java @@ -23,7 +23,7 @@ public class ConnectionListener implements Runnable { Socket socket = listener.accept(); ConnectionIn client = new ConnectionIn(socket); XMPPComponent.addConnectionIn(client); - client.parseStream(); + XMPPComponent.executorService.submit(client); } catch (Exception e) { logger.log(Level.SEVERE, "s2s error", e); } -- cgit v1.2.3