Nmap Development mailing list archives

Fw: [nmap-svn] r36095 - nmap


From: Tudor-Emil COMAN <tudor_emil.coman () cti pub ro>
Date: Fri, 12 Aug 2016 17:37:51 +0000

Dan,



Yes that covers it pretty well, I'll try to give write more helpful commit messages.


Cheers,

Tudor

________________________________
From: Daniel Miller <bonsaiviking () gmail com>
Sent: Friday, August 12, 2016 7:20:55 AM
To: Tudor-Emil COMAN
Cc: Nmap-dev
Subject: Re: [nmap-svn] r36095 - nmap

Tudor,

Can you explain this to me? The commit message was very terse and does not offer any information about what has 
changed. I see that you changed from using std::lower_bound to std::set::find, which in the case of std::set means 
improving from linear to logarithmic time. In order to do this, you use a comparison object, HssPredicate, to trick the 
find() function into finding the element with a specific sockaddr value without instantiating a whole HostScanStats 
object. Because of using the set's find method, you can't pass a new comparison object to each call like you could with 
std::lower_bound, so you use a static member of the comparison object's class. This works for us because Nmap is not 
multithreaded.

Does that about cover it? Or am I missing something?

Dan



On Wed, Aug 10, 2016 at 10:39 AM, <commit-mailer () nmap org<mailto:commit-mailer () nmap org>> wrote:
Author: tudor
Date: Wed Aug 10 08:39:19 2016
New Revision: 36095

Log:
UltraScanInfo::findHost is now faster

Modified:
   nmap/scan_engine.cc
   nmap/scan_engine.h

Modified: nmap/scan_engine.cc
==============================================================================
--- nmap/scan_engine.cc (original)
+++ nmap/scan_engine.cc Wed Aug 10 08:39:19 2016
@@ -154,15 +154,12 @@


 int HssPredicate::operator() (HostScanStats *lhs, HostScanStats *rhs) {
-  return 0 > sockaddr_storage_cmp(lhs->target->TargetSockAddr(), rhs->target->TargetSockAddr());
-}
-
-int SockAddrPredicate::operator() (HostScanStats *lhs, HostScanStats *rhs) {
   const struct sockaddr_storage *lss, *rss;
   lss = (lhs) ? lhs->target->TargetSockAddr() : ss;
   rss = (rhs) ? rhs->target->TargetSockAddr() : ss;
   return 0 > sockaddr_storage_cmp(lss, rss);
 }
+struct sockaddr_storage *HssPredicate::ss = NULL;

 void UltraScanInfo::log_overall_rates(int logt) {
   log_write(logt, "Overall sending rates: %.2f packets / s", send_rate_meter.getOverallPacketRate(&now));
@@ -1139,17 +1136,17 @@
 HostScanStats *UltraScanInfo::findHost(struct sockaddr_storage *ss) {
   std::set<HostScanStats *>::iterator hss;

-  SockAddrPredicate p(ss);
+  HssPredicate::ss = ss;
   HostScanStats *fakeHss = NULL;

-  hss = std::lower_bound(incompleteHosts.begin(), incompleteHosts.end(), fakeHss, p);
+  hss = incompleteHosts.find(fakeHss);
   if (hss != incompleteHosts.end()) {
     if (o.debugging > 2)
       log_write(LOG_STDOUT, "Found %s in incomplete hosts list.\n", (*hss)->target->targetipstr());
     return *hss;
   }

-  hss = std::lower_bound(completedHosts.begin(), completedHosts.end(), fakeHss, p);
+  hss = completedHosts.find(fakeHss);
   if (hss != completedHosts.end()) {
     if (o.debugging > 2)
       log_write(LOG_STDOUT, "Found %s in completed hosts list.\n", (*hss)->target->targetipstr());

Modified: nmap/scan_engine.h
==============================================================================
--- nmap/scan_engine.h  (original)
+++ nmap/scan_engine.h  Wed Aug 10 08:39:19 2016
@@ -654,15 +654,7 @@
 struct HssPredicate {
 public:
   int operator() (HostScanStats *lhs, HostScanStats *rhs);
-};
-
-struct SockAddrPredicate {
-public:
-  SockAddrPredicate(struct sockaddr_storage *ss) {
-    this->ss = ss;
-  }
-  int operator() (HostScanStats *lhs, HostScanStats *rhs);
-  struct sockaddr_storage *ss;
+  static struct sockaddr_storage *ss;
 };

 class UltraScanInfo {

_______________________________________________
Sent through the svn mailing list
https://nmap.org/mailman/listinfo/svn

_______________________________________________
Sent through the dev mailing list
https://nmap.org/mailman/listinfo/dev
Archived at http://seclists.org/nmap-dev/

Current thread: