Introduce PacketLogger, implementers can log all received or sent packets by the stack.
This commit is contained in:
parent
15b6780ccf
commit
7e868bb3f1
@ -251,6 +251,18 @@ 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -152,11 +152,27 @@ class MessageProcessor
|
|||||||
|
|
||||||
logger.finest("Dispatching a StunMessageEvent.");
|
logger.finest("Dispatching a StunMessageEvent.");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
StunMessageEvent stunMessageEvent
|
StunMessageEvent stunMessageEvent
|
||||||
= new StunMessageEvent(stunStack, rawMessage, stunMessage);
|
= new StunMessageEvent(stunStack, rawMessage, stunMessage);
|
||||||
|
|
||||||
messageEventHandler.handleMessageEvent(stunMessageEvent);
|
messageEventHandler.handleMessageEvent(stunMessageEvent);
|
||||||
}
|
}
|
||||||
|
finally // make sure we log the packet in case of exception
|
||||||
|
{
|
||||||
|
if(StunStack.isPacketLoggerEnabled())
|
||||||
|
{
|
||||||
|
StunStack.getPacketLogger().logPacket(
|
||||||
|
rawMessage.getRemoteAddress().getAddressBytes(),
|
||||||
|
rawMessage.getRemoteAddress().getPort(),
|
||||||
|
rawMessage.getLocalAddress().getAddressBytes(),
|
||||||
|
rawMessage.getLocalAddress().getPort(),
|
||||||
|
rawMessage.getBytes(),
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch(Throwable err)
|
catch(Throwable err)
|
||||||
{
|
{
|
||||||
|
|||||||
41
src/org/ice4j/stack/PacketLogger.java
Normal file
41
src/org/ice4j/stack/PacketLogger.java
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* ice4j, the OpenSource Java Solution for NAT and Firewall Traversal.
|
||||||
|
* Maintained by the SIP Communicator community (http://sip-communicator.org).
|
||||||
|
*
|
||||||
|
* Distributable under LGPL license. See terms of license at gnu.org.
|
||||||
|
*/
|
||||||
|
package org.ice4j.stack;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The interface which interested implementers will use in order
|
||||||
|
* to track and log packets send and received by this stack.
|
||||||
|
*
|
||||||
|
* @author Damian Minkov
|
||||||
|
*/
|
||||||
|
public interface PacketLogger
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Logs a incoming or outgoing packet.
|
||||||
|
*
|
||||||
|
* @param sourceAddress the source address of the packet.
|
||||||
|
* @param sourcePort the source port.
|
||||||
|
* @param destinationAddress the destination address of the packet.
|
||||||
|
* @param destinationPort the destination port.
|
||||||
|
* @param packetContent the content of the packet.
|
||||||
|
* @param sender whether we are sending or not the packet.
|
||||||
|
*/
|
||||||
|
public void logPacket(
|
||||||
|
byte[] sourceAddress,
|
||||||
|
int sourcePort,
|
||||||
|
byte[] destinationAddress,
|
||||||
|
int destinationPort,
|
||||||
|
byte[] packetContent,
|
||||||
|
boolean sender);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether the logger is enabled.
|
||||||
|
* @return <tt>true</tt> if the logger is enabled, <tt>false</tt>
|
||||||
|
* otherwise.
|
||||||
|
*/
|
||||||
|
public boolean isEnabled();
|
||||||
|
}
|
||||||
@ -83,6 +83,11 @@ public class StunStack
|
|||||||
*/
|
*/
|
||||||
private final EventDispatcher eventDispatcher = new EventDispatcher();
|
private final EventDispatcher eventDispatcher = new EventDispatcher();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The packet logger instance.
|
||||||
|
*/
|
||||||
|
private static PacketLogger packetLogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the number of Message processors running in the same time.
|
* Sets the number of Message processors running in the same time.
|
||||||
*
|
*
|
||||||
@ -1030,4 +1035,32 @@ public class StunStack
|
|||||||
|
|
||||||
return getCredentialsManager().checkLocalUserName(lfrag);
|
return getCredentialsManager().checkLocalUserName(lfrag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the currently set packet logger.
|
||||||
|
* @return the currently available packet logger.
|
||||||
|
*/
|
||||||
|
static PacketLogger getPacketLogger()
|
||||||
|
{
|
||||||
|
return packetLogger;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setting a packet logger for the stack.
|
||||||
|
* @param packetLogger the packet logger to use.
|
||||||
|
*/
|
||||||
|
public static void setPacketLogger(PacketLogger packetLogger)
|
||||||
|
{
|
||||||
|
StunStack.packetLogger = packetLogger;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether packet logger is set and enabled.
|
||||||
|
* @return <tt>true</tt> if we have a packet logger instance and
|
||||||
|
* it is enabled.
|
||||||
|
*/
|
||||||
|
static boolean isPacketLoggerEnabled()
|
||||||
|
{
|
||||||
|
return packetLogger != null && packetLogger.isEnabled();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user