Skip to content

Commit 666047b

Browse files
authored
Merge pull request jl777#373 from KomodoPlatform/beta
0.6.1
2 parents b998ca1 + dd40e2d commit 666047b

38 files changed

+1565
-263
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ sudo apt-get install build-essential pkg-config libc6-dev m4 g++-multilib autoco
115115
curl https://sh.rustup.rs -sSf | sh
116116
source $HOME/.cargo/env
117117
rustup target add x86_64-pc-windows-gnu
118+
119+
sudo update-alternatives --config x86_64-w64-mingw32-gcc
120+
# (configure to use POSIX variant)
121+
sudo update-alternatives --config x86_64-w64-mingw32-g++
122+
# (configure to use POSIX variant)
123+
118124
git clone https://github.com/jl777/komodo --branch master --single-branch
119125
cd komodo
120126
./zcutil/fetch-params.sh

depends/funcs.mk

+3-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ $(1)_download_path_fixed=$(subst :,\:,$$($(1)_download_path))
9191

9292

9393
#default commands
94+
# The default behavior for tar will try to set ownership when running as uid 0 and may not succeed, --no-same-owner disables this behavior
9495
$(1)_fetch_cmds ?= $(call fetch_file,$(1),$(subst \:,:,$$($(1)_download_path_fixed)),$$($(1)_download_file),$($(1)_file_name),$($(1)_sha256_hash))
95-
$(1)_extract_cmds ?= mkdir -p $$($(1)_extract_dir) && echo "$$($(1)_sha256_hash) $$($(1)_source)" > $$($(1)_extract_dir)/.$$($(1)_file_name).hash && $(build_SHA256SUM) -c $$($(1)_extract_dir)/.$$($(1)_file_name).hash && tar --strip-components=1 -xf $$($(1)_source)
96+
$(1)_extract_cmds ?= mkdir -p $$($(1)_extract_dir) && echo "$$($(1)_sha256_hash) $$($(1)_source)" > $$($(1)_extract_dir)/.$$($(1)_file_name).hash && $(build_SHA256SUM) -c $$($(1)_extract_dir)/.$$($(1)_file_name).hash && tar --no-same-owner --strip-components=1 -xf $$($(1)_source)
9697
$(1)_preprocess_cmds ?=
9798
$(1)_build_cmds ?=
9899
$(1)_config_cmds ?=
@@ -193,7 +194,7 @@ $($(1)_preprocessed): | $($(1)_dependencies) $($(1)_extracted)
193194
$(AT)touch $$@
194195
$($(1)_configured): | $($(1)_preprocessed)
195196
$(AT)echo Configuring $(1)...
196-
$(AT)rm -rf $(host_prefix); mkdir -p $(host_prefix)/lib; cd $(host_prefix); $(foreach package,$($(1)_all_dependencies), tar xf $($(package)_cached); )
197+
$(AT)rm -rf $(host_prefix); mkdir -p $(host_prefix)/lib; cd $(host_prefix); $(foreach package,$($(1)_all_dependencies), tar --no-same-owner -xf $($(package)_cached); )
197198
$(AT)mkdir -p $$(@D)
198199
$(AT)+cd $$(@D); $($(1)_config_env) $(call $(1)_config_cmds, $(1))
199200
$(AT)touch $$@

src/Makefile.am

+4
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ BITCOIN_CORE_H = \
187187
crypto/haraka_portable.h \
188188
crypto/verus_hash.h \
189189
deprecation.h \
190+
fs.h \
190191
hash.h \
191192
httprpc.h \
192193
httpserver.h \
@@ -245,6 +246,7 @@ BITCOIN_CORE_H = \
245246
txdb.h \
246247
txmempool.h \
247248
ui_interface.h \
249+
util/asmap.h \
248250
uint256.h \
249251
uint252.h \
250252
undo.h \
@@ -312,6 +314,7 @@ libbitcoin_server_a_SOURCES = \
312314
cc/betprotocol.cpp \
313315
chain.cpp \
314316
checkpoints.cpp \
317+
fs.cpp \
315318
crosschain.cpp \
316319
crosschain_authority.cpp \
317320
crypto/haraka.h \
@@ -521,6 +524,7 @@ libbitcoin_util_a_SOURCES = \
521524
utilmoneystr.cpp \
522525
utilstrencodings.cpp \
523526
utiltime.cpp \
527+
util/asmap.cpp \
524528
$(BITCOIN_CORE_H) \
525529
$(LIBZCASH_H)
526530

src/Makefile.ktest.include

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ komodo_test_SOURCES = \
1212
test-komodo/test_parse_notarisation.cpp \
1313
test-komodo/test_buffered_file.cpp \
1414
test-komodo/test_sha256_crypto.cpp \
15-
test-komodo/test_script_standard_tests.cpp
15+
test-komodo/test_script_standard_tests.cpp \
16+
test-komodo/test_addrman.cpp \
17+
test-komodo/test_netbase_tests.cpp
1618

1719
komodo_test_CPPFLAGS = $(komodod_CPPFLAGS)
1820

src/ac/etomic

-2
This file was deleted.

src/ac/k64

-2
This file was deleted.

src/ac/ksb

-2
This file was deleted.

src/ac/kv

-2
This file was deleted.

src/ac/our

-2
This file was deleted.

src/ac/zexo

-2
This file was deleted.

src/addrman.cpp

+44-11
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,25 @@
2323
#include "serialize.h"
2424
#include "streams.h"
2525

26-
int CAddrInfo::GetTriedBucket(const uint256& nKey) const
26+
int CAddrInfo::GetTriedBucket(const uint256& nKey, const std::vector<bool> &asmap) const
2727
{
2828
uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << GetKey()).GetHash().GetCheapHash();
29-
uint64_t hash2 = (CHashWriter(SER_GETHASH, 0) << nKey << GetGroup() << (hash1 % ADDRMAN_TRIED_BUCKETS_PER_GROUP)).GetHash().GetCheapHash();
30-
return hash2 % ADDRMAN_TRIED_BUCKET_COUNT;
29+
uint64_t hash2 = (CHashWriter(SER_GETHASH, 0) << nKey << GetGroup(asmap) << (hash1 % ADDRMAN_TRIED_BUCKETS_PER_GROUP)).GetHash().GetCheapHash();
30+
int tried_bucket = hash2 % ADDRMAN_TRIED_BUCKET_COUNT;
31+
uint32_t mapped_as = GetMappedAS(asmap);
32+
LogPrint("net", "IP %s mapped to AS%i belongs to tried bucket %i\n", ToStringIP(), mapped_as, tried_bucket);
33+
return tried_bucket;
3134
}
3235

33-
int CAddrInfo::GetNewBucket(const uint256& nKey, const CNetAddr& src) const
36+
int CAddrInfo::GetNewBucket(const uint256& nKey, const CNetAddr& src, const std::vector<bool> &asmap) const
3437
{
35-
std::vector<unsigned char> vchSourceGroupKey = src.GetGroup();
36-
uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << GetGroup() << vchSourceGroupKey).GetHash().GetCheapHash();
38+
std::vector<unsigned char> vchSourceGroupKey = src.GetGroup(asmap);
39+
uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << GetGroup(asmap) << vchSourceGroupKey).GetHash().GetCheapHash();
3740
uint64_t hash2 = (CHashWriter(SER_GETHASH, 0) << nKey << vchSourceGroupKey << (hash1 % ADDRMAN_NEW_BUCKETS_PER_SOURCE_GROUP)).GetHash().GetCheapHash();
38-
return hash2 % ADDRMAN_NEW_BUCKET_COUNT;
41+
int new_bucket = hash2 % ADDRMAN_NEW_BUCKET_COUNT;
42+
uint32_t mapped_as = GetMappedAS(asmap);
43+
LogPrint("net", "IP %s mapped to AS%i belongs to new bucket %i\n", ToStringIP(), mapped_as, new_bucket);
44+
return new_bucket;
3945
}
4046

4147
int CAddrInfo::GetBucketPosition(const uint256 &nKey, bool fNew, int nBucket) const
@@ -175,7 +181,7 @@ void CAddrMan::MakeTried(CAddrInfo& info, int nId)
175181
assert(info.nRefCount == 0);
176182

177183
// which tried bucket to move the entry to
178-
int nKBucket = info.GetTriedBucket(nKey);
184+
int nKBucket = info.GetTriedBucket(nKey, m_asmap);
179185
int nKBucketPos = info.GetBucketPosition(nKey, false, nKBucket);
180186

181187
// first make space to add it (the existing tried entry there is moved to new, deleting whatever is there).
@@ -191,7 +197,7 @@ void CAddrMan::MakeTried(CAddrInfo& info, int nId)
191197
nTried--;
192198

193199
// find which new bucket it belongs to
194-
int nUBucket = infoOld.GetNewBucket(nKey);
200+
int nUBucket = infoOld.GetNewBucket(nKey, m_asmap);
195201
int nUBucketPos = infoOld.GetBucketPosition(nKey, true, nUBucket);
196202
ClearNew(nUBucket, nUBucketPos);
197203
assert(vvNew[nUBucket][nUBucketPos] == -1);
@@ -301,7 +307,7 @@ bool CAddrMan::Add_(const CAddress& addr, const CNetAddr& source, int64_t nTimeP
301307
fNew = true;
302308
}
303309

304-
int nUBucket = pinfo->GetNewBucket(nKey, source);
310+
int nUBucket = pinfo->GetNewBucket(nKey, source, m_asmap);
305311
int nUBucketPos = pinfo->GetBucketPosition(nKey, true, nUBucket);
306312
if (vvNew[nUBucket][nUBucketPos] != nId) {
307313
bool fInsert = vvNew[nUBucket][nUBucketPos] == -1;
@@ -453,7 +459,7 @@ int CAddrMan::Check_()
453459
if (vvTried[n][i] != -1) {
454460
if (!setTried.count(vvTried[n][i]))
455461
return -11;
456-
if (mapInfo[vvTried[n][i]].GetTriedBucket(nKey) != n)
462+
if (mapInfo[vvTried[n][i]].GetTriedBucket(nKey, m_asmap) != n)
457463
return -17;
458464
if (mapInfo[vvTried[n][i]].GetBucketPosition(nKey, false, n) != i)
459465
return -18;
@@ -530,3 +536,30 @@ void CAddrMan::Connected_(const CService& addr, int64_t nTime)
530536
int CAddrMan::RandomInt(int nMax){
531537
return GetRandInt(nMax);
532538
}
539+
540+
std::vector<bool> CAddrMan::DecodeAsmap(fs::path path)
541+
{
542+
std::vector<bool> bits;
543+
FILE *filestr = fsbridge::fopen(path, "rb");
544+
CAutoFile file(filestr, SER_DISK, CLIENT_VERSION);
545+
if (file.IsNull()) {
546+
LogPrintf("Failed to open asmap file from disk\n");
547+
return bits;
548+
}
549+
fseek(filestr, 0, SEEK_END);
550+
int length = ftell(filestr);
551+
LogPrintf("Opened asmap file %s (%d bytes) from disk\n", path, length);
552+
fseek(filestr, 0, SEEK_SET);
553+
char cur_byte;
554+
for (int i = 0; i < length; ++i) {
555+
file >> cur_byte;
556+
for (int bit = 0; bit < 8; ++bit) {
557+
bits.push_back((cur_byte >> bit) & 1);
558+
}
559+
}
560+
if (!SanityCheckASMap(bits)) {
561+
LogPrintf("Sanity check of asmap file %s failed\n", path);
562+
return {};
563+
}
564+
return bits;
565+
}

0 commit comments

Comments
 (0)