Skip to content

Commit

Permalink
logging: asmap logging and #include fixups
Browse files Browse the repository at this point in the history
- move asmap #includes to sorted positions in addrman and init (move-only)

- remove redundant quotes in asmap InitError, update test

- remove full stops from asmap logging to be consistent with debug logging,
  update tests
  • Loading branch information
jonatack authored and furszy committed Jul 28, 2021
1 parent 0c9efb8 commit 2fc1f37
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
10 changes: 5 additions & 5 deletions src/addrman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#include "addrman.h"

#include "hash.h"
#include "serialize.h"
#include "streams.h"
#include "logging.h"
#include "serialize.h"


int CAddrInfo::GetTriedBucket(const uint256& nKey, const std::vector<bool> &asmap) const
Expand All @@ -18,7 +18,7 @@ int CAddrInfo::GetTriedBucket(const uint256& nKey, const std::vector<bool> &asma
uint64_t hash2 = (CHashWriter(SER_GETHASH, 0) << nKey << GetGroup(asmap) << (hash1 % ADDRMAN_TRIED_BUCKETS_PER_GROUP)).GetHash().GetCheapHash();
int tried_bucket = hash2 % ADDRMAN_TRIED_BUCKET_COUNT;
uint32_t mapped_as = GetMappedAS(asmap);
LogPrint(BCLog::NET, "IP %s mapped to AS%i belongs to tried bucket %i.\n", ToStringIP(), mapped_as, tried_bucket);
LogPrint(BCLog::NET, "IP %s mapped to AS%i belongs to tried bucket %i\n", ToStringIP(), mapped_as, tried_bucket);
return tried_bucket;
}

Expand All @@ -29,7 +29,7 @@ int CAddrInfo::GetNewBucket(const uint256& nKey, const CNetAddr& src, const std:
uint64_t hash2 = (CHashWriter(SER_GETHASH, 0) << nKey << vchSourceGroupKey << (hash1 % ADDRMAN_NEW_BUCKETS_PER_SOURCE_GROUP)).GetHash().GetCheapHash();
int new_bucket = hash2 % ADDRMAN_NEW_BUCKET_COUNT;
uint32_t mapped_as = GetMappedAS(asmap);
LogPrint(BCLog::NET, "IP %s mapped to AS%i belongs to new bucket %i.\n", ToStringIP(), mapped_as, new_bucket);
LogPrint(BCLog::NET, "IP %s mapped to AS%i belongs to new bucket %i\n", ToStringIP(), mapped_as, new_bucket);
return new_bucket;
}

Expand Down Expand Up @@ -632,12 +632,12 @@ std::vector<bool> CAddrMan::DecodeAsmap(fs::path path)
FILE *filestr = fsbridge::fopen(path, "rb");
CAutoFile file(filestr, SER_DISK, CLIENT_VERSION);
if (file.IsNull()) {
LogPrintf("Failed to open asmap file from disk.\n");
LogPrintf("Failed to open asmap file from disk\n");
return bits;
}
fseek(filestr, 0, SEEK_END);
int length = ftell(filestr);
LogPrintf("Opened asmap file %s (%d bytes) from disk.\n", path, length);
LogPrintf("Opened asmap file %s (%d bytes) from disk\n", path, length);
fseek(filestr, 0, SEEK_SET);
char cur_byte;
for (int i = 0; i < length; ++i) {
Expand Down
11 changes: 5 additions & 6 deletions src/addrman.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,22 @@
#ifndef BITCOIN_ADDRMAN_H
#define BITCOIN_ADDRMAN_H

#include "clientversion.h"
#include "netaddress.h"
#include "protocol.h"
#include "random.h"
#include "sync.h"
#include "timedata.h"
#include "util/system.h"
#include "clientversion.h"

#include <fs.h>
#include <hash.h>
#include <iostream>
#include <map>
#include <set>
#include <stdint.h>
#include <vector>
#include <iostream>
#include <streams.h>
#include <fs.h>
#include <hash.h>

#include <vector>

/**
* Extended statistics about a CAddress
Expand Down
6 changes: 3 additions & 3 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1982,14 +1982,14 @@ bool AppInitMain()
}
std::vector<bool> asmap = CAddrMan::DecodeAsmap(asmap_path);
if (asmap.size() == 0) {
UIError(strprintf(_("Could not parse asmap file '%s'"), asmap_path));
UIError(strprintf(_("Could not parse asmap file %s"), asmap_path));
return false;
}
const uint256 asmap_version = SerializeHash(asmap);
connman.SetAsmap(std::move(asmap));
LogPrintf("Using asmap version %s for IP bucketing.\n", asmap_version.ToString());
LogPrintf("Using asmap version %s for IP bucketing\n", asmap_version.ToString());
} else {
LogPrintf("Using /16 prefix for IP bucketing.\n");
LogPrintf("Using /16 prefix for IP bucketing\n");
}

// ********************************************************* Step 12: finished
Expand Down
6 changes: 3 additions & 3 deletions test/functional/feature_asmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
VERSION = 'fec61fa21a9f46f3b17bdcd660d7f4cd90b966aad3aec593c99b35f0aca15853'

def expected_messages(filename):
return ['Opened asmap file "{}" (59 bytes) from disk.'.format(filename),
'Using asmap version {} for IP bucketing.'.format(VERSION)]
return ['Opened asmap file "{}" (59 bytes) from disk'.format(filename),
'Using asmap version {} for IP bucketing'.format(VERSION)]

class AsmapTest(PivxTestFramework):
def set_test_params(self):
Expand Down Expand Up @@ -76,7 +76,7 @@ def test_default_asmap(self):
def test_default_asmap_with_missing_file(self):
self.log.info('Test pivxd -asmap with missing default map file')
self.stop_node(0)
msg = "Error: Could not find asmap file '\"{}\"'".format(self.default_asmap)
msg = "Error: Could not find asmap file \"{}\"".format(self.default_asmap)
self.assert_start_raises_init_error(0, extra_args=['-asmap'], expected_msg=msg)

def test_empty_asmap(self):
Expand Down

0 comments on commit 2fc1f37

Please sign in to comment.