Nmap Development mailing list archives
Re: [nmap-svn] r36095 - nmap
From: Daniel Miller <bonsaiviking () gmail com>
Date: Thu, 11 Aug 2016 23:20:55 -0500
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> 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:
- Re: [nmap-svn] r36095 - nmap Daniel Miller (Aug 11)
- Message not available
- Fw: [nmap-svn] r36095 - nmap Tudor-Emil COMAN (Aug 12)
- Message not available
