Permalink
Browse files

first

  • Loading branch information...
jedmccaleb committed Oct 14, 2011
0 parents commit a8e8613475f178f779fd2800c38175615c118a13
Showing with 25,368 additions and 0 deletions.
  1. +57 −0 Application.cpp
  2. +47 −0 Application.h
  3. +102 −0 BitcoinUtil.cpp
  4. +103 −0 BitcoinUtil.h
  5. +174 −0 CallRPC.cpp
  6. +4 −0 CallRPC.h
  7. +50 −0 Config.cpp
  8. +32 −0 Config.h
  9. +48 −0 ConnectionPool.cpp
  10. +21 −0 ConnectionPool.h
  11. BIN Debug/newcoin.exe.embed.manifest.res
  12. BIN Debug/newcoin_manifest.rc
  13. +241 −0 HttpReply.cpp
  14. +50 −0 HttpReply.h
  15. +24 −0 HttpRequest.h
  16. +38 −0 KnownNodeList.cpp
  17. +30 −0 KnownNodeList.h
  18. +204 −0 Ledger.cpp
  19. +53 −0 Ledger.h
  20. +39 −0 LedgerHistory.cpp
  21. +21 −0 LedgerHistory.h
  22. +186 −0 LedgerMaster.cpp
  23. +51 −0 LedgerMaster.h
  24. +9 −0 NetworkThread.h
  25. +67 −0 NewcoinAddress.cpp
  26. +26 −0 NewcoinAddress.h
  27. +56 −0 PackedMessage.cpp
  28. +74 −0 PackedMessage.h
  29. +330 −0 Peer.cpp
  30. +90 −0 Peer.h
  31. +34 −0 PeerDoor.cpp
  32. +16 −0 PeerDoor.h
  33. +28 −0 RPC.h
  34. 0 RPCCommands.cpp
  35. +6 −0 RPCCommands.h
  36. +48 −0 RPCDoor.cpp
  37. +18 −0 RPCDoor.h
  38. +139 −0 RPCServer.cpp
  39. +45 −0 RPCServer.h
  40. +330 −0 RequestParser.cpp
  41. +72 −0 RequestParser.h
  42. +43 −0 SecureAllocator.h
  43. +46 −0 TimingService.cpp
  44. +24 −0 TimingService.h
  45. +17 −0 Transaction.h
  46. +139 −0 TransactionBundle.cpp
  47. +41 −0 TransactionBundle.h
  48. +7 −0 UniqueNodeList.cpp
  49. +16 −0 UniqueNodeList.h
  50. +29 −0 ValidationCollection.cpp
  51. +17 −0 ValidationCollection.h
  52. +133 −0 Wallet.cpp
  53. +44 −0 Wallet.h
  54. +245 −0 base58.h
  55. +538 −0 bignum.h
  56. +5 −0 config.xml
  57. +67 −0 cryptopp/License.txt
  58. +429 −0 cryptopp/Readme.txt
  59. +462 −0 cryptopp/config.h
  60. +199 −0 cryptopp/cpu.cpp
  61. +263 −0 cryptopp/cpu.h
  62. +1,668 −0 cryptopp/cryptlib.h
  63. +29 −0 cryptopp/iterhash.h
  64. +1,134 −0 cryptopp/misc.h
  65. +21 −0 cryptopp/pch.h
  66. +501 −0 cryptopp/secblock.h
  67. +899 −0 cryptopp/sha.cpp
  68. +63 −0 cryptopp/sha.h
  69. +1 −0 cryptopp/simple.h
  70. +223 −0 cryptopp/smartptr.h
  71. +27 −0 cryptopp/stdcpp.h
  72. +2 −0 debug test.bat
  73. +24 −0 json/LICENSE.txt
  74. +18 −0 json/json_spirit.h
  75. +54 −0 json/json_spirit_error_position.h
  76. +137 −0 json/json_spirit_reader.cpp
  77. +62 −0 json/json_spirit_reader.h
  78. +612 −0 json/json_spirit_reader_template.h
  79. +70 −0 json/json_spirit_stream_reader.h
  80. +61 −0 json/json_spirit_utils.h
  81. +8 −0 json/json_spirit_value.cpp
  82. +534 −0 json/json_spirit_value.h
  83. +95 −0 json/json_spirit_writer.cpp
  84. +50 −0 json/json_spirit_writer.h
  85. +248 −0 json/json_spirit_writer_template.h
  86. +241 −0 key.h
  87. +36 −0 keystore.cpp
  88. +58 −0 keystore.h
  89. +49 −0 main.cpp
  90. +98 −0 newcoin.proto
  91. +59 −0 newcoin.sln
  92. +197 −0 newcoin.vcxproj
  93. +3 −0 nodes.xml
  94. +60 −0 notes.txt
  95. +280 −0 rpc.cpp
  96. +403 −0 script.h
  97. +5 −0 tests/client1/config.xml
  98. +4 −0 tests/client1/nodes.xml
  99. +9 −0 tests/client1/unl.xml
  100. +7 −0 tests/client1/wallet.xml
  101. +6 −0 tests/client2/config.xml
  102. +4 −0 tests/client2/nodes.xml
  103. +9 −0 tests/client2/unl.xml
  104. +7 −0 tests/client2/wallet.xml
  105. +4 −0 tests/setup.bat
  106. +10 −0 types.h
  107. +766 −0 uint256.h
  108. +9 −0 unl.xml
  109. +62 −0 util/pugiconfig.hpp
  110. +9,576 −0 util/pugixml.cpp
  111. +1,131 −0 util/pugixml.hpp
  112. +7 −0 wallet.xml
@@ -0,0 +1,57 @@
#include "Application.h"
#include "Config.h"
#include "PeerDoor.h"
#include "RPCDoor.h"
//#include <boost/log/trivial.hpp>
#include <iostream>
using namespace std;

Application* theApp=NULL;

/*
What needs to happen:
Listen for connections
Try to maintain the right number of connections
Process messages from peers
Process messages from RPC
Periodically publish a new ledger
Save the various pieces of data
*/

Application::Application()
{
theConfig.load();
mKnownNodes.load();
mUNL.load();
mWallet.load();
mLedgerMaster.load();
mPeerDoor=NULL;
mRPCDoor=NULL;
}


void Application::run()
{
if(theConfig.PEER_PORT)
{
mPeerDoor=new PeerDoor(mIOService);
}//else BOOST_LOG_TRIVIAL(info) << "No Peer Port set. Not listening for connections.";

if(theConfig.RPC_PORT)
{
mRPCDoor=new RPCDoor(mIOService);
}//else BOOST_LOG_TRIVIAL(info) << "No RPC Port set. Not listening for commands.";

mConnectionPool.connectToNetwork(mKnownNodes,mIOService);
mTimingService.start(mIOService);
cout << "Before Run." << endl;
mIOService.run();// This blocks

//BOOST_LOG_TRIVIAL(info) << "Done.";
cout << "Done." << endl;
}




@@ -0,0 +1,47 @@
#include "UniqueNodeList.h"
#include "ConnectionPool.h"
#include "KnownNodeList.h"
#include "LedgerMaster.h"
#include "TimingService.h"
#include "ValidationCollection.h"
#include "Wallet.h"
#include <boost/asio.hpp>

class RPCDoor;
class PeerDoor;


class Application
{
TimingService mTimingService;
UniqueNodeList mUNL;
KnownNodeList mKnownNodes;
Wallet mWallet;
ValidationCollection mValidations;

LedgerMaster mLedgerMaster;

ConnectionPool mConnectionPool;
PeerDoor* mPeerDoor;
RPCDoor* mRPCDoor;

boost::asio::io_service mIOService;



public:
Application();

ConnectionPool& getConnectionPool(){ return(mConnectionPool); }
LedgerMaster& getLedgerMaster(){ return(mLedgerMaster); }
UniqueNodeList& getUNL(){ return(mUNL); }
ValidationCollection& getValidationCollection(){ return(mValidations); }



void run();


};

extern Application* theApp;
@@ -0,0 +1,102 @@
#include "BitcoinUtil.h"
#include <stdarg.h>
#include <windows.h>
#include <openssl/rand.h>
#include <time.h>

using namespace std;

std::string gFormatStr("v1");

std::string FormatFullVersion()
{
return(gFormatStr);
}


string strprintf(const char* format, ...)
{
char buffer[50000];
char* p = buffer;
int limit = sizeof(buffer);
int ret;
loop
{
va_list arg_ptr;
va_start(arg_ptr, format);
ret = _vsnprintf(p, limit, format, arg_ptr);
va_end(arg_ptr);
if (ret >= 0 && ret < limit)
break;
if (p != buffer)
delete[] p;
limit *= 2;
p = new char[limit];
if (p == NULL)
throw std::bad_alloc();
}
string str(p, p+ret);
if (p != buffer)
delete[] p;
return str;
}


inline int64 GetPerformanceCounter()
{
int64 nCounter = 0;
#ifdef WIN32
QueryPerformanceCounter((LARGE_INTEGER*)&nCounter);
#else
timeval t;
gettimeofday(&t, NULL);
nCounter = t.tv_sec * 1000000 + t.tv_usec;
#endif
return nCounter;
}

void RandAddSeed()
{
// Seed with CPU performance counter
int64 nCounter = GetPerformanceCounter();
RAND_add(&nCounter, sizeof(nCounter), 1.5);
memset(&nCounter, 0, sizeof(nCounter));
}
//
// "Never go to sea with two chronometers; take one or three."
// Our three time sources are:
// - System clock
// - Median of other nodes's clocks
// - The user (asking the user to fix the system clock if the first two disagree)
//
int64 GetTime()
{
return time(NULL);
}

void RandAddSeedPerfmon()
{
RandAddSeed();

// This can take up to 2 seconds, so only do it every 10 minutes
static int64 nLastPerfmon;
if (GetTime() < nLastPerfmon + 10 * 60)
return;
nLastPerfmon = GetTime();

#ifdef WIN32
// Don't need this on Linux, OpenSSL automatically uses /dev/urandom
// Seed with the entire set of perfmon data
unsigned char pdata[250000];
memset(pdata, 0, sizeof(pdata));
unsigned long nSize = sizeof(pdata);
long ret = RegQueryValueExA(HKEY_PERFORMANCE_DATA, "Global", NULL, NULL, pdata, &nSize);
RegCloseKey(HKEY_PERFORMANCE_DATA);
if (ret == ERROR_SUCCESS)
{
RAND_add(pdata, nSize, nSize/100.0);
memset(pdata, 0, nSize);
//printf("%s RandAddSeed() %d bytes\n", DateTimeStrFormat("%x %H:%M", GetTime()).c_str(), nSize);
}
#endif
}
@@ -0,0 +1,103 @@
#ifndef __BITCOIN_UTIL__
#define __BITCOIN_UTIL__

// TODO: these things should all go somewhere

#include <string>
#include "types.h"
#include "uint256.h"
#include <openssl/ripemd.h>
#include <openssl/sha.h>

std::string strprintf(const char* format, ...);
std::string FormatFullVersion();
void RandAddSeedPerfmon();

static const unsigned int MAX_SIZE = 0x02000000;

#define loop for (;;)




template<typename T1>
inline uint256 Hash(const T1 pbegin, const T1 pend)
{
static unsigned char pblank[1];
uint256 hash1;
SHA256((pbegin == pend ? pblank : (unsigned char*)&pbegin[0]), (pend - pbegin) * sizeof(pbegin[0]), (unsigned char*)&hash1);
uint256 hash2;
SHA256((unsigned char*)&hash1, sizeof(hash1), (unsigned char*)&hash2);
return hash2;
}

template<typename T1, typename T2>
inline uint256 Hash(const T1 p1begin, const T1 p1end,
const T2 p2begin, const T2 p2end)
{
static unsigned char pblank[1];
uint256 hash1;
SHA256_CTX ctx;
SHA256_Init(&ctx);
SHA256_Update(&ctx, (p1begin == p1end ? pblank : (unsigned char*)&p1begin[0]), (p1end - p1begin) * sizeof(p1begin[0]));
SHA256_Update(&ctx, (p2begin == p2end ? pblank : (unsigned char*)&p2begin[0]), (p2end - p2begin) * sizeof(p2begin[0]));
SHA256_Final((unsigned char*)&hash1, &ctx);
uint256 hash2;
SHA256((unsigned char*)&hash1, sizeof(hash1), (unsigned char*)&hash2);
return hash2;
}

template<typename T1, typename T2, typename T3>
inline uint256 Hash(const T1 p1begin, const T1 p1end,
const T2 p2begin, const T2 p2end,
const T3 p3begin, const T3 p3end)
{
static unsigned char pblank[1];
uint256 hash1;
SHA256_CTX ctx;
SHA256_Init(&ctx);
SHA256_Update(&ctx, (p1begin == p1end ? pblank : (unsigned char*)&p1begin[0]), (p1end - p1begin) * sizeof(p1begin[0]));
SHA256_Update(&ctx, (p2begin == p2end ? pblank : (unsigned char*)&p2begin[0]), (p2end - p2begin) * sizeof(p2begin[0]));
SHA256_Update(&ctx, (p3begin == p3end ? pblank : (unsigned char*)&p3begin[0]), (p3end - p3begin) * sizeof(p3begin[0]));
SHA256_Final((unsigned char*)&hash1, &ctx);
uint256 hash2;
SHA256((unsigned char*)&hash1, sizeof(hash1), (unsigned char*)&hash2);
return hash2;
}

inline uint160 Hash160(const std::vector<unsigned char>& vch)
{
uint256 hash1;
SHA256(&vch[0], vch.size(), (unsigned char*)&hash1);
uint160 hash2;
RIPEMD160((unsigned char*)&hash1, sizeof(hash1), (unsigned char*)&hash2);
return hash2;
}

/*
#ifdef WIN32
// This is used to attempt to keep keying material out of swap
// Note that VirtualLock does not provide this as a guarantee on Windows,
// but, in practice, memory that has been VirtualLock'd almost never gets written to
// the pagefile except in rare circumstances where memory is extremely low.
#include <windows.h>
#define mlock(p, n) VirtualLock((p), (n));
#define munlock(p, n) VirtualUnlock((p), (n));
#else
#include <sys/mman.h>
#include <limits.h>
// This comes from limits.h if it's not defined there set a sane default
#ifndef PAGESIZE
#include <unistd.h>
#define PAGESIZE sysconf(_SC_PAGESIZE)
#endif
#define mlock(a,b) \
mlock(((void *)(((size_t)(a)) & (~((PAGESIZE)-1)))),\
(((((size_t)(a)) + (b) - 1) | ((PAGESIZE) - 1)) + 1) - (((size_t)(a)) & (~((PAGESIZE) - 1))))
#define munlock(a,b) \
munlock(((void *)(((size_t)(a)) & (~((PAGESIZE)-1)))),\
(((((size_t)(a)) + (b) - 1) | ((PAGESIZE) - 1)) + 1) - (((size_t)(a)) & (~((PAGESIZE) - 1))))
#endif
*/

#endif
Oops, something went wrong.

0 comments on commit a8e8613

Please sign in to comment.