Exemplo n.º 1
0
        public void Output(TimestampedData timestampedData)
        {
            var block     = new EnhancedPacketBlock(timestampedData);
            var blockData = block.GetBytes();

            this.writer.Write(blockData);
            this.writer.Flush();
        }
Exemplo n.º 2
0
        public void Output(TimestampedData timestampedData)
        {
            var block = new EnhancedPacketBlock(timestampedData);
            var blockData = block.GetBytes();

            this.writer.Write(blockData);
            this.writer.Flush();
        }
Exemplo n.º 3
0
        private void EnqueueOutput(TimestampedData timestampedData)
        {
            if (this._isStopping)
            {
                this._outputQueue.CompleteAdding();
                return;
            }

            this._outputQueue.Add(timestampedData);
        }
        protected override bool TryRead(CsvReader reader, CsvSerializerContext serializer, CsvHeaderNamingContext naming, ref ITimestampedData result)
        {
            DateTimeOffset timestamp;

            if (reader.TryGetField <DateTimeOffset>(naming.Get(_timestampFieldName), out timestamp))
            {
                result = new TimestampedData(timestamp);
                return(true);
            }

            return(false);
        }
Exemplo n.º 5
0
        public void Output(TimestampedData timestampedData)
        {
            int index = NetworkInterfaceInfoList.IndexOf(timestampedData.NetworkInterface);

            if (index == -1)
            {
                var interfaceDescriptionBlock = new InterfaceDescriptionBlock(timestampedData.NetworkInterface);
                writer.Write(interfaceDescriptionBlock.GetBytes());
                NetworkInterfaceInfoList.Add(timestampedData.NetworkInterface);
            }


            var block = new EnhancedPacketBlock(timestampedData);

            writer.Write(block.GetBytes());
            writer.Flush();
        }
Exemplo n.º 6
0
 public EnhancedPacketBlock(TimestampedData timestampedData)
 {
     this.timestampedData = timestampedData;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Inserts the connection into the cache IF we don't have one already (we only cache one
 /// connection per unique descriptor).
 /// 
 /// This method is thread safe.
 /// 
 /// Due to MS Access not allowing more than one connection to have the DB locked for modifying at
 /// one time, any connections to Access DBs are closed and not cached.
 /// </summary>
 public void Return(AbstractSqlConnectionDescriptor connDesc, IDbConnection conn)
 {
     bool closeConn = false;
     if (!connDesc.UsePooling())
     {
         closeConn = true;
     }
     else
     {
         lock (_cache)
         {
             if (_cache.ContainsKey(connDesc))
             {
                 // already have a connection for this connstr.  We're tolerant of this, just
                 // go ahead and close the second connection.
                 closeConn = true;
             }
             else
             {
                 _cache[connDesc] = new TimestampedData<IDbConnection>(conn);
             }
         }
     }
     if (closeConn)
     {
         // Not caching it, just close it.
         try
         {
             if (_log.IsDebugEnabled)
             {
                 _log.Debug("Closing DB connection: " + conn.ConnectionString);
             }
             conn.Close();
         }
         catch (Exception e)
         {
             // This exception is not rethrown because we don't want to mask any
             // previous exception that might be being thrown out of "invokeMe".
             _log.Warn("Caught an exception while trying to close a DB connection we just used.", e);
         }
     }
 }
Exemplo n.º 8
0
 public EnhancedPacketBlock(TimestampedData timestampedData)
 {
     this.timestampedData = timestampedData;
 }
Exemplo n.º 9
0
        public unsafe void Output(TimestampedData timestampedData)
        {
            if (timestampedData.Protocol != 6)
            {
                return;                                // TCP
            }
            var mark      = timestampedData.RouteMark;
            var tcpPacket = new TCPPacket(timestampedData.Data, timestampedData.HeaderLength);

            if (!tcpPacket.IsValid || (tcpPacket.Flags & TCPFlags.ACK) != TCPFlags.ACK)
            {
                if ((tcpPacket.Flags & FlagFinRst) != 0)
                {
                    IpcClient.SendSignal(Signal.InternalConnectionFin, null, true);
                }

                return;
            }

            if (tcpPacket.Payload == null || tcpPacket.Payload.Length == 0)
            {
                return;
            }

            Interlocked.Increment(ref this._packetsAnalyzed);

            _buffer.Seek(0, SeekOrigin.End);                               // pos = end
            _buffer.Write(tcpPacket.Payload, 0, tcpPacket.Payload.Length); // pos = end

            var needPurge     = false;
            var currentHeader = new byte[HeaderLength];

            for (;;)
            {
                if (!needPurge)
                {
                    _buffer.Seek(processedLength, SeekOrigin.Begin);                                 // pos = 0

                    if (_buffer.Length - processedLength <= HeaderLength || processedLength > 65536) // not enough data
                    {
                        var remaining = _buffer.Length - processedLength;
                        if (remaining < 0)
                        {
                            throw new AggregateException("Invalid processedLength");
                        }

                        var tmp = new byte[remaining];
                        _buffer.Read(tmp, 0, tmp.Length);
                        _buffer.SetLength(0);
                        _buffer.Write(tmp, 0, tmp.Length);
                        processedLength = 0;
                        return;
                    }

                    _buffer.Read(currentHeader, 0, HeaderLength); // pos = 40


                    if (!IsValidHeader(currentHeader))
                    {
                        needPurge = true;
                        continue;
                    }

                    NetworkPacketHeader header;
                    fixed(byte *p = &currentHeader[0])
                    {
                        header = *(NetworkPacketHeader *)p;
                    }

                    if (header.Malformed)
                    {
                        needPurge = true;
                        continue;
                    }

                    var timeDelta = Math.Abs(Helper.DateTimeToUnixTimeStamp(DateTime.Now) * 1000 - header.Timestamp);

                    if (header.Length < HeaderLength || (header.Timestamp != 0 && timeDelta > 60000)) // > 1 min
                    {
                        needPurge = true;
                        continue;
                    }

                    if (header.Length > _buffer.Length - processedLength)
                    {
                        return; // wait for more content
                    }
                    var content = GenerateContent(_buffer, header.IsCompressed, header.Length);

                    if (content.Length == 0)
                    {
                        content.Dispose();

                        needPurge = true;
                        continue;
                    }

                    ConsumeContent(content, header, mark);

                    processedLength += header.Length; // pos = 0
                }
                else
                {
                    needPurge = false;

                    var bytes    = _buffer.ToArray();
                    var newStart = processedLength + 1;
                    var pos      = FindMagic(new ArraySegment <byte>(bytes, newStart, bytes.Length - newStart));

                    if (pos == -1)
                    {
                        _buffer.SetLength(0); // no available data, drop all content
                        processedLength = 0;
                        return;
                    }

                    processedLength += pos + 1;
                }
            }
        }