aboutsummaryrefslogtreecommitdiff
path: root/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java')
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java51
1 files changed, 20 insertions, 31 deletions
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 344cc7c1..a6d0549c 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
@@ -6,8 +6,6 @@ import com.juick.xmpp.JID;
import com.juick.xmpp.Message;
import com.juick.xmpp.Presence;
import com.juick.xmpp.utils.XmlUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.xmlpull.v1.XmlPullParser;
import javax.net.ssl.SSLException;
@@ -25,8 +23,6 @@ import java.util.UUID;
*/
public class ConnectionIn extends Connection implements Runnable {
- private static final Logger LOGGER = LoggerFactory.getLogger(ConnectionIn.class);
-
final public List<String> from = new ArrayList<>();
public long tsRemoteData = 0;
public long packetsRemote = 0;
@@ -42,7 +38,7 @@ public class ConnectionIn extends Connection implements Runnable {
@Override
public void run() {
- LOGGER.info("STREAM FROM ? {} START", streamID);
+ logger.info("stream from ? {} start", streamID);
try {
parser.next(); // stream:stream
updateTsRemoteData();
@@ -50,7 +46,7 @@ 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("stream from ? " + streamID + " invalid first packet");
}
boolean xmppversionnew = parser.getAttributeValue(null, "version") != null;
String from = parser.getAttributeValue(null, "from");
@@ -74,23 +70,16 @@ public class ConnectionIn extends Connection implements Runnable {
if (tag.equals("result") && parser.getNamespace().equals(NS_DB)) {
String dfrom = parser.getAttributeValue(null, "from");
String to = parser.getAttributeValue(null, "to");
- LOGGER.info("STREAM FROM {} TO {} {} ASKING FOR DIALBACK", dfrom, to, streamID);
+ logger.info("stream from {} to {} {} asking for dialback", dfrom, to, streamID);
if (dfrom.endsWith(xmpp.HOSTNAME) && (dfrom.equals(xmpp.HOSTNAME) || dfrom.endsWith("." + xmpp.HOSTNAME))) {
break;
}
if (to != null && to.equals(xmpp.HOSTNAME)) {
String dbKey = XmlUtils.getTagText(parser);
updateTsRemoteData();
-
- ConnectionOut c = xmpp.getConnectionOut(dfrom, false);
- if (c != null) {
- c.sendDialbackVerify(streamID, dbKey);
- } else {
- c = new ConnectionOut(xmpp, dfrom, streamID, dbKey);
- xmpp.service.submit(c);
- }
+ xmpp.startDialback(dfrom, streamID, dbKey);
} else {
- throw new HostUnknownException("STREAM FROM " + dfrom + " " + streamID + " INVALID TO " + to);
+ throw new HostUnknownException("stream from " + dfrom + " " + streamID + " invalid to " + to);
}
} else if (tag.equals("verify") && parser.getNamespace().equals(NS_DB)) {
String vfrom = parser.getAttributeValue(null, "from");
@@ -105,10 +94,10 @@ public class ConnectionIn extends Connection implements Runnable {
}
if (valid) {
sendStanza("<db:verify from='" + vto + "' to='" + vfrom + "' id='" + vid + "' type='valid'/>");
- LOGGER.info("STREAM FROM {} {} DIALBACK VERIFY VALID", vfrom, streamID);
+ logger.info("stream from {} {} dialback verify valid", vfrom, streamID);
} else {
sendStanza("<db:verify from='" + vto + "' to='" + vfrom + "' id='" + vid + "' type='invalid'/>");
- LOGGER.warn("STREAM FROM {} {} DIALBACK VERIFY INVALID", vfrom, streamID);
+ logger.warn("stream from {} {} dialback verify invalid", vfrom, streamID);
}
} else if (tag.equals("presence") && checkFromTo(parser)) {
Presence p = Presence.parse(parser, null);
@@ -119,7 +108,7 @@ public class ConnectionIn extends Connection implements Runnable {
updateTsRemoteData();
Message msg = Message.parse(parser, xmpp.childParsers);
if (msg != null && (msg.type == null || !msg.type.equals(Message.Type.error))) {
- LOGGER.info("STREAM {}: {}", streamID, msg);
+ logger.info("stream {}: {}", streamID, msg);
if (!bot.incomingMessage(msg)) {
xmpp.getRouter().sendStanza(msg.toString());
}
@@ -129,11 +118,11 @@ public class ConnectionIn extends Connection implements Runnable {
String type = parser.getAttributeValue(null, "type");
String xml = XmlUtils.parseToString(parser, true);
if (type == null || !type.equals(Iq.Type.error)) {
- LOGGER.info("STREAM {}: {}", streamID, xml);
+ logger.info("stream {}: {}", streamID, xml);
xmpp.getRouter().sendStanza(xml);
}
} else if (sc != null && !isSecured() && tag.equals("starttls")) {
- LOGGER.info("STREAM {} SECURING", streamID);
+ logger.info("stream {} securing", streamID);
sendStanza("<proceed xmlns=\"" + NS_TLS + "\" />");
try {
socket = sc.getSocketFactory().createSocket(socket, socket.getInetAddress().getHostAddress(),
@@ -141,10 +130,10 @@ public class ConnectionIn extends Connection implements Runnable {
((SSLSocket) socket).setUseClientMode(false);
((SSLSocket) socket).startHandshake();
setSecured(true);
- LOGGER.info("STREAM {} SECURED", streamID);
+ logger.info("stream {} secured", streamID);
restartParser();
} catch (SSLException sex) {
- LOGGER.warn("STREAM {} SSL ERROR {}", streamID, sex);
+ logger.warn("stream {} ssl error {}", streamID, sex);
sendStanza("<failed xmlns\"" + NS_TLS + "\" />");
xmpp.removeConnectionIn(this);
closeConnection();
@@ -152,21 +141,21 @@ public class ConnectionIn extends Connection implements Runnable {
} else if (isSecured() && tag.equals("stream") && parser.getNamespace().equals(NS_STREAM)) {
sendOpenStream(null, true);
} else {
- if (LOGGER.isInfoEnabled()) // prevent call parseToString if logger disabled
- LOGGER.info("STREAM {}: {}", streamID, XmlUtils.parseToString(parser, true));
+ String unhandledStanza = XmlUtils.parseToString(parser, true);
+ logger.warn("Unhandled stanza from {}: {}", streamID, unhandledStanza);
}
}
- LOGGER.warn("STREAM {} FINISHED", streamID);
+ logger.warn("stream {} finished", streamID);
xmpp.removeConnectionIn(this);
closeConnection();
} catch (EOFException | SocketException ex) {
- LOGGER.info("STREAM {} CLOSED (dirty)", streamID);
+ logger.info("stream {} closed (dirty)", streamID);
xmpp.removeConnectionIn(this);
closeConnection();
} catch (HostUnknownException e) {
- LOGGER.warn(e.getMessage());
+ logger.warn(e.getMessage());
} catch (Exception e) {
- LOGGER.warn("STREAM {} ERROR {}", streamID, e);
+ logger.warn("stream {} error {}", streamID, e);
xmpp.removeConnectionIn(this);
closeConnection();
}
@@ -195,10 +184,10 @@ public class ConnectionIn extends Connection implements Runnable {
sendStanza("<db:result from='" + xmpp.HOSTNAME + "' to='" + sfrom + "' type='" + type + "'/>");
if (type.equals("valid")) {
from.add(sfrom);
- LOGGER.info("STREAM FROM {} {} READY", sfrom, streamID);
+ logger.info("stream from {} {} ready", sfrom, streamID);
}
} catch (IOException e) {
- LOGGER.warn("STREAM FROM {} {} ERROR: {}", sfrom, streamID, e);
+ logger.warn("stream from {} {} error: {}", sfrom, streamID, e);
}
}