aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/xmpp/s2s/ConnectionOut.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/xmpp/s2s/ConnectionOut.java')
-rw-r--r--src/main/java/com/juick/xmpp/s2s/ConnectionOut.java34
1 files changed, 18 insertions, 16 deletions
diff --git a/src/main/java/com/juick/xmpp/s2s/ConnectionOut.java b/src/main/java/com/juick/xmpp/s2s/ConnectionOut.java
index d3a10406..fede701e 100644
--- a/src/main/java/com/juick/xmpp/s2s/ConnectionOut.java
+++ b/src/main/java/com/juick/xmpp/s2s/ConnectionOut.java
@@ -17,6 +17,7 @@ import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
+import java.util.UUID;
import java.util.logging.Level;
/**
@@ -29,30 +30,31 @@ public class ConnectionOut extends Connection implements Runnable {
String checkSID = null;
String dbKey = null;
- public ConnectionOut(String hostname) throws CertificateException, UnrecoverableKeyException, NoSuchAlgorithmException, XmlPullParserException, KeyManagementException, KeyStoreException, IOException {
- super();
+ public ConnectionOut(XMPPComponent xmpp, String hostname) throws CertificateException, UnrecoverableKeyException, NoSuchAlgorithmException, XmlPullParserException, KeyManagementException, KeyStoreException, IOException {
+ super(xmpp);
to = hostname;
}
- public ConnectionOut(String hostname, String checkSID, String dbKey) throws Exception {
- super();
+ public ConnectionOut(XMPPComponent xmpp, String hostname, String checkSID, String dbKey) throws Exception {
+ super(xmpp);
to = hostname;
this.checkSID = checkSID;
this.dbKey = dbKey;
+ streamID = UUID.randomUUID().toString();
}
void sendOpenStream() throws IOException {
sendStanza("<?xml version='1.0'?><stream:stream xmlns='jabber:server' id='" + streamID +
"' xmlns:stream='http://etherx.jabber.org/streams' xmlns:db='jabber:server:dialback' from='" +
- XMPPComponent.HOSTNAME + "' to='" + to + "' version='1.0'>");
+ xmpp.HOSTNAME + "' to='" + to + "' version='1.0'>");
}
void processDialback() throws Exception {
if (checkSID != null) {
sendDialbackVerify(checkSID, dbKey);
}
- sendStanza("<db:result from='" + XMPPComponent.HOSTNAME + "' to='" + to + "'>" +
- generateDialbackKey(to, XMPPComponent.HOSTNAME, streamID) + "</db:result>");
+ sendStanza("<db:result from='" + xmpp.HOSTNAME + "' to='" + to + "'>" +
+ generateDialbackKey(to, xmpp.HOSTNAME, streamID) + "</db:result>");
}
@Override
@@ -76,7 +78,7 @@ public class ConnectionOut extends Connection implements Runnable {
}
LOGGER.info("STREAM TO " + to + " " + streamID + " OPEN");
- XMPPComponent.addConnectionOut(ConnectionOut.this);
+ xmpp.addConnectionOut(ConnectionOut.this);
boolean xmppversionnew = parser.getAttributeValue(null, "version") != null;
if (!xmppversionnew) {
processDialback();
@@ -95,7 +97,7 @@ public class ConnectionOut extends Connection implements Runnable {
streamReady = true;
LOGGER.info("STREAM TO " + to + " " + streamID + " READY");
- String cache = XMPPComponent.getFromCache(to);
+ String cache = xmpp.getFromCache(to);
if (cache != null) {
LOGGER.info("STREAM TO " + to + " " + streamID + " SENDING CACHE");
sendStanza(cache);
@@ -110,7 +112,7 @@ public class ConnectionOut extends Connection implements Runnable {
String type = parser.getAttributeValue(null, "type");
String sid = parser.getAttributeValue(null, "id");
if (from != null && from.equals(to) && sid != null && !sid.isEmpty() && type != null) {
- ConnectionIn c = XMPPComponent.getConnectionIn(sid);
+ ConnectionIn c = xmpp.getConnectionIn(sid);
if (c != null) {
c.sendDialbackResult(from, type);
}
@@ -118,7 +120,7 @@ public class ConnectionOut extends Connection implements Runnable {
XmlUtils.skip(parser);
} else if (tag.equals("features") && parser.getNamespace().equals(NS_STREAM)) {
StreamFeatures features = StreamFeatures.parse(parser);
- if (!isSecured() && features.STARTTLS >= 0 && !XMPPComponent.brokenSSLhosts.contains(to)) {
+ if (!isSecured() && features.STARTTLS >= 0 && !xmpp.brokenSSLhosts.contains(to)) {
System.out.println("STREAM TO " + to + " " + streamID + " SECURING");
sendStanza("<starttls xmlns=\"" + NS_TLS + "\" />");
} else {
@@ -136,7 +138,7 @@ public class ConnectionOut extends Connection implements Runnable {
} catch (SSLException sex) {
LOGGER.log(Level.SEVERE, String.format("s2s ssl error: %s %s", to, streamID), sex);
sendStanza("<failed xmlns\"" + NS_TLS + "\" />");
- XMPPComponent.removeConnectionOut(this);
+ xmpp.removeConnectionOut(this);
closeConnection();
}
} else if (isSecured() && tag.equals("stream") && parser.getNamespace().equals(NS_STREAM)) {
@@ -147,22 +149,22 @@ public class ConnectionOut extends Connection implements Runnable {
}
LOGGER.warning("STREAM TO " + to + " " + streamID + " FINISHED");
- XMPPComponent.removeConnectionOut(ConnectionOut.this);
+ xmpp.removeConnectionOut(ConnectionOut.this);
closeConnection();
} catch (EOFException eofex) {
LOGGER.info(String.format("STREAM %s %s CLOSED (dirty)", to, streamID));
- XMPPComponent.removeConnectionOut(ConnectionOut.this);
+ xmpp.removeConnectionOut(ConnectionOut.this);
closeConnection();
} catch (Exception e) {
LOGGER.log(Level.SEVERE, String.format("s2s out exception: %s %s", to, streamID), e);
- XMPPComponent.removeConnectionOut(ConnectionOut.this);
+ xmpp.removeConnectionOut(ConnectionOut.this);
closeConnection();
}
}
public void sendDialbackVerify(String sid, String key) {
try {
- sendStanza("<db:verify from='" + XMPPComponent.HOSTNAME + "' to='" + to + "' id='" + sid + "'>" + key + "</db:verify>");
+ sendStanza("<db:verify from='" + xmpp.HOSTNAME + "' to='" + to + "' id='" + sid + "'>" + key + "</db:verify>");
} catch (IOException e) {
LOGGER.log(Level.WARNING, "STREAM TO " + to + " " + streamID + " ERROR", e);
}