diff options
Diffstat (limited to 'src/net/java/sip/communicator/impl/packetlogging/PacketLoggingServiceImpl.java')
-rw-r--r-- | src/net/java/sip/communicator/impl/packetlogging/PacketLoggingServiceImpl.java | 64 |
1 files changed, 44 insertions, 20 deletions
diff --git a/src/net/java/sip/communicator/impl/packetlogging/PacketLoggingServiceImpl.java b/src/net/java/sip/communicator/impl/packetlogging/PacketLoggingServiceImpl.java index 788e8db..1e459f1 100644 --- a/src/net/java/sip/communicator/impl/packetlogging/PacketLoggingServiceImpl.java +++ b/src/net/java/sip/communicator/impl/packetlogging/PacketLoggingServiceImpl.java @@ -20,6 +20,7 @@ package net.java.sip.communicator.impl.packetlogging; import java.io.*; import java.util.*; +import com.google.common.collect.*; import net.java.sip.communicator.util.*; import org.jitsi.service.fileaccess.*; @@ -41,6 +42,14 @@ public class PacketLoggingServiceImpl = Logger.getLogger(PacketLoggingServiceImpl.class); /** + * The max size of the <tt>EvictingQueue</tt> that the saver thread + * is using. + * + * TODO this needs to be configurable eventually. + */ + private static final int EVICTING_QUEUE_MAX_SIZE = 1000; + + /** * The OutputStream we are currently writing to. */ private FileOutputStream outputStream = null; @@ -62,10 +71,17 @@ public class PacketLoggingServiceImpl new byte[]{ (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, - (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, - (byte)0x08, (byte)0x00 + (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 }; + /** IEEE 802.3 EtherType for IPv4 */ + private final static byte[] ipv4EtherType = + new byte[] { 0x08, 0x00 }; + + /** IEEE 802.3 EtherType for IPv6 */ + private final static byte[] ipv6EtherType = + new byte[] { (byte)0x86, (byte)0xdd }; + /** * The fake ipv4 header we use as template. */ @@ -313,22 +329,22 @@ public class PacketLoggingServiceImpl { switch(protocol) { - case SIP: - return cfg.isSipLoggingEnabled(); - case JABBER: - return cfg.isJabberLoggingEnabled(); - case RTP: - return cfg.isRTPLoggingEnabled(); - case ICE4J: - return cfg.isIce4JLoggingEnabled(); - default: - /* - * It may seem like it was unnecessary to invoke - * getConfiguration and isGlobalLoggingEnabled prior to - * checking that the specified protocol is supported but, - * actually, there are no other ProtocolName values. - */ - return false; + case SIP: + return cfg.isSipLoggingEnabled(); + case JABBER: + return cfg.isJabberLoggingEnabled(); + case RTP: + return cfg.isRTPLoggingEnabled(); + case ICE4J: + return cfg.isIce4JLoggingEnabled(); + case ARBITRARY: + return cfg.isArbitraryLoggingEnabled(); + default: + // It may seem like it was unnecessary to invoke + // getConfiguration and isGlobalLoggingEnabled prior to checking + // that the specified protocol is supported but, actually, there + // are no other ProtocolName values. + return false; } } else @@ -553,6 +569,7 @@ public class PacketLoggingServiceImpl int tsSec = (int)(current/1000); int tsUsec = (int)((current%1000) * 1000); int feakHeaderLen = fakeEthernetHeader.length + + (isIPv4 ? ipv4EtherType : ipv6EtherType).length + ipHeader.length + transportHeader.length; int inclLen = packet.packetLength + feakHeaderLen; int origLen = inclLen; @@ -577,6 +594,7 @@ public class PacketLoggingServiceImpl addInt(origLen); outputStream.write(fakeEthernetHeader); + outputStream.write(isIPv4 ? ipv4EtherType : ipv6EtherType); outputStream.write(ipHeader); outputStream.write(transportHeader); outputStream.write( @@ -767,7 +785,8 @@ public class PacketLoggingServiceImpl /** * List of packets queued to be written in the file. */ - private final List<Packet> pktsToSave = new ArrayList<Packet>(); + private final EvictingQueue<Packet> pktsToSave + = EvictingQueue.create(EVICTING_QUEUE_MAX_SIZE); /** * Initializes a new <tt>SaverThread</tt>. @@ -803,7 +822,7 @@ public class PacketLoggingServiceImpl continue; } - pktToSave = pktsToSave.remove(0); + pktToSave = pktsToSave.poll(); } if(pktToSave != null) @@ -842,6 +861,11 @@ public class PacketLoggingServiceImpl */ public synchronized void queuePacket(Packet packet) { + if (EVICTING_QUEUE_MAX_SIZE - pktsToSave.size() == 0) + { + logger.warn("Queue is full, packets are being evicted."); + } + pktsToSave.add(packet); notifyAll(); } |