aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2011-07-07 15:22:54 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2011-07-07 15:22:54 +0200
commitae3d0aba158d0a38c33d687e5473d688fbcb903d (patch)
tree33aad906eba0bf0500a24196649651bd8d48dfa4 /src
parentfbaee7a8533b23d846ee16837320f709c4e83d47 (diff)
Sync to bitcoin git e94010b2395694d56dd6
Diffstat (limited to 'src')
-rw-r--r--src/bitcoinrpc.cpp25
-rw-r--r--src/init.cpp4
-rw-r--r--src/keystore.cpp1
-rw-r--r--src/main.cpp19
-rw-r--r--src/net.cpp41
-rw-r--r--src/net.h2
-rw-r--r--src/qt/addresstablemodel.cpp16
-rw-r--r--src/serialize.h2
-rw-r--r--src/util.cpp7
-rw-r--r--src/wallet.cpp101
-rw-r--r--src/wallet.h9
11 files changed, 113 insertions, 114 deletions
diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp
index 644ad92297..0493c6a08f 100644
--- a/src/bitcoinrpc.cpp
+++ b/src/bitcoinrpc.cpp
@@ -13,7 +13,7 @@
#include <boost/iostreams/stream.hpp>
#include <boost/algorithm/string.hpp>
#ifdef USE_SSL
-#include <boost/asio/ssl.hpp>
+#include <boost/asio/ssl.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket> SSLStream;
@@ -332,12 +332,15 @@ Value getnewaddress(const Array& params, bool fHelp)
// Generate a new key that is added to wallet
string strAddress = PubKeyToAddress(pwalletMain->GetKeyFromKeyPool());
- pwalletMain->SetAddressBookName(strAddress, strAccount);
+ // This could be done in the same main CS as GetKeyFromKeyPool.
+ CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook)
+ pwalletMain->SetAddressBookName(strAddress, strAccount);
+
return strAddress;
}
-// requires cs_main, cs_mapWallet locks
+// requires cs_main, cs_mapWallet, cs_mapAddressBook locks
string GetAccountAddress(string strAccount, bool bForceNew=false)
{
string strAddress;
@@ -393,6 +396,7 @@ Value getaccountaddress(const Array& params, bool fHelp)
CRITICAL_BLOCK(cs_main)
CRITICAL_BLOCK(pwalletMain->cs_mapWallet)
+ CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook)
{
ret = GetAccountAddress(strAccount);
}
@@ -431,9 +435,10 @@ Value setaccount(const Array& params, bool fHelp)
if (strAddress == GetAccountAddress(strOldAccount))
GetAccountAddress(strOldAccount, true);
}
+
+ pwalletMain->SetAddressBookName(strAddress, strAccount);
}
- pwalletMain->SetAddressBookName(strAddress, strAccount);
return Value::null;
}
@@ -838,7 +843,7 @@ Value sendmany(const Array& params, bool fHelp)
CScript scriptPubKey;
if (!scriptPubKey.SetBitcoinAddress(strAddress))
throw JSONRPCError(-5, string("Invalid bitcoin address:")+strAddress);
- int64 nAmount = AmountFromValue(s.value_);
+ int64 nAmount = AmountFromValue(s.value_);
totalAmount += nAmount;
vecSend.push_back(make_pair(scriptPubKey, nAmount));
@@ -1156,7 +1161,7 @@ Value listtransactions(const Array& params, bool fHelp)
}
// ret is now newest to oldest
}
-
+
// Make sure we return only last nCount items (sends-to-self might give us an extra):
if (ret.size() > nCount)
{
@@ -1532,7 +1537,7 @@ string rfc1123Time()
return string(buffer);
}
-string HTTPReply(int nStatus, const string& strMsg)
+static string HTTPReply(int nStatus, const string& strMsg)
{
if (nStatus == 401)
return strprintf("HTTP/1.0 401 Authorization Required\r\n"
@@ -1554,6 +1559,7 @@ string HTTPReply(int nStatus, const string& strMsg)
string strStatus;
if (nStatus == 200) strStatus = "OK";
else if (nStatus == 400) strStatus = "Bad Request";
+ else if (nStatus == 403) strStatus = "Forbidden";
else if (nStatus == 404) strStatus = "Not Found";
else if (nStatus == 500) strStatus = "Internal Server Error";
return strprintf(
@@ -1887,7 +1893,12 @@ void ThreadRPCServer2(void* parg)
// Restrict callers by IP
if (!ClientAllowed(peer.address().to_string()))
+ {
+ // Only send a 403 if we're not using SSL to prevent a DoS during the SSL handshake.
+ if (!fUseSSL)
+ stream << HTTPReply(403, "") << std::flush;
continue;
+ }
map<string, string> mapHeaders;
string strRequest;
diff --git a/src/init.cpp b/src/init.cpp
index cac921e2b2..adbfa18c6a 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -493,7 +493,9 @@ bool AppInit2(int argc, char* argv[])
}
}
- if (mapArgs.count("-dnsseed"))
+ if (GetBoolArg("-nodnsseed"))
+ printf("DNS seeding disabled\n");
+ else
DNSAddressSeed();
if (mapArgs.count("-paytxfee"))
diff --git a/src/keystore.cpp b/src/keystore.cpp
index 7dd045fe5f..bfad27c6d3 100644
--- a/src/keystore.cpp
+++ b/src/keystore.cpp
@@ -29,5 +29,6 @@ bool CKeyStore::AddKey(const CKey& key)
mapKeys[key.GetPubKey()] = key.GetPrivKey();
mapPubKeys[Hash160(key.GetPubKey())] = key.GetPubKey();
}
+ return true;
}
diff --git a/src/main.cpp b/src/main.cpp
index 54902e82eb..594f1d3bc4 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -32,8 +32,8 @@ map<COutPoint, CInPoint> mapNextTx;
map<uint256, CBlockIndex*> mapBlockIndex;
uint256 hashGenesisBlock("0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f");
CBigNum bnProofOfWorkLimit(~uint256(0) >> 32);
-const int nTotalBlocksEstimate = 131000; // Conservative estimate of total nr of blocks on main chain
-const int nInitialBlockThreshold = 10000; // Regard blocks up until N-threshold as "initial download"
+const int nTotalBlocksEstimate = 134444; // Conservative estimate of total nr of blocks on main chain
+const int nInitialBlockThreshold = 120; // Regard blocks up until N-threshold as "initial download"
CBlockIndex* pindexGenesisBlock = NULL;
int nBestHeight = -1;
CBigNum bnBestChainWork = 0;
@@ -1294,7 +1294,8 @@ bool CBlock::AcceptBlock()
(nHeight == 70567 && hash != uint256("0x00000000006a49b14bcf27462068f1264c961f11fa2e0eddd2be0791e1d4124a")) ||
(nHeight == 74000 && hash != uint256("0x0000000000573993a3c9e41ce34471c079dcf5f52a0e824a81e7f953b8661a20")) ||
(nHeight == 105000 && hash != uint256("0x00000000000291ce28027faea320c8d2b054b2e0fe44a773f3eefb151d6bdc97")) ||
- (nHeight == 118000 && hash != uint256("0x000000000000774a7f8a7a12dc906ddb9e17e75d684f15e00f8767f9e8f36553")))
+ (nHeight == 118000 && hash != uint256("0x000000000000774a7f8a7a12dc906ddb9e17e75d684f15e00f8767f9e8f36553")) ||
+ (nHeight == 134444 && hash != uint256("0x00000000000005b12ffd4cd315cd34ffd4a594f430ac814c91184a0d42d2b0fe")))
return error("AcceptBlock() : rejected by checkpoint lockin at %d", nHeight);
// Write block to history file
@@ -1311,7 +1312,7 @@ bool CBlock::AcceptBlock()
if (hashBestChain == hash)
CRITICAL_BLOCK(cs_vNodes)
BOOST_FOREACH(CNode* pnode, vNodes)
- if (nBestHeight > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : 118000))
+ if (nBestHeight > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : 134444))
pnode->PushInventory(CInv(MSG_BLOCK, hash));
return true;
@@ -2040,20 +2041,24 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
if (pindex)
pindex = pindex->pnext;
int nLimit = 500 + locator.GetDistanceBack();
+ unsigned int nBytes = 0;
printf("getblocks %d to %s limit %d\n", (pindex ? pindex->nHeight : -1), hashStop.ToString().substr(0,20).c_str(), nLimit);
for (; pindex; pindex = pindex->pnext)
{
if (pindex->GetBlockHash() == hashStop)
{
- printf(" getblocks stopping at %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString().substr(0,20).c_str());
+ printf(" getblocks stopping at %d %s (%u bytes)\n", pindex->nHeight, pindex->GetBlockHash().ToString().substr(0,20).c_str(), nBytes);
break;
}
pfrom->PushInventory(CInv(MSG_BLOCK, pindex->GetBlockHash()));
- if (--nLimit <= 0)
+ CBlock block;
+ block.ReadFromDisk(pindex, true);
+ nBytes += block.GetSerializeSize(SER_NETWORK);
+ if (--nLimit <= 0 || nBytes >= SendBufferSize()/2)
{
// When this block is requested, we'll send an inv that'll make them
// getblocks the next batch of inventory.
- printf(" getblocks stopping at limit %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString().substr(0,20).c_str());
+ printf(" getblocks stopping at limit %d %s (%u bytes)\n", pindex->nHeight, pindex->GetBlockHash().ToString().substr(0,20).c_str(), nBytes);
pfrom->hashContinue = pindex->GetBlockHash();
break;
}
diff --git a/src/net.cpp b/src/net.cpp
index 4b13726230..0d3348da72 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -9,6 +9,15 @@
#include "init.h"
#include "strlcpy.h"
+#ifdef __WXMSW__
+#include <string.h>
+// This file can be downloaded as a part of the Windows Platform SDK
+// and is required for Bitcoin binaries to work properly on versions
+// of Windows before XP. If you are doing builds of Bitcoin for
+// public release, you should uncomment this line.
+//#include <WSPiApi.h>
+#endif
+
#ifdef USE_UPNP
#include <miniupnpc/miniwget.h>
#include <miniupnpc/miniupnpc.h>
@@ -148,7 +157,7 @@ bool ConnectSocket(const CAddress& addrConnect, SOCKET& hSocketRet, int nTimeout
}
if (nRet != 0)
{
- printf("connect() failed after select(): %i\n",nRet);
+ printf("connect() failed after select(): %s\n",strerror(nRet));
closesocket(hSocket);
return false;
}
@@ -159,7 +168,7 @@ bool ConnectSocket(const CAddress& addrConnect, SOCKET& hSocketRet, int nTimeout
else
#endif
{
- printf("connect() failed: %s\n",WSAGetLastError());
+ printf("connect() failed: %i\n",WSAGetLastError());
closesocket(hSocket);
return false;
}
@@ -915,7 +924,7 @@ void ThreadSocketHandler2(void* parg)
CDataStream& vRecv = pnode->vRecv;
unsigned int nPos = vRecv.size();
- if (nPos > 1000*GetArg("-maxreceivebuffer", 10*1000)) {
+ if (nPos > ReceiveBufferSize()) {
if (!pnode->fDisconnect)
printf("socket recv flood control disconnect (%d bytes)\n", vRecv.size());
pnode->CloseSocketDisconnect();
@@ -980,7 +989,7 @@ void ThreadSocketHandler2(void* parg)
pnode->CloseSocketDisconnect();
}
}
- if (vSend.size() > 1000*GetArg("-maxsendbuffer", 10*1000)) {
+ if (vSend.size() > SendBufferSize()) {
if (!pnode->fDisconnect)
printf("socket send flood control disconnect (%d bytes)\n", vSend.size());
pnode->CloseSocketDisconnect();
@@ -1139,25 +1148,29 @@ void MapPort(bool fMapPort)
static const char *strDNSSeed[] = {
"bitseed.xf2.org",
"bitseed.bitcoin.org.uk",
+ "dnsseed.bluematt.me",
};
void DNSAddressSeed()
{
int found = 0;
- printf("Loading addresses from DNS seeds (could take a while)\n");
+ if (!fTestNet)
+ {
+ printf("Loading addresses from DNS seeds (could take a while)\n");
- for (int seed_idx = 0; seed_idx < ARRAYLEN(strDNSSeed); seed_idx++) {
- vector<CAddress> vaddr;
- if (Lookup(strDNSSeed[seed_idx], vaddr, NODE_NETWORK, -1, true))
- {
- BOOST_FOREACH (CAddress& addr, vaddr)
+ for (int seed_idx = 0; seed_idx < ARRAYLEN(strDNSSeed); seed_idx++) {
+ vector<CAddress> vaddr;
+ if (Lookup(strDNSSeed[seed_idx], vaddr, NODE_NETWORK, -1, true))
{
- if (addr.GetByte(3) != 127)
+ BOOST_FOREACH (CAddress& addr, vaddr)
{
- addr.nTime = 0;
- AddAddress(addr);
- found++;
+ if (addr.GetByte(3) != 127)
+ {
+ addr.nTime = 0;
+ AddAddress(addr);
+ found++;
+ }
}
}
}
diff --git a/src/net.h b/src/net.h
index cafb175d94..8f21de8dc9 100644
--- a/src/net.h
+++ b/src/net.h
@@ -24,6 +24,8 @@ extern int nConnectTimeout;
+inline unsigned int ReceiveBufferSize() { return 1000*GetArg("-maxreceivebuffer", 10*1000); }
+inline unsigned int SendBufferSize() { return 1000*GetArg("-maxsendbuffer", 10*1000); }
inline unsigned short GetDefaultPort() { return fTestNet ? 18333 : 8333; }
static const unsigned int PUBLISH_HOPS = 5;
enum
diff --git a/src/qt/addresstablemodel.cpp b/src/qt/addresstablemodel.cpp
index e375ff8cbc..d04989ea2e 100644
--- a/src/qt/addresstablemodel.cpp
+++ b/src/qt/addresstablemodel.cpp
@@ -165,10 +165,13 @@ bool AddressTableModel::setData(const QModelIndex & index, const QVariant & valu
// Double-check that we're not overwriting receiving address
if(rec->type == AddressTableEntry::Sending)
{
- // Remove old entry
- wallet->EraseAddressBookName(rec->address.toStdString());
- // Add new entry with new address
- wallet->SetAddressBookName(value.toString().toStdString(), rec->label.toStdString());
+ CRITICAL_BLOCK(wallet->cs_mapAddressBook)
+ {
+ // Remove old entry
+ wallet->DelAddressBookName(rec->address.toStdString());
+ // Add new entry with new address
+ wallet->SetAddressBookName(value.toString().toStdString(), rec->label.toStdString());
+ }
rec->address = value.toString();
}
@@ -274,7 +277,10 @@ bool AddressTableModel::removeRows(int row, int count, const QModelIndex & paren
// Also refuse to remove receiving addresses.
return false;
}
- wallet->EraseAddressBookName(rec->address.toStdString());
+ CRITICAL_BLOCK(wallet->cs_mapAddressBook)
+ {
+ wallet->DelAddressBookName(rec->address.toStdString());
+ }
updateList();
return true;
}
diff --git a/src/serialize.h b/src/serialize.h
index 0d66d6a956..31862a71a9 100644
--- a/src/serialize.h
+++ b/src/serialize.h
@@ -33,7 +33,7 @@ class CDataStream;
class CAutoFile;
static const unsigned int MAX_SIZE = 0x02000000;
-static const int VERSION = 32300;
+static const int VERSION = 32400;
static const char* pszSubVer = "";
static const bool VERSION_IS_BETA = true;
diff --git a/src/util.cpp b/src/util.cpp
index 2bc2cdd599..3d89f6a829 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -344,11 +344,6 @@ string FormatMoney(int64 n, bool fPlus)
if (nTrim)
str.erase(str.size()-nTrim, nTrim);
- // Insert thousands-separators:
- size_t point = str.find(".");
- for (int i = (str.size()-point)+3; i < str.size(); i += 4)
- if (isdigit(str[str.size() - i - 1]))
- str.insert(str.size() - i, 1, ',');
if (n < 0)
str.insert((unsigned int)0, 1, '-');
else if (fPlus && n > 0)
@@ -371,8 +366,6 @@ bool ParseMoney(const char* pszIn, int64& nRet)
p++;
for (; *p; p++)
{
- if (*p == ',' && p > pszIn && isdigit(p[-1]) && isdigit(p[1]) && isdigit(p[2]) && isdigit(p[3]) && !isdigit(p[4]))
- continue;
if (*p == '.')
{
p++;
diff --git a/src/wallet.cpp b/src/wallet.cpp
index f896336773..5b88f387c7 100644
--- a/src/wallet.cpp
+++ b/src/wallet.cpp
@@ -98,14 +98,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn)
BOOST_FOREACH(const CTxOut& txout, wtx.vout)
{
if (txout.scriptPubKey == scriptDefaultKey)
- {
- if (!fFileBacked)
- continue;
- CWalletDB walletdb(strWalletFile);
- vchDefaultKey = GetKeyFromKeyPool();
- walletdb.WriteDefaultKey(vchDefaultKey);
- walletdb.WriteName(PubKeyToAddress(vchDefaultKey), "");
- }
+ SetDefaultKey(GetKeyFromKeyPool());
}
#endif
// Notify UI
@@ -967,16 +960,33 @@ bool CWallet::LoadWallet(bool& fFirstRunRet)
// Create new default key
RandAddSeedPerfmon();
- vchDefaultKey = GetKeyFromKeyPool();
+ SetDefaultKey(GetKeyFromKeyPool());
if (!SetAddressBookName(PubKeyToAddress(vchDefaultKey), ""))
return false;
- CWalletDB(strWalletFile).WriteDefaultKey(vchDefaultKey);
}
CreateThread(ThreadFlushWalletDB, &strWalletFile);
return true;
}
+
+bool CWallet::SetAddressBookName(const string& strAddress, const string& strName)
+{
+ mapAddressBook[strAddress] = strName;
+ if (!fFileBacked)
+ return false;
+ return CWalletDB(strWalletFile).WriteName(strAddress, strName);
+}
+
+bool CWallet::DelAddressBookName(const string& strAddress)
+{
+ mapAddressBook.erase(strAddress);
+ if (!fFileBacked)
+ return false;
+ return CWalletDB(strWalletFile).EraseName(strAddress);
+}
+
+
void CWallet::PrintWallet(const CBlock& block)
{
CRITICAL_BLOCK(cs_mapWallet)
@@ -1004,6 +1014,17 @@ bool CWallet::GetTransaction(const uint256 &hashTx, CWalletTx& wtx)
return false;
}
+bool CWallet::SetDefaultKey(const std::vector<unsigned char> &vchPubKey)
+{
+ if (fFileBacked)
+ {
+ if (!CWalletDB(strWalletFile).WriteDefaultKey(vchPubKey))
+ return false;
+ }
+ vchDefaultKey = vchPubKey;
+ return true;
+}
+
bool GetWalletFile(CWallet* pwallet, string &strWalletFileOut)
{
if (!pwallet->fFileBacked)
@@ -1070,65 +1091,6 @@ void CWallet::ReturnKey(int64 nIndex)
printf("keypool return %"PRI64d"\n", nIndex);
}
-bool CWallet::SetAddressBookName(const std::string& strAddress, const std::string& strName)
-{
- if (!fFileBacked)
- return false;
- if(CWalletDB(strWalletFile).WriteName(strAddress, strName))
- {
- CRITICAL_BLOCK(cs_mapAddressBook)
- mapAddressBook[strAddress] = strName;
- return true;
- }
- else
- {
- return false;
- }
-}
-
-bool CWallet::EraseAddressBookName(const std::string& strAddress)
-{
- if (!fFileBacked)
- return false;
- if(CWalletDB(strWalletFile).EraseName(strAddress))
- {
- CRITICAL_BLOCK(cs_mapAddressBook)
- mapAddressBook.erase(strAddress);
- return true;
- }
- else
- {
- return false;
- }
-}
-
-
-std::string CWallet::GetDefaultAddress()
-{
- if (!fFileBacked)
- return false;
- std::vector<unsigned char> vchPubKey;
- if (CWalletDB(strWalletFile, "r").ReadDefaultKey(vchPubKey))
- {
- return PubKeyToAddress(vchPubKey);
- }
- else
- {
- return "";
- }
-}
-
-bool CWallet::SetDefaultAddress(const std::string& strAddress)
-{
- uint160 hash160;
- if (!AddressToHash160(strAddress, hash160))
- return false;
- if (!mapPubKeys.count(hash160))
- return false;
- return CWalletDB(strWalletFile).WriteDefaultKey(mapPubKeys[hash160]);
-}
-
-
vector<unsigned char> CWallet::GetKeyFromKeyPool()
{
int64 nIndex = 0;
@@ -1174,3 +1136,4 @@ void CReserveKey::ReturnKey()
nIndex = -1;
vchPubKey.clear();
}
+
diff --git a/src/wallet.h b/src/wallet.h
index 69110a4afa..7d9db97267 100644
--- a/src/wallet.h
+++ b/src/wallet.h
@@ -149,10 +149,12 @@ public:
bool LoadWallet(bool& fFirstRunRet);
// bool BackupWallet(const std::string& strDest);
+
+ // requires cs_mapAddressBook lock
bool SetAddressBookName(const std::string& strAddress, const std::string& strName);
- bool EraseAddressBookName(const std::string& strAddress);
- std::string GetDefaultAddress();
- bool SetDefaultAddress(const std::string& strAddress);
+
+ // requires cs_mapAddressBook lock
+ bool DelAddressBookName(const std::string& strAddress);
void UpdatedTransaction(const uint256 &hashTx)
{
@@ -174,6 +176,7 @@ public:
bool GetTransaction(const uint256 &hashTx, CWalletTx& wtx);
+ bool SetDefaultKey(const std::vector<unsigned char> &vchPubKey);
};