Skip to content

Commit

Permalink
Merge pull request dashpay#69 from cevap/patch
Browse files Browse the repository at this point in the history
Patch
  • Loading branch information
Cevap Master authored Jan 26, 2019
2 parents 00df395 + 60c41f4 commit dc05035
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 17 deletions.
16 changes: 10 additions & 6 deletions src/addrman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,10 @@ void CAddrMan::Attempt_(const CService& addr, int64_t nTime)
info.nAttempts++;
}

CAddress CAddrMan::Select_()
CAddrInfo CAddrMan::Select_()
{
if (size() == 0)
return CAddress();
return CAddrInfo();

// Use a 50% chance for choosing between tried and new table entries.
if (nTried > 0 && (nNew == 0 || GetRandInt(2) == 0)) {
Expand All @@ -346,8 +346,10 @@ CAddress CAddrMan::Select_()
while (1) {
int nKBucket = GetRandInt(ADDRMAN_TRIED_BUCKET_COUNT);
int nKBucketPos = GetRandInt(ADDRMAN_BUCKET_SIZE);
if (vvTried[nKBucket][nKBucketPos] == -1)
continue;
while (vvTried[nKBucket][nKBucketPos] == -1) {
nKBucket = (nKBucket + insecure_rand()) % ADDRMAN_TRIED_BUCKET_COUNT;
nKBucketPos = (nKBucketPos + insecure_rand()) % ADDRMAN_BUCKET_SIZE;
}
int nId = vvTried[nKBucket][nKBucketPos];
assert(mapInfo.count(nId) == 1);
CAddrInfo& info = mapInfo[nId];
Expand All @@ -361,8 +363,10 @@ CAddress CAddrMan::Select_()
while (1) {
int nUBucket = GetRandInt(ADDRMAN_NEW_BUCKET_COUNT);
int nUBucketPos = GetRandInt(ADDRMAN_BUCKET_SIZE);
if (vvNew[nUBucket][nUBucketPos] == -1)
continue;
while (vvNew[nUBucket][nUBucketPos] == -1) {
nUBucket = (nUBucket + insecure_rand()) % ADDRMAN_NEW_BUCKET_COUNT;
nUBucketPos = (nUBucketPos + insecure_rand()) % ADDRMAN_BUCKET_SIZE;
}
int nId = vvNew[nUBucket][nUBucketPos];
assert(mapInfo.count(nId) == 1);
CAddrInfo& info = mapInfo[nId];
Expand Down
13 changes: 7 additions & 6 deletions src/addrman.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@
*/
class CAddrInfo : public CAddress
{
public:
//! last try whatsoever by us (memory only)
int64_t nLastTry;

private:
//! where knowledge about this address first came from
CNetAddr source;

//! last successful connection by us
int64_t nLastSuccess;

//! last try whatsoever by us:
// int64_t CAddress::nLastTry

//! connection attempts since last successful attempt
int nAttempts;

Expand Down Expand Up @@ -232,7 +233,7 @@ class CAddrMan

//! Select an address to connect to.
//! nUnkBias determines how much to favor new addresses over tried ones (min=0, max=100)
CAddress Select_();
CAddrInfo Select_();

#ifdef DEBUG_ADDRMAN
//! Perform consistency check. Returns an error code or zero.
Expand Down Expand Up @@ -534,9 +535,9 @@ class CAddrMan
* Choose an address to connect to.
* nUnkBias determines how much "new" entries are favored over "tried" ones (0-100).
*/
CAddress Select()
CAddrInfo Select()
{
CAddress addrRet;
CAddrInfo addrRet;
{
LOCK(cs);
Check();
Expand Down
2 changes: 1 addition & 1 deletion src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,7 @@ void ThreadOpenConnections()

int nTries = 0;
while (true) {
CAddress addr = addrman.Select();
CAddrInfo addr = addrman.Select();

// if we selected an invalid address, restart
if (!addr.IsValid() || setConnected.count(addr.GetGroup()) || IsLocal(addr))
Expand Down
1 change: 0 additions & 1 deletion src/protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ void CAddress::Init()
{
nServices = NODE_NETWORK;
nTime = 100000000;
nLastTry = 0;
}

CInv::CInv()
Expand Down
3 changes: 0 additions & 3 deletions src/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ class CAddress : public CService

// disk and network only
unsigned int nTime;

// memory only
int64_t nLastTry;
};

/** inv message data */
Expand Down
1 change: 1 addition & 0 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,7 @@ void BitcoinGUI::optionsClicked()

OptionsDialog dlg(this, enableWallet);
dlg.setModel(clientModel->getOptionsModel());
dlg.setCurrentIndex(0);
dlg.exec();
}

Expand Down
5 changes: 5 additions & 0 deletions src/qt/optionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,8 @@ bool OptionsDialog::eventFilter(QObject* object, QEvent* event)
}
return QDialog::eventFilter(object, event);
}

void OptionsDialog::setCurrentIndex(int index)
{
ui->tabWidget->setCurrentIndex(index);
}
1 change: 1 addition & 0 deletions src/qt/optionsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class OptionsDialog : public QDialog

void setModel(OptionsModel* model);
void setMapper();
void setCurrentIndex(int index);

protected:
bool eventFilter(QObject* object, QEvent* event);
Expand Down

0 comments on commit dc05035

Please sign in to comment.