From 51bfc341be1975b7a11e0b3a59cfbb4710e78446 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 4 Oct 2017 15:31:44 +0300 Subject: juick-xmpp-wip: router component --- .../com/juick/components/s2s/ConnectionIn.java | 30 ++++++++++++---------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java') 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 eed72a18..e6f404ef 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 @@ -22,8 +22,8 @@ import com.juick.xmpp.extensions.StreamError; import com.juick.xmpp.utils.XmlUtils; import org.apache.commons.lang3.StringUtils; import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; import rocks.xmpp.addr.Jid; -import rocks.xmpp.core.session.XmppSessionConfiguration; import rocks.xmpp.core.stanza.model.Stanza; import javax.net.ssl.SSLException; @@ -35,7 +35,13 @@ import java.io.IOException; import java.io.StringReader; import java.net.Socket; import java.net.SocketException; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.UnrecoverableKeyException; +import java.security.cert.CertificateException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.UUID; @@ -47,9 +53,8 @@ public class ConnectionIn extends Connection implements Runnable { final public List from = new ArrayList<>(); public long tsRemoteData = 0; public long packetsRemote = 0; - XmppSessionConfiguration configuration; - public ConnectionIn(XMPPServer xmpp, Socket socket) throws Exception { + public ConnectionIn(XMPPServer xmpp, Socket socket) throws CertificateException, UnrecoverableKeyException, NoSuchAlgorithmException, XmlPullParserException, KeyManagementException, KeyStoreException, IOException { super(xmpp); this.socket = socket; restartParser(); @@ -83,7 +88,7 @@ public class ConnectionIn extends Connection implements Runnable { boolean xmppversionnew = parser.getAttributeValue(null, "version") != null; String from = parser.getAttributeValue(null, "from"); - if (xmpp.bannedHosts.contains(from)) { + if (Arrays.asList(xmpp.bannedHosts).contains(from)) { closeConnection(); return; } @@ -121,17 +126,14 @@ public class ConnectionIn extends Connection implements Runnable { String vid = parser.getAttributeValue(null, "id"); String vkey = XmlUtils.getTagText(parser); updateTsRemoteData(); - boolean valid = false; + final boolean[] valid = {false}; if (vfrom != null && vto != null && vid != null && vkey != null) { - ConnectionOut c = xmpp.getConnectionOut(vfrom, false); - if (c == null) { - logger.warn("outgoing connection to {} not found", vfrom); - } else { + xmpp.getConnectionOut(vfrom, false).ifPresent(c -> { String dialbackKey = c.dbKey; - valid = vkey.equals(dialbackKey); - } + valid[0] = vkey.equals(dialbackKey); + }); } - if (valid) { + if (valid[0]) { sendStanza(""); logger.info("stream from {} {} dialback verify valid", vfrom, streamID); } else { @@ -154,7 +156,7 @@ public class ConnectionIn extends Connection implements Runnable { String xml = XmlUtils.parseToString(parser, false); if (type == null || !type.equals("error")) { logger.info("stream {} iq: {}", streamID, xml); - xmpp.getRouter().sendStanza(parse(xml)); + xmpp.onStanzaReceived(parse(xml)); } } else if (sc != null && !isSecured() && tag.equals("starttls")) { logger.info("stream {} securing", streamID); @@ -209,7 +211,7 @@ public class ConnectionIn extends Connection implements Runnable { xmpp.HOSTNAME + "' id='" + streamID + "' version='1.0'>"; if (xmppversionnew) { openStream += ""; - if (sc != null && !isSecured() && !xmpp.brokenSSLhosts.contains(from)) { + if (sc != null && !isSecured() && !Arrays.asList(xmpp.brokenSSLhosts).contains(from)) { openStream += ""; } openStream += ""; -- cgit v1.2.3