Commit dff6675b authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Added read timeout when creating outgoing connections while waiting for...

Added read timeout when creating outgoing connections while waiting for initial stream header. JM-648

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3787 b35dd754-fafc-0310-a699-88a17e54d16e
parent 53e6ae31
......@@ -275,6 +275,10 @@ public class OutgoingServerSession extends Session {
openingStream.append(" version=\"1.0\">");
connection.deliverRawText(openingStream.toString());
// Set a read timeout (of 5 seconds) so we don't keep waiting forever
int soTimeout = socket.getSoTimeout();
socket.setSoTimeout(5000);
XMPPPacketReader reader = new XMPPPacketReader();
reader.getXPPParser().setInput(new InputStreamReader(socket.getInputStream(),
CHARSET));
......@@ -288,6 +292,8 @@ public class OutgoingServerSession extends Session {
// Check if the remote server is XMPP 1.0 compliant
if (serverVersion != null && decodeVersion(serverVersion)[0] >= 1) {
// Restore default timeout
socket.setSoTimeout(soTimeout);
// Get the stream features
Element features = reader.parseDocument().getRootElement();
// Check if TLS is enabled
......@@ -353,7 +359,7 @@ public class OutgoingServerSession extends Session {
Log.debug("OS - Indicating we want TLS to " + hostname);
connection.deliverRawText("<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>");
MXParser xpp = (MXParser) reader.getXPPParser();
MXParser xpp = reader.getXPPParser();
// Wait for the <proceed> response
Element proceed = reader.parseDocument().getRootElement();
if (proceed != null && proceed.getName().equals("proceed")) {
......@@ -561,7 +567,7 @@ public class OutgoingServerSession extends Session {
try {
if (packet instanceof IQ) {
IQ reply = new IQ();
reply.setID(((IQ) packet).getID());
reply.setID(packet.getID());
reply.setTo(packet.getFrom());
reply.setFrom(packet.getTo());
reply.setChildElement(((IQ) packet).getChildElement().createCopy());
......@@ -597,6 +603,7 @@ public class OutgoingServerSession extends Session {
}
}
catch (UnauthorizedException e) {
// Do nothing
}
catch (Exception e) {
Log.warn("Error returning error to sender. Original packet: " + packet, e);
......
......@@ -160,7 +160,10 @@ class ServerDialback {
stream.append(" xmlns=\"jabber:server\"");
stream.append(" xmlns:db=\"jabber:server:dialback\">");
connection.deliverRawText(stream.toString());
stream = null;
// Set a read timeout (of 5 seconds) so we don't keep waiting forever
int soTimeout = socket.getSoTimeout();
socket.setSoTimeout(5000);
XMPPPacketReader reader = new XMPPPacketReader();
reader.setXPPFactory(FACTORY);
......@@ -172,6 +175,8 @@ class ServerDialback {
eventType = xpp.next();
}
if ("jabber:server:dialback".equals(xpp.getNamespace("db"))) {
// Restore default timeout
socket.setSoTimeout(soTimeout);
String id = xpp.getAttributeValue("", "id");
OutgoingServerSocketReader socketReader = new OutgoingServerSocketReader(reader);
if (authenticateDomain(socketReader, domain, hostname, id)) {
......@@ -249,7 +254,6 @@ class ServerDialback {
sb.append(key);
sb.append("</db:result>");
connection.deliverRawText(sb.toString());
sb = null;
// Process the answer from the Receiving Server
try {
......@@ -357,7 +361,6 @@ class ServerDialback {
String verifyFROM = doc.attributeValue("from");
String id = doc.attributeValue("id");
Log.debug("AS - Connection closed for host: " + verifyFROM + " id: " + id);
sb = null;
return null;
}
else {
......@@ -506,7 +509,7 @@ class ServerDialback {
private boolean verifyKey(String key, String streamID, String recipient, String hostname,
String host, int port) throws IOException, XmlPullParserException,
RemoteConnectionFailedException {
XMPPPacketReader reader = null;
XMPPPacketReader reader;
Writer writer = null;
// Establish a TCP connection back to the domain name asserted by the Originating Server
Log.debug("RS - Trying to connect to Authoritative Server: " + hostname + ":" + port);
......@@ -534,7 +537,6 @@ class ServerDialback {
stream.append(" xmlns:db=\"jabber:server:dialback\">");
writer.write(stream.toString());
writer.flush();
stream = null;
// Get the answer from the Authoritative Server
XmlPullParser xpp = reader.getXPPParser();
......@@ -553,7 +555,6 @@ class ServerDialback {
sb.append("</db:verify>");
writer.write(sb.toString());
writer.flush();
sb = null;
try {
Element doc = reader.parseDocument().getRootElement();
......@@ -625,6 +626,7 @@ class ServerDialback {
socket.close();
}
catch (IOException ioe) {
// Do nothing
}
}
return false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment