<commit_before>// MaxDelaySensor.cc

#include "lib.h"
#include "MaxDelaySensor.h"
#include "DelaySensor.h"
#include "CommandOutput.h"
#include "StateSensor.h"

using namespace std;

MaxDelaySensor::MaxDelaySensor(DelaySensor * newDelay, StateSensor * newState,
        MinDelaySensor *newminDelay)
  : maximum(0, 0.01)
  , delay(newDelay)
  , state(newState)
  , mindelay(newminDelay)
{
}

void MaxDelaySensor::localSend(PacketInfo *)
{
}

void MaxDelaySensor::localAck(PacketInfo * packet)
{
  int current = delay->getLastDelay();
  /*
   * We assume that the minimum delay is transmission delay plus the
   * propagation delay. Thus, any additional time is from queueing.
   * Thus, queueingDelay = maxDelay - minDelay
   * BUT - the latency we feed to dummynet is the whole time spend in the
   * dummynet queue, so we have to include the 'forward' part of the min delay
   * in our calculation.
   */
  int minimumDelay = mindelay->getMinDelay();
  int queueingDelay = current - (minimumDelay/2);
  logWrite(SENSOR, "current=%d,min=%d,queueing=%d,saturated=%d", current,
           minimumDelay, queueingDelay, state->isSaturated());
  if (queueingDelay < 0) {
    logWrite(ERROR,"Queueing delay is less than zero!");
  }
  if ((queueingDelay > maximum) && (current != 0) && state->isSaturated())
  {
    ostringstream buffer;
    buffer << "MAXINQ=" << queueingDelay;
    maximum.reset(queueingDelay);
    global::output->eventMessage(buffer.str(), packet->elab);
  }
  else
  {
    maximum.decay();
  }
}
<commit_msg>Bugfix: Only try to get the max delay for established connections.<commit_after>// MaxDelaySensor.cc

#include "lib.h"
#include "MaxDelaySensor.h"
#include "DelaySensor.h"
#include "CommandOutput.h"
#include "StateSensor.h"

using namespace std;

MaxDelaySensor::MaxDelaySensor(DelaySensor * newDelay, StateSensor * newState,
        MinDelaySensor *newminDelay)
  : maximum(0, 0.01)
  , delay(newDelay)
  , state(newState)
  , mindelay(newminDelay)
{
}

void MaxDelaySensor::localSend(PacketInfo *)
{
}

void MaxDelaySensor::localAck(PacketInfo * packet)
{

  /*
   * Only try to make this calculation on established connections
   */
  if (state->getState() != StateSensor::ESTABLISHED) {
    return;
  }

  /*
   * We assume that the minimum delay is transmission delay plus the
   * propagation delay. Thus, any additional time is from queueing.
   * Thus, queueingDelay = maxDelay - minDelay
   * BUT - the latency we feed to dummynet is the whole time spend in the
   * dummynet queue, so we have to include the 'forward' part of the min delay
   * in our calculation.
   */
  int current = delay->getLastDelay();
  int minimumDelay = mindelay->getMinDelay();
  int queueingDelay = current - (minimumDelay/2);
  logWrite(SENSOR, "current=%d,min=%d,queueing=%d,saturated=%d", current,
           minimumDelay, queueingDelay, state->isSaturated());
  if (queueingDelay < 0) {
    logWrite(ERROR,"Queueing delay is less than zero!");
  }
  if ((queueingDelay > maximum) && (current != 0) && state->isSaturated())
  {
    ostringstream buffer;
    buffer << "MAXINQ=" << queueingDelay;
    maximum.reset(queueingDelay);
    global::output->eventMessage(buffer.str(), packet->elab);
  }
  else
  {
    maximum.decay();
  }
}

{'fraction_non_alphanumeric': 0.12496152662357649, 'fraction_numerical': 0.0043090181594336715, 'mean_word_length': 4.0, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '337933', 'n_tokens_mistral': 1055, 'n_tokens_neox': 1053, 'n_words': 277}