Fixes cases with peer-reflexives Candidate as well as some calls initiated from Gmail. Fixes framing length calculation and some missing implemented methods reported by Ingo Bauersachs on dev mailing-list.

This commit is contained in:
seb 2011-10-13 14:51:33 +00:00
parent b6213785aa
commit 44fd1c4a06
6 changed files with 61 additions and 9 deletions

View File

@ -1229,6 +1229,9 @@ public class Agent
if(compatibilityMode == CompatibilityMode.GTALK) if(compatibilityMode == CompatibilityMode.GTALK)
{ {
if(localAddress.getTransport() == Transport.TCP)
localCandidate = findLocalCandidate(localAddress);
else
localCandidate = findLocalCandidate(localAddress, localCandidate = findLocalCandidate(localAddress,
remoteUFrag); remoteUFrag);
} }
@ -1328,10 +1331,21 @@ public class Agent
triggerPair.getLocalCandidate().getTransportAddress(), triggerPair.getLocalCandidate().getTransportAddress(),
triggerPair.getRemoteCandidate().getTransportAddress()); triggerPair.getRemoteCandidate().getTransportAddress());
else else
{
if(triggerPair.getLocalCandidate().getTransport() == Transport.TCP)
{
knownPair = findCandidatePair(
triggerPair.getLocalCandidate().getTransportAddress(),
triggerPair.getRemoteCandidate().getTransportAddress());
}
else
{
knownPair = findCandidatePair( knownPair = findCandidatePair(
((RemoteCandidate)triggerPair.getRemoteCandidate()). ((RemoteCandidate)triggerPair.getRemoteCandidate()).
getUfrag(), getUfrag(),
triggerPair.getLocalCandidate().getUfrag()); triggerPair.getLocalCandidate().getUfrag());
}
}
IceMediaStream parentStream = triggerPair.getLocalCandidate() IceMediaStream parentStream = triggerPair.getLocalCandidate()
.getParentComponent().getParentStream(); .getParentComponent().getParentStream();
@ -1407,6 +1421,8 @@ public class Agent
// Its state is set to Waiting [and it] is enqueued into the // Its state is set to Waiting [and it] is enqueued into the
// triggered check queue. // triggered check queue.
// //
logger.info("Add peer CandidatePair with new reflexive address to" +
" checkList");
parentStream.addToCheckList(triggerPair); parentStream.addToCheckList(triggerPair);
} }

View File

@ -578,6 +578,12 @@ class ConnectivityCheckClient
//generated from it momentarily //generated from it momentarily
validLocalCandidate = peerReflexiveCandidate; validLocalCandidate = peerReflexiveCandidate;
if(parentAgent.getCompatibilityMode() == CompatibilityMode.GTALK)
{
validLocalCandidate.setUfrag(
checkedPair.getLocalCandidate().getUfrag());
}
logger.info("Receive a peer-reflexive candidate: " + logger.info("Receive a peer-reflexive candidate: " +
peerReflexiveCandidate.getTransportAddress()); peerReflexiveCandidate.getTransportAddress());
} }

View File

@ -795,9 +795,13 @@ public class DelegatingSocket
inputStream = this.getInputStream(); inputStream = this.getInputStream();
} }
short desiredLength = (short) int fb = inputStream.read();
(((inputStream.read() << 8) & 0xff) | (inputStream.read() & 0xff)); int sb = inputStream.read();
if(fb == -1 || sb == -1)
throw new SocketException("failed to read first two bytes");
int desiredLength = (((fb & 0xff) << 8) | (sb & 0xff));
int readLen = 0; int readLen = 0;
int offset = 0; int offset = 0;

View File

@ -264,7 +264,7 @@ public class GoogleRelayedCandidateSocket
* *
* @author Sebastien Vincent * @author Sebastien Vincent
*/ */
private class TCPOutputStream protected class TCPOutputStream
extends OutputStream extends OutputStream
{ {
/** /**

View File

@ -87,16 +87,32 @@ public class IceTcpSocketWrapper
byte data[] = p.getData(); byte data[] = p.getData();
int len = 0; int len = 0;
int desiredLength =
(((inputStream.read() & 0xff) << 8) | (inputStream.read() & 0xff));
int readLen = 0;
int offset = 0;
inputStream.skip(2); while(readLen < desiredLength)
len = inputStream.read(data); {
if(len > 0) len = inputStream.read(data, offset, desiredLength - offset);
if(len == -1)
throw new SocketException("read failed");
offset += len;
readLen += len;
}
if (readLen == desiredLength)
{ {
p.setData(data); p.setData(data);
p.setLength(len); p.setLength(len);
p.setAddress(this.getLocalAddress()); p.setAddress(this.getLocalAddress());
p.setPort(this.getLocalPort()); p.setPort(this.getLocalPort());
} }
else
{
throw new SocketException("Failed to receive data from socket");
}
data = null; data = null;
} }

View File

@ -40,6 +40,7 @@ public class TCPOutputStream
public void close() public void close()
throws IOException throws IOException
{ {
outputStream.close();
} }
/** /**
@ -49,6 +50,7 @@ public class TCPOutputStream
public void flush() public void flush()
throws IOException throws IOException
{ {
outputStream.flush();
} }
/** /**
@ -68,6 +70,14 @@ public class TCPOutputStream
public void write(byte[] b, int off, int len) public void write(byte[] b, int off, int len)
throws IOException throws IOException
{ {
// GoogleRelayedCandidateSocket will encapsulate data in TURN message
// so do not add framing here
if(outputStream instanceof GoogleRelayedCandidateSocket.TCPOutputStream)
{
outputStream.write(b, off, len);
return;
}
byte data[] = new byte[len + 2]; byte data[] = new byte[len + 2];
data[0] = (byte)((len >> 8) & 0xff); data[0] = (byte)((len >> 8) & 0xff);
data[1] = (byte)(len & 0xff); data[1] = (byte)(len & 0xff);