// Parse, filter and output a captured packet private void Process(TimestampedData timestampedData) { // Only parse the packet if we need to filter or raise an event if (PacketCaptured != null || this.filters.PropertyFilters.Any()) { try { var packet = this.packetParser.Parse(timestampedData.Data, timestampedData.Timestamp); if (!this.filters.IsMatch(packet)) { return; } try { PacketCaptured?.Invoke(packet); } catch (Exception ex) { this.logger.LogWarning(ex, "Unhandled error in event handler: {ErrorMessage}", ex.Message); } } catch (Exception ex) { this.logger.LogWarning(ex, "Unable to parse packet of {Length} bytes received at {Timestamp}: {ErrorMessage}", timestampedData.Data.Length, timestampedData.Timestamp, ex.Message); return; } } this.output?.Output(timestampedData); this.Statistics.IncrementCaptured(); }
private void EnqueueOutput(TimestampedData timestampedData) { if (this.isStopping) { this.outputQueue.CompleteAdding(); return; } this.outputQueue.Add(timestampedData); }
private void Output(TimestampedData timestampedData) { // Only parse the packet header if we need to filter if (this.filters.PropertyFilters.Any()) { var packet = new IPPacket(timestampedData.Data); if (!this.filters.IsMatch(packet)) { return; } } this.output.Output(timestampedData); Interlocked.Increment(ref this.packetsCaptured); }
// Queue up a captured packet for processing private void Enqueue(TimestampedData timestampedData) { if (this.isStopping) { this.processQueue.CompleteAdding(); return; } var added = this.processQueue.TryAdd(timestampedData); this.Statistics.IncrementObserved(); // Did we add the packet to the processing queue, or was it full? if (!added) { this.Statistics.IncrementDropped(); } }