aboutsummaryrefslogtreecommitdiff
path: root/juick-xmpp/src
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-12-22 13:28:17 +0300
committerGravatar Vitaly Takmazov2016-12-22 13:32:34 +0300
commita6aa01258352a4053d55727c974492ffe27f1fcc (patch)
treec1d36b871ececbf653c1e806e1f73765c6e87916 /juick-xmpp/src
parentebfae6637d88c9d444f39c7fbe43ce4b7ffc130f (diff)
juick-xmpp: refactoring
Diffstat (limited to 'juick-xmpp/src')
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/s2s/Connection.java2
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java8
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionOut.java6
3 files changed, 11 insertions, 5 deletions
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("<db:verify from='" + xmpp.HOSTNAME + "' to='" + to + "' id='" + sid + "'>" +
key + "</db:verify>");
}
+
+ @Override
+ public void restartParser() throws XmlPullParserException, IOException {
+ super.restartParser();
+ streamID = UUID.randomUUID().toString();
+ }
}