#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;
// 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;
CRITICAL_BLOCK(cs_main)
CRITICAL_BLOCK(pwalletMain->cs_mapWallet)
+ CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook)
{
ret = GetAccountAddress(strAccount);
}
if (strAddress == GetAccountAddress(strOldAccount))
GetAccountAddress(strOldAccount, true);
}
+
+ pwalletMain->SetAddressBookName(strAddress, strAccount);
}
- pwalletMain->SetAddressBookName(strAddress, strAccount);
return Value::null;
}
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));
}
// 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)
{
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"
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(
// 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;