From 308d924415d253bce1fefcfd1f5a8fa55bf07dbb Mon Sep 17 00:00:00 2001 From: d33tah Date: Wed, 23 Jul 2014 14:37:16 +0000 Subject: [PATCH] Remove an unneeded duplicate variable assignment. --- global_structures.h | 19 +++++++++++ osscan2.cc | 44 +++++++++---------------- scan_engine.cc | 79 +++++++++++++++++---------------------------- 3 files changed, 65 insertions(+), 77 deletions(-) diff --git a/global_structures.h b/global_structures.h index fdb591b2b..ed3f68d71 100644 --- a/global_structures.h +++ b/global_structures.h @@ -238,6 +238,7 @@ struct FingerPrintDB { /* Based on TCP congestion control techniques from RFC2581. */ struct ultra_timing_vals { +private: double cwnd; /* Congestion window - in probes */ int ssthresh; /* The threshold above which mode is changed from slow start to congestion avoidance */ @@ -256,6 +257,24 @@ struct ultra_timing_vals { struct timeval last_drop; double cc_scale(const struct scan_performance_vars *perf); +public: + ultra_timing_vals(double cwnd_arg, int ssthresh_arg, struct timeval *now) { + cwnd = cwnd_arg; + ssthresh = ssthresh_arg; + num_replies_expected = 0; + num_replies_received = 0; + num_updates = 0; + if (now == NULL) + gettimeofday(&last_drop, NULL); + else + last_drop = *now; + } + double getCwnd() const { return cwnd; } + int getSsthresh() const { return ssthresh; } + int getNumUpdates() const { return num_updates; } + struct timeval getLastDrop() const { return last_drop; } + void incrementNumUpdates() { num_updates++; } + void incrementNumRepliesExpected() { num_replies_expected++; } void ack(const struct scan_performance_vars *perf, double scale = 1.0); void drop(unsigned in_flight, const struct scan_performance_vars *perf, const struct timeval *now); diff --git a/osscan2.cc b/osscan2.cc index 78ff04b69..a22e0f0bd 100644 --- a/osscan2.cc +++ b/osscan2.cc @@ -999,7 +999,9 @@ const char *OFProbe::typestr() { * Implementation of class HostOsScanStats * ******************************************************************************/ -HostOsScanStats::HostOsScanStats(Target * t) { +HostOsScanStats::HostOsScanStats(Target * t) : timing(perf.host_initial_cwnd, + perf.initial_ssthresh, NULL) { + int i; target = t; @@ -1016,14 +1018,6 @@ HostOsScanStats::HostOsScanStats(Target * t) { sendDelayMs = MAX(o.scan_delay, OS_PROBE_DELAY); lastProbeSent = now; - /* Timing */ - timing.cwnd = perf.host_initial_cwnd; - timing.ssthresh = perf.initial_ssthresh; /* Will be reduced if any packets are dropped anyway */ - timing.num_replies_expected = 0; - timing.num_replies_received = 0; - timing.num_updates = 0; - gettimeofday(&timing.last_drop, NULL); - for (i = 0; i < NUM_FPTESTS; i++) FPtests[i] = NULL; for (i = 0; i < 6; i++) { @@ -1300,11 +1294,11 @@ void HostOsScan::adjust_times(HostOsScanStats *hss, OFProbe *probe, struct timev adjust_timeouts2(&(probe->sent), rcvdtime, &(stats->to)); } - stats->timing.num_replies_expected++; - stats->timing.num_updates++; + stats->timing.incrementNumRepliesExpected(); + stats->timing.incrementNumUpdates(); - hss->timing.num_replies_expected++; - hss->timing.num_updates++; + hss->timing.incrementNumRepliesExpected(); + hss->timing.incrementNumUpdates(); /* Notice a drop if 1. We get a response to a retransmitted probe (meaning the first reply was @@ -1320,9 +1314,9 @@ void HostOsScan::adjust_times(HostOsScanStats *hss, OFProbe *probe, struct timev hss->target->targetipstr()); } } - if (TIMEVAL_AFTER(probe->sent, hss->timing.last_drop)) + if (TIMEVAL_AFTER(probe->sent, hss->timing.getLastDrop())) hss->timing.drop(hss->numProbesActive(), &perf, &now); - if (TIMEVAL_AFTER(probe->sent, stats->timing.last_drop)) + if (TIMEVAL_AFTER(probe->sent, stats->timing.getLastDrop())) stats->timing.drop_group(stats->num_probes_active, &perf, &now); } @@ -1539,7 +1533,7 @@ bool HostOsScan::hostSendOK(HostOsScanStats *hss, struct timeval *when) { } } - if (hss->timing.cwnd >= hss->numProbesActive() + .5) { + if (hss->timing.getCwnd() >= hss->numProbesActive() + .5) { if (when) *when = now; return true; @@ -1571,7 +1565,7 @@ bool HostOsScan::hostSendOK(HostOsScanStats *hss, struct timeval *when) { if (tdiff < 0) { earliest_to = sendTime; } else { - if (tdiff > 0 && hss->timing.cwnd > hss->numProbesActive() + .5) { + if (tdiff > 0 && hss->timing.getCwnd() > hss->numProbesActive() + .5) { earliest_to = sendTime; } } @@ -1612,7 +1606,7 @@ bool HostOsScan::hostSeqSendOK(HostOsScanStats *hss, struct timeval *when) { return false; } - if (hss->timing.cwnd >= hss->numProbesActive() + .5) { + if (hss->timing.getCwnd() >= hss->numProbesActive() + .5) { if (when) *when = now; return true; @@ -1642,7 +1636,7 @@ bool HostOsScan::hostSeqSendOK(HostOsScanStats *hss, struct timeval *when) { if (tdiff < 0) { earliest_to = sendTime; } else { - if (tdiff > 0 && hss->timing.cwnd > hss->numProbesActive() + .5) { + if (tdiff > 0 && hss->timing.getCwnd() > hss->numProbesActive() + .5) { earliest_to = sendTime; } } @@ -2222,14 +2216,8 @@ int HostOsScan::send_closedudp_probe(HostOsScanStats *hss, * Implementation of class ScanStats * ******************************************************************************/ -ScanStats::ScanStats() { - /* init timing val */ - timing.cwnd = perf.group_initial_cwnd; - timing.ssthresh = perf.initial_ssthresh; /* Will be reduced if any packets are dropped anyway */ - timing.num_replies_expected = 0; - timing.num_replies_received = 0; - timing.num_updates = 0; - gettimeofday(&timing.last_drop, NULL); +ScanStats::ScanStats() : timing(perf.host_initial_cwnd, perf.initial_ssthresh, + NULL) { initialize_timeout_info(&to); @@ -2243,7 +2231,7 @@ bool ScanStats::sendOK() { if (num_probes_sent - num_probes_sent_at_last_wait >= 50) return false; - if (timing.cwnd < num_probes_active + 0.5) + if (timing.getCwnd() < num_probes_active + 0.5) return false; return true; diff --git a/scan_engine.cc b/scan_engine.cc index 488416079..def523485 100644 --- a/scan_engine.cc +++ b/scan_engine.cc @@ -201,7 +201,6 @@ struct ultra_scan_performance_vars : public scan_performance_vars { void init() { scan_performance_vars::init(); ping_magnifier = 3; - ping_magnifier = 3; pingtime = 1250000; tryno_cap = o.getMaxRetransmissions(); } @@ -784,14 +783,6 @@ private: /* Whether this is storing timing stats for a whole group or an individual host */ enum ultra_timing_type { TIMING_HOST, TIMING_GROUP }; -/* Initialize the ultra_timing_vals structure timing. The utt must be - TIMING_HOST or TIMING_GROUP. If you happen to have the current - time handy, pass it as now, otherwise pass NULL */ -static void init_ultra_timing_vals(ultra_timing_vals *timing, - enum ultra_timing_type utt, - int num_hosts_in_group, - struct ultra_scan_performance_vars *perf, - struct timeval *now); /* Take a buffer, buf, of size bufsz (64 bytes is sufficient) and writes a short description of the probe (arg1) into buf. It also returns @@ -1061,11 +1052,12 @@ bool ConnectScanInfo::clearSD(int sd) { } } -GroupScanStats::GroupScanStats(UltraScanInfo *UltraSI) { +GroupScanStats::GroupScanStats(UltraScanInfo *UltraSI) : timing( + UltraSI->perf.group_initial_cwnd, UltraSI->perf.initial_ssthresh, + &UltraSI->now) { memset(&latestip, 0, sizeof(latestip)); memset(&timeout, 0, sizeof(timeout)); USI = UltraSI; - init_ultra_timing_vals(&timing, TIMING_GROUP, USI->numIncompleteHosts(), &(USI->perf), &USI->now); initialize_timeout_info(&to); /* Default timout should be much lower for arp */ if (USI->ping_scan_arp) @@ -1200,7 +1192,7 @@ bool GroupScanStats::sendOK(struct timeval *when) { return true; } - if (timing.cwnd >= num_probes_active + 0.5) { + if (timing.getCwnd() >= num_probes_active + 0.5) { if (when) *when = USI->now; return true; @@ -1241,7 +1233,9 @@ static bool pingprobe_is_appropriate(const UltraScanInfo *USI, return false; } -HostScanStats::HostScanStats(Target *t, UltraScanInfo *UltraSI) { +HostScanStats::HostScanStats(Target *t, UltraScanInfo *UltraSI) : timing( + UltraSI->perf.host_initial_cwnd, UltraSI->perf.initial_ssthresh, + &UltraSI->now) { target = t; USI = UltraSI; next_portidx = 0; @@ -1265,7 +1259,6 @@ HostScanStats::HostScanStats(Target *t, UltraScanInfo *UltraSI) { ports_finished = 0; numprobes_sent = 0; memset(&completiontime, 0, sizeof(completiontime)); - init_ultra_timing_vals(&timing, TIMING_HOST, 1, &(USI->perf), &USI->now); bench_tryno = 0; memset(&sdn, 0, sizeof(sdn)); sdn.last_boost = USI->now; @@ -1339,7 +1332,9 @@ unsigned long HostScanStats::probeExpireTime(const UltraProbe *probe) { (call it again if they do). when will become now if it returns true. */ bool HostScanStats::sendOK(struct timeval *when) { - struct ultra_timing_vals tmng; + struct ultra_timing_vals tmng = ultra_timing_vals(USI->perf.group_initial_cwnd, + USI->perf.initial_ssthresh, + &USI->now); std::list::iterator probeI; struct timeval probe_to, earliest_to, sendTime; long tdiff; @@ -1382,7 +1377,7 @@ bool HostScanStats::sendOK(struct timeval *when) { } getTiming(&tmng); - if (tmng.cwnd >= num_probes_active + .5 && + if (tmng.getCwnd() >= num_probes_active + .5 && (freshPortsLeft() || num_probes_waiting_retransmit || !retry_stack.empty())) { if (when) *when = USI->now; @@ -1419,7 +1414,7 @@ bool HostScanStats::sendOK(struct timeval *when) { earliest_to = sendTime; } else { getTiming(&tmng); - if (tdiff > 0 && tmng.cwnd > num_probes_active + .5) { + if (tdiff > 0 && tmng.getCwnd() > num_probes_active + .5) { earliest_to = sendTime; } } @@ -2053,24 +2048,6 @@ int determineScanGroupSize(int hosts_scanned_so_far, return groupsize; } -/* Initialize the ultra_timing_vals structure timing. The utt must be - TIMING_HOST or TIMING_GROUP. If you happen to have the current - time handy, pass it as now, otherwise pass NULL */ -static void init_ultra_timing_vals(ultra_timing_vals *timing, - enum ultra_timing_type utt, - int num_hosts_in_group, - struct ultra_scan_performance_vars *perf, - struct timeval *now) { - timing->cwnd = (utt == TIMING_HOST) ? perf->host_initial_cwnd : perf->group_initial_cwnd; - timing->ssthresh = perf->initial_ssthresh; /* Will be reduced if any packets are dropped anyway */ - timing->num_replies_expected = 0; - timing->num_replies_received = 0; - timing->num_updates = 0; - if (now) - timing->last_drop = *now; - else gettimeofday(&timing->last_drop, NULL); -} - /* Returns the next probe to try against target. Supports many different types of probes (see probespec structure). Returns 0 and fills in pspec if there is a new probe, -1 if there are none @@ -2375,11 +2352,11 @@ static void ultrascan_adjust_timing(UltraScanInfo *USI, HostScanStats *hss, struct timeval *rcvdtime) { int ping_magnifier = (probe->isPing()) ? USI->perf.ping_magnifier : 1; - USI->gstats->timing.num_replies_expected++; - USI->gstats->timing.num_updates++; + USI->gstats->timing.incrementNumRepliesExpected(); + USI->gstats->timing.incrementNumUpdates(); - hss->timing.num_replies_expected++; - hss->timing.num_updates++; + hss->timing.incrementNumRepliesExpected(); + hss->timing.incrementNumUpdates(); /* Notice a drop if 1) We get a response to a retransmitted probe (meaning the first reply was @@ -2390,9 +2367,9 @@ static void ultrascan_adjust_timing(UltraScanInfo *USI, HostScanStats *hss, if (o.debugging > 1) log_write(LOG_PLAIN, "Ultrascan DROPPED %sprobe packet to %s detected\n", probe->isPing() ? "PING " : "", hss->target->targetipstr()); // Drops often come in big batches, but we only want one decrease per batch. - if (TIMEVAL_AFTER(probe->sent, hss->timing.last_drop)) + if (TIMEVAL_AFTER(probe->sent, hss->timing.getLastDrop())) hss->timing.drop(hss->num_probes_active, &USI->perf, &USI->now); - if (TIMEVAL_AFTER(probe->sent, USI->gstats->timing.last_drop)) + if (TIMEVAL_AFTER(probe->sent, USI->gstats->timing.getLastDrop())) USI->gstats->timing.drop_group(USI->gstats->num_probes_active, &USI->perf, &USI->now); } /* If !probe->isPing() and rcvdtime == NULL, do nothing. */ @@ -2700,15 +2677,15 @@ void HostScanStats::getTiming(struct ultra_timing_vals *tmng) { } /* Otherwise, use the global cwnd stats if it has sufficient responses */ - if (USI->gstats->timing.num_updates > 1) { + if (USI->gstats->timing.getNumUpdates() > 1) { *tmng = USI->gstats->timing; return; } + *tmng = ultra_timing_vals(USI->perf.host_initial_cwnd, + USI->perf.initial_ssthresh, NULL); + /* Last resort is to use canned values */ - tmng->cwnd = USI->perf.host_initial_cwnd; - tmng->ssthresh = USI->perf.initial_ssthresh; - tmng->num_updates = 0; return; } @@ -4128,15 +4105,19 @@ static void printAnyStats(UltraScanInfo *USI) { std::list::iterator hostI; HostScanStats *hss; - struct ultra_timing_vals hosttm; + struct timeval now; + gettimeofday(&now, NULL); + struct ultra_timing_vals hosttm = ultra_timing_vals(USI->perf.group_initial_cwnd, + USI->perf.initial_ssthresh, + &now); /* Print debugging states for each host being scanned */ if (o.debugging > 2) { log_write(LOG_PLAIN, "**TIMING STATS** (%.4fs): IP, probes active/freshportsleft/retry_stack/outstanding/retranwait/onbench, cwnd/ssthresh/delay, timeout/srtt/rttvar/\n", o.TimeSinceStart()); log_write(LOG_PLAIN, " Groupstats (%d/%d incomplete): %d/*/*/*/*/* %.2f/%d/* %d/%d/%d\n", USI->numIncompleteHosts(), USI->numInitialHosts(), - USI->gstats->num_probes_active, USI->gstats->timing.cwnd, - USI->gstats->timing.ssthresh, USI->gstats->to.timeout, + USI->gstats->num_probes_active, USI->gstats->timing.getCwnd(), + USI->gstats->timing.getSsthresh(), USI->gstats->to.timeout, USI->gstats->to.srtt, USI->gstats->to.rttvar); if (o.debugging > 3) { @@ -4149,7 +4130,7 @@ static void printAnyStats(UltraScanInfo *USI) { (int) hss->retry_stack.size(), hss->num_probes_outstanding(), hss->num_probes_waiting_retransmit, (int) hss->probe_bench.size(), - hosttm.cwnd, hosttm.ssthresh, hss->sdn.delayms, + hosttm.getCwnd(), hosttm.getSsthresh(), hss->sdn.delayms, hss->probeTimeout(), hss->target->to.srtt, hss->target->to.rttvar); }