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.net.*;
import java.nio.channels.*; import java.nio.channels.*;
import org.ice4j.stack.*;
/** /**
* Implements a <tt>DatagramSocket</tt> which delegates its calls to a specific * Implements a <tt>DatagramSocket</tt> which delegates its calls to a specific
* <tt>DatagramSocket</tt>. * <tt>DatagramSocket</tt>.
@ -558,11 +560,29 @@ public class DelegatingDatagramSocket
public void send(DatagramPacket p) public void send(DatagramPacket p)
throws IOException throws IOException
{ {
// Sends the packet to the final DatagramSocket
if (delegate == null) if (delegate == null)
{
super.send(p); 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 else
{
delegate.send(p); delegate.send(p);
} }
}
/** /**
* Enables/disables <tt>SO_BROADCAST</tt>. * Enables/disables <tt>SO_BROADCAST</tt>.

View File

@ -10,6 +10,8 @@ import java.io.*;
import java.nio.channels.*; import java.nio.channels.*;
import java.net.*; import java.net.*;
import org.ice4j.stack.*;
/** /**
* Implements a <tt>Socket</tt> which delegates its calls to a specific * Implements a <tt>Socket</tt> which delegates its calls to a specific
* <tt>Socket</tt>. * <tt>Socket</tt>.
@ -745,6 +747,7 @@ public class DelegatingSocket
*/ */
public void send(DatagramPacket p) throws IOException public void send(DatagramPacket p) throws IOException
{ {
// The delegate socket will encapsulate the packet.
if (delegate != null && delegate instanceof DelegatingSocket) if (delegate != null && delegate instanceof DelegatingSocket)
{ {
((DelegatingSocket) delegate).send(p); ((DelegatingSocket) delegate).send(p);
@ -756,7 +759,22 @@ public class DelegatingSocket
outputStream = getOutputStream(); outputStream = getOutputStream();
} }
// Else, sends the packet to the final socket (outputStream).
outputStream.write(p.getData(), p.getOffset(), p.getLength()); 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); message, 0, message.length, address);
sock.send(datagramPacket); 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. * Returns the currently set packet logger.
* @return the currently available packet logger. * @return the currently available packet logger.
*/ */
static PacketLogger getPacketLogger() public static PacketLogger getPacketLogger()
{ {
return packetLogger; return packetLogger;
} }
@ -1132,7 +1132,7 @@ public class StunStack
* @return <tt>true</tt> if we have a packet logger instance and * @return <tt>true</tt> if we have a packet logger instance and
* it is enabled. * it is enabled.
*/ */
static boolean isPacketLoggerEnabled() public static boolean isPacketLoggerEnabled()
{ {
return packetLogger != null && packetLogger.isEnabled(); return packetLogger != null && packetLogger.isEnabled();
} }