Corrects logged addresses for relayed packets.

This commit is contained in:
chenzo 2012-05-29 13:16:17 +00:00
parent f36c7609a8
commit 632d53ac67
4 changed files with 40 additions and 14 deletions

View File

@ -11,6 +11,8 @@ import java.io.*;
import java.net.*;
import java.nio.channels.*;
import org.ice4j.stack.*;
/**
* Implements a <tt>DatagramSocket</tt> which delegates its calls to a specific
* <tt>DatagramSocket</tt>.
@ -558,10 +560,28 @@ public class DelegatingDatagramSocket
public void send(DatagramPacket p)
throws IOException
{
// Sends the packet to the final DatagramSocket
if (delegate == null)
{
super.send(p);
// no exception packet is successfully sent, log it
if(StunStack.isPacketLoggerEnabled())
{
StunStack.getPacketLogger().logPacket(
super.getLocalAddress().getAddress(),
super.getLocalPort(),
p.getAddress().getAddress(),
p.getPort(),
p.getData(),
true);
}
}
// Else, the delegate socket will encapsulate the packet.
else
{
delegate.send(p);
}
}
/**

View File

@ -10,6 +10,8 @@ import java.io.*;
import java.nio.channels.*;
import java.net.*;
import org.ice4j.stack.*;
/**
* Implements a <tt>Socket</tt> which delegates its calls to a specific
* <tt>Socket</tt>.
@ -745,6 +747,7 @@ public class DelegatingSocket
*/
public void send(DatagramPacket p) throws IOException
{
// The delegate socket will encapsulate the packet.
if (delegate != null && delegate instanceof DelegatingSocket)
{
((DelegatingSocket) delegate).send(p);
@ -756,7 +759,22 @@ public class DelegatingSocket
outputStream = getOutputStream();
}
// Else, sends the packet to the final socket (outputStream).
outputStream.write(p.getData(), p.getOffset(), p.getLength());
// no exception packet is successfully sent, log it
if(StunStack.isPacketLoggerEnabled())
{
InetSocketAddress localAddress
= (InetSocketAddress) super.getLocalSocketAddress();
StunStack.getPacketLogger().logPacket(
localAddress.getAddress().getAddress(),
localAddress.getPort(),
p.getAddress().getAddress(),
p.getPort(),
p.getData(),
true);
}
}
/**

View File

@ -265,18 +265,6 @@ class Connector
message, 0, message.length, address);
sock.send(datagramPacket);
// no exception packet is successfully sent, log it
if(StunStack.isPacketLoggerEnabled())
{
StunStack.getPacketLogger().logPacket(
sock.getLocalAddress().getAddress(),
sock.getLocalPort(),
address.getAddressBytes(),
address.getPort(),
message,
true);
}
}
/**

View File

@ -1113,7 +1113,7 @@ public class StunStack
* Returns the currently set packet logger.
* @return the currently available packet logger.
*/
static PacketLogger getPacketLogger()
public static PacketLogger getPacketLogger()
{
return packetLogger;
}
@ -1132,7 +1132,7 @@ public class StunStack
* @return <tt>true</tt> if we have a packet logger instance and
* it is enabled.
*/
static boolean isPacketLoggerEnabled()
public static boolean isPacketLoggerEnabled()
{
return packetLogger != null && packetLogger.isEnabled();
}