aboutsummaryrefslogtreecommitdiff
path: root/src/addrman.h
diff options
context:
space:
mode:
authorEthanHeilman <ethan.r.heilman@gmail.com>2015-09-22 15:24:16 -0400
committerEthanHeilman <ethan.r.heilman@gmail.com>2015-09-24 15:20:48 -0400
commit1534d9a83c3648709690f8ad6af752b782a35be7 (patch)
treee97554f6ee564182aa1c6e09af938c39f222b684 /src/addrman.h
parent8bc1b3a1f37b86014bca583f8e33a5dd75772019 (diff)
downloadbitcoin-1534d9a83c3648709690f8ad6af752b782a35be7.tar.xz
Creates unittests for addrman, makes addrman testable.
Adds several unittests for addrman to verify it works as expected. Makes small modifications to addrman to allow deterministic and targeted tests.
Diffstat (limited to 'src/addrman.h')
-rw-r--r--src/addrman.h16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/addrman.h b/src/addrman.h
index 384b6cfdb9..1123caabfa 100644
--- a/src/addrman.h
+++ b/src/addrman.h
@@ -22,6 +22,8 @@
*/
class CAddrInfo : public CAddress
{
+
+
public:
//! last try whatsoever by us (memory only)
int64_t nLastTry;
@@ -230,8 +232,8 @@ protected:
//! Mark an entry as attempted to connect.
void Attempt_(const CService &addr, int64_t nTime);
- //! Select an address to connect to.
- CAddrInfo Select_();
+ //! Select an address to connect to, if newOnly is set to true, only the new table is selected from.
+ CAddrInfo Select_(bool newOnly);
#ifdef DEBUG_ADDRMAN
//! Perform consistency check. Returns an error code or zero.
@@ -532,13 +534,13 @@ public:
/**
* Choose an address to connect to.
*/
- CAddrInfo Select()
+ CAddrInfo Select(bool newOnly = false)
{
CAddrInfo addrRet;
{
LOCK(cs);
Check();
- addrRet = Select_();
+ addrRet = Select_(newOnly);
Check();
}
return addrRet;
@@ -567,6 +569,12 @@ public:
Check();
}
}
+
+ //! Ensure that bucket placement is always the same for testing purposes.
+ void MakeDeterministic(){
+ nKey.SetNull(); //Do not use outside of tests.
+ }
+
};
#endif // BITCOIN_ADDRMAN_H