diff options
author | 2016-05-08 03:55:47 +0300 | |
---|---|---|
committer | 2016-05-08 03:55:47 +0300 | |
commit | 768951b8c25abf34f6045cf2f352c64f7d2ecc37 (patch) | |
tree | 1ba2def4df5230a64a47591279afd0d7c9ee3788 /src/main/java | |
parent | 388716986b483e99e5140ca1557cd38632b5115b (diff) |
fix connection in
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/com/juick/xmpp/s2s/ConnectionIn.java | 47 | ||||
-rw-r--r-- | src/main/java/com/juick/xmpp/s2s/ConnectionListener.java | 2 |
2 files changed, 24 insertions, 25 deletions
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("<db:verify from='" + vto + "' to='" + vfrom + "' id='" + vid + "' type='invalid'/>"); LOGGER.warning("STREAM FROM " + vfrom + " " + streamID + " DIALBACK VERIFY INVALID"); } - } else if (!isSecured() && tag.equals("starttls")) { - LOGGER.info("STREAM " + streamID + " SECURING"); - sendStanza("<proceed xmlns=\"" + NS_TLS + "\" />"); - 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("<failed xmlns\"" + NS_TLS + "\" />"); - 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("<proceed xmlns=\"" + NS_TLS + "\" />"); + 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("<failed xmlns\"" + NS_TLS + "\" />"); + 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); } |