From a6aa01258352a4053d55727c974492ffe27f1fcc Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 22 Dec 2016 13:28:17 +0300 Subject: juick-xmpp: refactoring --- juick-xmpp/src/main/java/com/juick/components/s2s/Connection.java | 2 -- .../src/main/java/com/juick/components/s2s/ConnectionIn.java | 8 +++++--- .../src/main/java/com/juick/components/s2s/ConnectionOut.java | 6 ++++++ 3 files changed, 11 insertions(+), 5 deletions(-) (limited to 'juick-xmpp') diff --git a/juick-xmpp/src/main/java/com/juick/components/s2s/Connection.java b/juick-xmpp/src/main/java/com/juick/components/s2s/Connection.java index e54a1548..d07715ab 100644 --- a/juick-xmpp/src/main/java/com/juick/components/s2s/Connection.java +++ b/juick-xmpp/src/main/java/com/juick/components/s2s/Connection.java @@ -16,7 +16,6 @@ import java.net.Socket; import java.nio.charset.StandardCharsets; import java.security.*; import java.security.cert.CertificateException; -import java.util.UUID; /** * @@ -133,6 +132,5 @@ public class Connection { parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); parser.setInput(new InputStreamReader(socket.getInputStream())); writer = new OutputStreamWriter(socket.getOutputStream(), StandardCharsets.UTF_8); - streamID = UUID.randomUUID().toString(); } } diff --git a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java index 25f28ef6..77412227 100644 --- a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java +++ b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java @@ -30,13 +30,11 @@ public class ConnectionIn extends Connection implements Runnable { public ConnectionIn(XMPPServer xmpp, Socket socket) throws Exception { super(xmpp); this.socket = socket; - streamID = UUID.randomUUID().toString(); restartParser(); } @Override public void run() { - logger.info("stream from ? {} start", streamID); try { parser.next(); // stream:stream updateTsRemoteData(); @@ -44,7 +42,11 @@ public class ConnectionIn extends Connection implements Runnable { || !parser.getNamespace("stream").equals(NS_STREAM)) { // || !parser.getAttributeValue(null, "version").equals("1.0") // || !parser.getAttributeValue(null, "to").equals(Main.HOSTNAME)) { - throw new Exception("stream from ? " + streamID + " invalid first packet"); + throw new Exception(String.format("stream from %s invalid", socket.getRemoteSocketAddress())); + } + streamID = parser.getAttributeValue(null, "id"); + if (streamID == null) { + streamID = UUID.randomUUID().toString(); } boolean xmppversionnew = parser.getAttributeValue(null, "version") != null; String from = parser.getAttributeValue(null, "from"); diff --git a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionOut.java b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionOut.java index e39c143d..5f990ccd 100644 --- a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionOut.java +++ b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionOut.java @@ -167,4 +167,10 @@ public class ConnectionOut extends Connection implements Runnable { sendStanza("" + key + ""); } + + @Override + public void restartParser() throws XmlPullParserException, IOException { + super.restartParser(); + streamID = UUID.randomUUID().toString(); + } } -- cgit v1.2.3