Skip to content

Commit

Permalink
addr relaying fixes, proxy option and privacy patches, detect connect…
Browse files Browse the repository at this point in the history
… to self, non-final tx locktime changes, fix hide unconfirmed generated
  • Loading branch information
non-github-bitcoin committed Oct 29, 2009
1 parent 6ccefea commit cc0b4c3
Show file tree
Hide file tree
Showing 19 changed files with 1,209 additions and 339 deletions.
12 changes: 6 additions & 6 deletions build.txt
@@ -1,4 +1,4 @@
BitCoin v0.1.6 ALPHA
BitCoin v0.1.6 BETA

Copyright (c) 2009 Satoshi Nakamoto
Distributed under the MIT/X11 software license, see the accompanying
Expand All @@ -19,10 +19,10 @@ Dependencies
Libraries you need to obtain separately to build:

default path download
wxWidgets \wxWidgets http://www.wxwidgets.org/downloads/
OpenSSL \OpenSSL http://www.openssl.org/source/
Berkeley DB \DB http://www.oracle.com/technology/software/products/berkeley-db/index.html
Boost \Boost http://www.boost.org/users/download/
wxWidgets \wxwidgets http://www.wxwidgets.org/downloads/
OpenSSL \openssl http://www.openssl.org/source/
Berkeley DB \db http://www.oracle.com/technology/software/products/berkeley-db/index.html
Boost \boost http://www.boost.org/users/download/

Their licenses:
wxWidgets LGPL 2.1 with very liberal exceptions
Expand Down Expand Up @@ -75,7 +75,7 @@ If you want to use it with MSVC, generate the .lib file
Berkeley DB
-----------
Using MinGW and MSYS:
cd \DB\build_unix
cd \db\build_unix
sh ../dist/configure --enable-mingw --enable-cxx
make

Expand Down
19 changes: 13 additions & 6 deletions db.cpp
Expand Up @@ -121,10 +121,12 @@ void CDB::Close()
pdb->close(0);
delete pdb;
pdb = NULL;
dbenv.txn_checkpoint(0, 0, 0);

CRITICAL_BLOCK(cs_db)
{
dbenv.txn_checkpoint(0, 0, 0);
--mapFileUseCount[strFile];
}

RandAddSeed();
}
Expand Down Expand Up @@ -376,11 +378,11 @@ bool CTxDB::LoadBlockIndex()
{
if (pindexGenesisBlock == NULL)
return true;
return error("CTxDB::LoadBlockIndex() : hashBestChain not found\n");
return error("CTxDB::LoadBlockIndex() : hashBestChain not found");
}

if (!mapBlockIndex.count(hashBestChain))
return error("CTxDB::LoadBlockIndex() : blockindex for hashBestChain not found\n");
return error("CTxDB::LoadBlockIndex() : blockindex for hashBestChain not found");
pindexBest = mapBlockIndex[hashBestChain];
nBestHeight = pindexBest->nHeight;
printf("LoadBlockIndex(): hashBestChain=%s height=%d\n", hashBestChain.ToString().substr(0,14).c_str(), nBestHeight);
Expand Down Expand Up @@ -500,16 +502,15 @@ bool CReviewDB::WriteReviews(uint256 hash, const vector<CReview>& vReviews)
CWalletDB::~CWalletDB()
{
// Flush whenever all handles to wallet.dat are closed
Close();
CRITICAL_BLOCK(cs_db)
{
Close(); // close includes a txn_checkpoint
map<string, int>::iterator mi = mapFileUseCount.find(strFile);
if (mi != mapFileUseCount.end())
{
int nRefCount = (*mi).second;
if (nRefCount == 0)
{
dbenv.txn_checkpoint(0, 0, 0);
dbenv.lsn_reset(strFile.c_str(), 0);
mapFileUseCount.erase(mi++);
}
Expand Down Expand Up @@ -600,6 +601,9 @@ bool CWalletDB::LoadWallet(vector<unsigned char>& vchDefaultKeyRet)
if (strKey == "nLimitProcessors") ssValue >> nLimitProcessors;
if (strKey == "fMinimizeToTray") ssValue >> fMinimizeToTray;
if (strKey == "fMinimizeOnClose") ssValue >> fMinimizeOnClose;
if (strKey == "fUseProxy") ssValue >> fUseProxy;
if (strKey == "addrProxy") ssValue >> addrProxy;

}
}
}
Expand All @@ -610,6 +614,9 @@ bool CWalletDB::LoadWallet(vector<unsigned char>& vchDefaultKeyRet)
printf("addrIncoming = %s\n", addrIncoming.ToString().c_str());
printf("fMinimizeToTray = %d\n", fMinimizeToTray);
printf("fMinimizeOnClose = %d\n", fMinimizeOnClose);
printf("fUseProxy = %d\n", fUseProxy);
printf("addrProxy = %s\n", addrProxy.ToString().c_str());


// The transaction fee setting won't be needed for many years to come.
// Setting it to zero here in case they set it to something in an earlier version.
Expand Down Expand Up @@ -639,7 +646,7 @@ bool LoadWallet(bool& fFirstRunRet)
else
{
// Create new keyUser and set as default key
RandAddSeed(true);
RandAddSeedPerfmon();
keyUser.MakeNewKey();
if (!AddKey(keyUser))
return false;
Expand Down
2 changes: 2 additions & 0 deletions headers.h
Expand Up @@ -5,6 +5,7 @@
#ifdef _MSC_VER
#pragma warning(disable:4786)
#pragma warning(disable:4804)
#pragma warning(disable:4805)
#pragma warning(disable:4717)
#endif
#ifdef _WIN32_WINNT
Expand Down Expand Up @@ -62,6 +63,7 @@ using namespace boost;



#include "strlcpy.h"
#include "serialize.h"
#include "uint256.h"
#include "util.h"
Expand Down
10 changes: 7 additions & 3 deletions irc.cpp
Expand Up @@ -163,6 +163,9 @@ void ThreadIRCSeed(void* parg)
int nErrorWait = 10;
int nRetryWait = 10;

if (fUseProxy && addrProxy.port == htons(9050))
return;

while (!fShutdown)
{
CAddress addrConnect("216.155.130.130:6667");
Expand Down Expand Up @@ -191,9 +194,10 @@ void ThreadIRCSeed(void* parg)
return;
}

string strMyName = EncodeAddress(addrLocalHost);

if (!addrLocalHost.IsRoutable())
string strMyName;
if (addrLocalHost.IsRoutable() && !fUseProxy)
strMyName = EncodeAddress(addrLocalHost);
else
strMyName = strprintf("x%u", GetRand(1000000000));


Expand Down
2 changes: 1 addition & 1 deletion key.h
Expand Up @@ -35,7 +35,7 @@ class key_error : public std::runtime_error
};


// secure_allocator is defined is serialize.h
// secure_allocator is defined in serialize.h
typedef vector<unsigned char, secure_allocator<unsigned char> > CPrivKey;


Expand Down
71 changes: 57 additions & 14 deletions main.cpp
Expand Up @@ -415,6 +415,10 @@ bool CTransaction::AcceptTransaction(CTxDB& txdb, bool fCheckInputs, bool* pfMis
if (!CheckTransaction())
return error("AcceptTransaction() : CheckTransaction failed");

// To help v0.1.5 clients who would see it as negative number. please delete this later.
if (nLockTime > INT_MAX)
return error("AcceptTransaction() : not accepting nLockTime beyond 2038");

// Do we already have it?
uint256 hash = GetHash();
CRITICAL_BLOCK(cs_mapTransactions)
Expand Down Expand Up @@ -1214,6 +1218,12 @@ bool CBlock::AcceptBlock()
if (nTime <= pindexPrev->GetMedianTimePast())
return error("AcceptBlock() : block's timestamp is too early");

// Check that all transactions are finalized (starting around 30 Nov 2009)
if (nBestHeight > 31000) // 25620 + 5320
foreach(const CTransaction& tx, vtx)
if (!tx.IsFinal(nTime))
return error("AcceptBlock() : contains a non-final transaction");

// Check proof of work
if (nBits != GetNextWorkRequired(pindexPrev))
return error("AcceptBlock() : incorrect proof of work");
Expand Down Expand Up @@ -1649,7 +1659,7 @@ bool ProcessMessages(CNode* pfrom)
CDataStream& vRecv = pfrom->vRecv;
if (vRecv.empty())
return true;
printf("ProcessMessages(%d bytes)\n", vRecv.size());
//printf("ProcessMessages(%d bytes)\n", vRecv.size());

//
// Message format
Expand Down Expand Up @@ -1692,7 +1702,7 @@ bool ProcessMessages(CNode* pfrom)
{
// Rewind and wait for rest of message
///// need a mechanism to give up waiting for overlong message size error
printf("MESSAGE-BREAK\n");
//printf("message-break\n");
vRecv.insert(vRecv.begin(), BEGIN(hdr), END(hdr));
Sleep(100);
break;
Expand All @@ -1711,7 +1721,20 @@ bool ProcessMessages(CNode* pfrom)
fRet = ProcessMessage(pfrom, strCommand, vMsg);
CheckForShutdown(2);
}
CATCH_PRINT_EXCEPTION("ProcessMessage()")
catch (std::ios_base::failure& e) {
if (strstr(e.what(), "CDataStream::read() : end of data"))
{
// Allow exceptions from underlength message on vRecv
LogException(&e, "ProcessMessage()");
}
else
PrintException(&e, "ProcessMessage()");
} catch (std::exception& e) {
PrintException(&e, "ProcessMessage()");
} catch (...) {
PrintException(NULL, "ProcessMessage()");
}

if (!fRet)
printf("ProcessMessage(%s, %d bytes) FAILED\n", strCommand.c_str(), nMessageSize);
}
Expand All @@ -1726,7 +1749,8 @@ bool ProcessMessages(CNode* pfrom)
bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
{
static map<unsigned int, vector<unsigned char> > mapReuseKey;
printf("received: %-12s (%d bytes)\n", strCommand.c_str(), vRecv.size());
RandAddSeedPerfmon();
printf("received: %s (%d bytes)\n", strCommand.c_str(), vRecv.size());
if (nDropMessagesTest > 0 && GetRand(nDropMessagesTest) == 0)
{
printf("dropmessages DROPPING RECV MESSAGE\n");
Expand All @@ -1735,18 +1759,32 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)




if (strCommand == "version")
{
// Can only do this once
// Each connection can only send one version message
if (pfrom->nVersion != 0)
return false;

int64 nTime;
CAddress addrMe;
CAddress addrFrom;
uint64 nNonce = 1;
vRecv >> pfrom->nVersion >> pfrom->nServices >> nTime >> addrMe;
if (pfrom->nVersion >= 106 && !vRecv.empty())
vRecv >> addrFrom >> nNonce;
if (pfrom->nVersion == 0)
return false;

// Disconnect if we connected to ourself
if (nNonce == nLocalHostNonce)
{
pfrom->fDisconnect = true;
pfrom->vRecv.clear();
pfrom->vSend.clear();
return true;
}

pfrom->vSend.SetVersion(min(pfrom->nVersion, VERSION));
pfrom->vRecv.SetVersion(min(pfrom->nVersion, VERSION));

Expand All @@ -1767,6 +1805,8 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
pfrom->PushMessage("getblocks", CBlockLocator(pindexBest), uint256(0));
}

pfrom->fSuccessfullyConnected = true;

printf("version message: version %d\n", pfrom->nVersion);
}

Expand Down Expand Up @@ -1800,16 +1840,16 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
if (fShutdown)
return true;
AddAddress(addrdb, addr);
if (addr.IsRoutable() && addr.ip != addrLocalHost.ip)
pfrom->AddAddressKnown(addr);
if (!pfrom->fGetAddr && addr.IsRoutable())
{
// Put on lists to send to other nodes
pfrom->setAddrKnown.insert(addr);
CRITICAL_BLOCK(cs_vNodes)
foreach(CNode* pnode, vNodes)
if (!pnode->setAddrKnown.count(addr))
pnode->vAddrToSend.push_back(addr);
pnode->PushAddress(addr);
}
}
pfrom->fGetAddr = false;
}


Expand Down Expand Up @@ -2009,7 +2049,7 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
return true;
const CAddress& addr = item.second;
if (addr.nTime > nSince)
pfrom->vAddrToSend.push_back(addr);
pfrom->PushAddress(addr);
}
}
}
Expand Down Expand Up @@ -2108,8 +2148,11 @@ bool SendMessages(CNode* pto)
vector<CAddress> vAddrToSend;
vAddrToSend.reserve(pto->vAddrToSend.size());
foreach(const CAddress& addr, pto->vAddrToSend)
if (!pto->setAddrKnown.count(addr))
{
// returns true if wasn't already contained in the set
if (pto->setAddrKnown.insert(addr).second)
vAddrToSend.push_back(addr);
}
pto->vAddrToSend.clear();
if (!vAddrToSend.empty())
pto->PushMessage("addr", vAddrToSend);
Expand Down Expand Up @@ -2193,7 +2236,7 @@ void GenerateBitcoins(bool fGenerate)
if (fLimitProcessors && nProcessors > nLimitProcessors)
nProcessors = nLimitProcessors;
int nAddThreads = nProcessors - vnThreadsRunning[3];
printf("starting %d bitcoinminer threads\n", nAddThreads);
printf("Starting %d BitcoinMiner threads\n", nAddThreads);
for (int i = 0; i < nAddThreads; i++)
if (_beginthread(ThreadBitcoinMiner, 0, NULL) == -1)
printf("Error: _beginthread(ThreadBitcoinMiner) failed\n");
Expand All @@ -2207,7 +2250,7 @@ void ThreadBitcoinMiner(void* parg)
try
{
bool fRet = BitcoinMiner();
printf("BitcoinMiner returned %s\n\n\n", fRet ? "true" : "false");
printf("BitcoinMiner returned %s\n", fRet ? "true" : "false");
vnThreadsRunning[3]--;
}
catch (std::exception& e) {
Expand Down Expand Up @@ -2737,7 +2780,7 @@ bool SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew)
else
strError = "Error: Transaction creation failed ";
wxMessageBox(strError, "Sending...");
return error("SendMoney() : %s\n", strError.c_str());
return error("SendMoney() : %s", strError.c_str());
}
if (!CommitTransactionSpent(wtxNew, key))
{
Expand Down
16 changes: 12 additions & 4 deletions main.h
Expand Up @@ -366,7 +366,7 @@ class CTransaction
int nVersion;
vector<CTxIn> vin;
vector<CTxOut> vout;
int nLockTime;
unsigned int nLockTime;


CTransaction()
Expand Down Expand Up @@ -401,9 +401,15 @@ class CTransaction
return SerializeHash(*this);
}

bool IsFinal() const
bool IsFinal(int64 nBlockTime=0) const
{
if (nLockTime == 0 || nLockTime < nBestHeight)
// Time based nLockTime implemented in 0.1.6,
// do not use time based until most 0.1.5 nodes have upgraded.
if (nBlockTime == 0)
nBlockTime = GetAdjustedTime();
if (nLockTime == 0)
return true;
if (nLockTime < (nLockTime < 500000000 ? nBestHeight : nBlockTime))
return true;
foreach(const CTxIn& txin, vin)
if (!txin.IsFinal())
Expand Down Expand Up @@ -686,8 +692,9 @@ class CWalletTx : public CMerkleTx
char fSpent;
//// probably need to sign the order info so know it came from payer

// memory only
// memory only UI hints
mutable unsigned int nTimeDisplayed;
mutable int nLinesDisplayed;


CWalletTx()
Expand All @@ -712,6 +719,7 @@ class CWalletTx : public CMerkleTx
fFromMe = false;
fSpent = false;
nTimeDisplayed = 0;
nLinesDisplayed = 0;
}

IMPLEMENT_SERIALIZE
Expand Down
4 changes: 2 additions & 2 deletions makefile
Expand Up @@ -17,8 +17,8 @@ endif



INCLUDEPATHS=-I"/boost" -I"/DB/build_unix" -I"/OpenSSL/include" -I"/wxWidgets/lib/vc_lib/mswd" -I"/wxWidgets/include"
LIBPATHS=-L"/DB/build_unix" -L"/OpenSSL/out" -L"/wxWidgets/lib/gcc_lib"
INCLUDEPATHS=-I"/boost" -I"/db/build_unix" -I"/openssl/include" -I"/wxwidgets/lib/vc_lib/mswd" -I"/wxwidgets/include"
LIBPATHS=-L"/db/build_unix" -L"/openssl/out" -L"/wxwidgets/lib/gcc_lib"
LIBS= \
-l db_cxx \
-l eay32 \
Expand Down

0 comments on commit cc0b4c3

Please sign in to comment.