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

View File

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

View File

@ -795,9 +795,13 @@ public class DelegatingSocket
inputStream = this.getInputStream();
}
short desiredLength = (short)
(((inputStream.read() << 8) & 0xff) | (inputStream.read() & 0xff));
int fb = inputStream.read();
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 offset = 0;

View File

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

View File

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

View File

@ -40,6 +40,7 @@ public class TCPOutputStream
public void close()
throws IOException
{
outputStream.close();
}
/**
@ -49,6 +50,7 @@ public class TCPOutputStream
public void flush()
throws IOException
{
outputStream.flush();
}
/**
@ -68,6 +70,14 @@ public class TCPOutputStream
public void write(byte[] b, int off, int len)
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];
data[0] = (byte)((len >> 8) & 0xff);
data[1] = (byte)(len & 0xff);