Commit Graph

230 Commits

Author SHA1 Message Date
Gavin Andresen 962b1cf441 Fix infinite loop with LogPrint on Windows
Running -printtodebugger -debug (or -debug=lock),
compiled with -DDEBUG_LOCKORDER would infinite loop
on Windows because every critical section lock/unlock
triggers a LogPrint.

Solution is to use the raw boost mutex instead of a CCriticalSection.
2013-12-10 11:34:28 +10:00
Wladimir J. van der Laan 0b47fe6bdc bitcoin-cli: remove unneeded dependencies (only code movement)
Remove unnecessary dependencies for bitcoin-cli
(leveldb, berkelydb, wallet, RPC server)

Build system changes:
- split libbitcoin.a into libbitcoin_common.a, libbitcoin_server.a and
  libbitcoin_cli.a

Code changes (movement only):
- split up HelpMessage into HelpMessage in init.cpp and HelpMessageCli
  in rpcclient.cpp
- move uiInterface from init.cpp to util.cpp
2013-12-03 09:07:13 +01:00
Philip Kaufmann 379778bde6 core: remove includes in .cpp, if header is already in .h
- example: if util.h includes stdint.h, remove it from util.cpp, as
  util.h is the first header included in util.cpp
2013-11-15 12:20:16 +01:00
Wladimir J. van der Laan d6f690f7da Use C99 printf statements in mingw
Otherwise, format specifiers such as %llu will not work on XP or
earlier.
This bug was introduced with 51ed9ec9.
http://sourceforge.net/apps/trac/mingw-w64/wiki/gnu%20printf
2013-11-13 17:02:27 +01:00
Gavin Andresen 17faf56262 Refactor: pull alert string sanitization into util 2013-11-11 10:22:45 +10:00
Brandon Dahler 51ed9ec971 Cleanup code using forward declarations.
Use misc methods of avoiding unnecesary header includes.
Replace int typedefs with int##_t from stdint.h.
Replace PRI64[xdu] with PRI[xdu]64 from inttypes.h.
Normalize QT_VERSION ifs where possible.
Resolve some indirect dependencies as direct ones.
Remove extern declarations from .cpp files.
2013-11-10 09:36:28 -06:00
Wladimir J. van der Laan bac72640ee Merge pull request #3076 from lano1106/uint256_util
Make util phexdigit array reusable
2013-11-04 05:55:37 -08:00
Pieter Wuille 1dffbf0060
Merge pull request #3114
a616206 Give peer time-adjustment data an own lock (Pieter Wuille)
2013-11-01 01:07:49 +01:00
Philip Kaufmann 3b570559f8 re-work -debug switch handling
- re-work -debug help message text
- make -debug log every debugging information again (even all categories)
- remove unneeded fDebug checks in front of LogPrint()/qDebug(), as that
  check is done in LogPrintf() when category is != NULL (true for all
  LogPrint() calls
- remove fDebug ONLY in code which is NOT performance-critical
- harmonize addrman category name
- deprecate -debugnet usage, should be used via -debug=net and remove the
  corresponding global
2013-10-30 16:02:09 +01:00
Olivier Langlois f171ec0c7d Make util phexdigit array reusable
class template base_uint had its own private lookup table.
This is saving 256 bytes per instantiation.

The result is not spectacular as bitcoin-qt has only shrinked of
about 1Kb but it is still valid improvement.

Also, I have replaced a for loop with a memset() call.

Made CBigNum::SetHex() use the new HexDigit() function.

Signed-off-by: Olivier Langlois <olivier@olivierlanglois.net>
2013-10-27 23:04:52 -04:00
Pieter Wuille a616206865 Give peer time-adjustment data an own lock
Instead of relying on cs_main (defined in a different module) to
prevent concurrent access to it.
2013-10-26 14:43:26 +02:00
Gavin Andresen 34f72ad6ef Merge pull request #3046 from sarchar/lockedpage-change
Changing LockedPageManager to use a managed instance
2013-10-20 16:14:26 -07:00
super3 db0e8ccd90 Bump Year Number to 2013 2013-10-20 15:25:06 -04:00
Chuck 0b8f47dc53 Changing LockedPageManager to use a managed instance
This ensures the allocator is ready no matter when it's needed (as
some STL implementations allocate in constructors -- i.e., MSVC's STL
in debug builds).

Using boost::call_once to guarantee thread-safe static initialization.

Adding some comments describing why the change was made.

Addressing deinitialization of the LockedPageManager object
by initializing it in a local static initializer and adding
an assert in the base's destructor.
2013-10-20 14:29:24 +07:00
Philip Kaufmann 917ac1dcc1 make fCommandLine a local variable in AppInit() 2013-10-08 10:52:42 +02:00
Philip Kaufmann faaeae1eb3 fix some printf -> LogPrintf leftovers 2013-09-20 10:49:34 +02:00
Gavin Andresen 881a85a22d Replace printf with LogPrintf / LogPrint 2013-09-18 20:39:25 +10:00
Gavin Andresen e51321fb75 Refactor: OutputDebugStringF -> LogPrint(category, ...) 2013-09-18 20:39:24 +10:00
Gregory Maxwell e7bad10c12 More fixes for blockchain corruption on OSX.
As we'd previously learned, OSX's fsync is a data eating lie.

Since 0.8.4 we're still getting some reports of disk corruption on
 OSX but now all of it looks like the block files have gotten out of
 sync with the database. It turns out that we were still using fsync()
 on the block files, so this isn't surprising.
2013-09-15 20:34:29 -07:00
Gavin Andresen b94595bb7f GetDataDir(): cache paths for each network separately 2013-08-22 11:05:44 +10:00
Gavin Andresen e622f3f195 Merge pull request #2855 from Diapolo/guard_CreatePidFile
exclude CreatePidFile() function on WIN32 as it is unused
2013-08-05 01:05:59 -07:00
Gavin Andresen 050d2e953f Remove #define loop from util.h
Replace the loop macro with while (true). The #define caused
problems for Qt.
2013-07-31 14:06:44 +10:00
Philip Kaufmann a034c7ebb6 exclude CreatePidFile() function on WIN32 as it is unused 2013-07-24 09:30:09 +02:00
Mike Hearn 0e4b317555 Introduce a CChainParameters singleton class and regtest mode.
The new class is accessed via the Params() method and holds
most things that vary between main, test and regtest networks.
The regtest mode has two purposes, one is to run the
bitcoind/bitcoinj comparison tool which compares two separate
implementations of the Bitcoin protocol looking for divergence.

The other is that when run, you get a local node which can mine
a single block instantly, which is highly convenient for testing
apps during development as there's no need to wait 10 minutes for
a block on the testnet.
2013-06-19 16:28:52 +02:00
Philip Kaufmann 53e71135de changes to thread code (directly use boost::thread)
- removes our NewThread() function an replaces remaining calls with
  boost::thread with our TraceThread template
- remove ExitThread() function
- fix THREAD_PRIORITY_ABOVE_NORMAL for non Windows OSes
2013-06-10 19:49:54 +02:00
Wladimir J. van der Laan 3e9c8bab54 Create parent directories if needed in GetDataDir
One-line change. Fixes #2752.
2013-06-08 10:03:23 +02:00
Philip Kaufmann 3260b4c090 remove GetBoolArg() fDefault parameter defaulting to false
- explicitly set the default of all GetBoolArg() calls
- rework getarg_test.cpp and util_tests.cpp to cover this change
- some indentation fixes
- move macdockiconhandler.h include in bitcoin.cpp to the "our headers"
  section
2013-06-01 12:53:57 +02:00
Jonas Schnelli b357a71cfa clear path cache after getting a proper config file (fixes #2605)
Signed-off-by: Jonas Schnelli <jonas.schnelli@include7.ch>
2013-05-02 18:55:25 +02:00
Pieter Wuille ba29a5590b Try to increase file descriptor rlimit if necessary
As the default can be too low, especially on OSX.
2013-04-29 01:46:24 +02:00
Tariq Bashir 6e34d9b12a Prevent prevent file descriptor leak in ShrinkDebugFile() 2013-04-27 16:00:28 +02:00
Philip Kaufmann b001c87126 small indentation, space, formatting fixes (no code changes) 2013-04-06 02:29:33 +02:00
Gavin Andresen b31499ec72 Clean up shutdown process 2013-04-03 19:57:53 -04:00
Gavin Andresen c8c2fbe07f Shutdown cleanup prep-work
Create a boost::thread_group object at the qt/bitcoind main-loop level
that will hold pointers to all the main-loop threads.

This will replace the vnThreadsRunning[] array.

For testing, ported the BitcoinMiner threads to use its
own boost::thread_group.
2013-04-03 14:04:21 -04:00
Gavin Andresen b8f4e42e1b Merge pull request #2229 from sipa/prealloc
Native versions for AllocateFileRange()
2013-02-22 09:00:13 -08:00
Gavin Andresen aaeb443791 Merge pull request #2312 from gmaxwell/random_random
ApproximateBestSubset internal RNG to prevent degenerate behavior.
2013-02-22 08:57:38 -08:00
Gavin Andresen 802a3dfdcc Merge pull request #2160 from petertodd/add-adjustedtime-to-rpc-getinfo
Add adjustedtime to getinfo RPC call
2013-02-22 08:47:45 -08:00
Gregory Maxwell 907a2aa4c7 Internal RNG for approximateBestSubset to prevent degenerate behavior.
This fixes test_bitcoin failures on openbsd reported by dhill on IRC.

  On some systems rand() is a simple LCG over 2^31 and so it produces
an even-odd sequence.  ApproximateBestSubset was only using the least
significant bit and so every run of the iterative solver would be the
same for some inputs, resulting in some pretty dumb decisions.

Using something other than the least significant bit would paper over
the issue but who knows what other way a system's rand() might get us
here.  Instead we use an internal RNG with a period of something like
2^60 which is well behaved.  This also makes it possible to make the
selection deterministic for the tests, if we wanted to implement that.
2013-02-18 14:13:39 -08:00
Pieter Wuille 1eb578796c Drop padding in blk* when finalizing file 2013-01-30 04:55:38 +01:00
Pieter Wuille 288fdc092a Native versions for AllocateFileRange() 2013-01-30 04:00:25 +01:00
Peter Todd 8686f6467c Add timeoffset to getinfo RPC call
Provides a method to get the difference between network adjusted time
and local time from the RPC interface.
2013-01-11 06:11:34 -05:00
Gavin Andresen ee3374234c OutputDebugStringF code cleanup
Initialize the OutputDebugStringF mutex and file pointer using
boost::call_once, to be thread-safe.
Make the return value of OutputDebugStringF really be the number of
characters written (*printf() semantics).
Declare the fReopenDebugLog flag volatile, since it is changed from
a signal handler.
And don't declare OutputDebugStringF() as inline.
2013-01-01 17:12:30 -05:00
Jeff Garzik 393819cde4 Remove 'T' from debug log timestamps
Space separation between major fields is easier for human eyes and
libs to parse.
2012-12-30 20:46:54 -05:00
Pieter Wuille 33766c9557 Merge pull request #2096 from 94m3k1n9/fix-time-formats
Change timestamps to use ISO8601 formatting
2012-12-13 14:39:57 -08:00
Richard Schwab 303b0009dc Change timestamps to use ISO8601 formatting 2012-12-12 16:32:22 +01:00
Pieter Wuille 3fb9b99cca Allow lengthy block reconnections to be interrupted
When the coin database is out of date with the block database, the
best block in it is automatically switched to. This reconnection
process can take time, so allow it to be interrupted.

This also stops block connection as soon as shutdown is requested,
leading to a faster shutdown.
2012-12-06 22:04:59 +01:00
Pieter Wuille 597fa4cd63 Add GetTempPath() to util 2012-11-29 01:00:35 +01:00
Philip Kaufmann 5350ea4171 update CClientUIInterface and remove orphan Wx stuff
- fix ThreadSafeMessageBox always displays error icon
- allow to specify MSG_ERROR / MSG_WARNING or MSG_INFORMATION without a
  custom caption / title
- allow to specify CClientUIInterface::ICON_ERROR / ICON_WARNING and
  ICON_INFORMATION (which is default) as message box icon
- remove CClientUIInterface::OK from ThreadSafeMessageBox-calls, as
  the OK button will be set as default, if none is specified
- prepend "Bitcoin - " to used captions
- rename BitcoinGUI::error() -> BitcoinGUI::message() and add function
  documentation
- change all style parameters and enum flags to unsigned
- update code to use that new API

- update Client- and WalletModel to use new BitcoinGUI::message() and
  rename the classes error() method into message()
- include the possibility to supply the wanted icon for messages from
  Client- and WalletModel via "style" parameter
2012-11-26 13:32:31 +01:00
Philip Kaufmann 0f8a647782 don't use memset() in privacy/security relevant code parts
As memset() can be optimized out by a compiler it should not be used in
privacy/security relevant code parts. OpenSSL provides the safe
OPENSSL_cleanse() function in crypto.h, which perfectly does the job of
clean and overwrite data.

For details see: http://www.viva64.com/en/b/0178/

- change memset() to OPENSSL_cleanse() where appropriate
- change a hard-coded number from netbase.cpp into a sizeof()
2012-11-09 12:53:53 +01:00
Pieter Wuille bba89aa82a Pre-allocate block and undo files in chunks
Introduce a AllocateFileRange() function in util, which wipes or
at least allocates a given range of a file. It can be overriden
by more efficient OS-dependent versions if necessary.

Block and undo files are now allocated in chunks of 16 and 1 MiB,
respectively.
2012-10-20 23:08:57 +02:00
Wladimir J. van der Laan 16f3618c13 Merge pull request #1879 from sipa/fdatasync
Use fdatasync instead of fsync on supported platforms
2012-10-11 00:42:47 -07:00
Wladimir J. van der Laan ac0ad5dc63 Merge pull request #1901 from laanwj/2012_10_remove_strlcpy
get rid of strlcpy.h
2012-10-11 00:39:51 -07:00
Pieter Wuille e996521390 Use fdatasync instead of fsync on supported platforms 2012-10-07 15:51:40 +02:00
Wladimir J. van der Laan 6032e4f4e7 get rid of strlcpy.h
Don't use hand-rolled string manipulation routine with a fixed
buffer in the bitcoin core, instead make use of c++ strings and boost.
2012-10-07 14:38:37 +02:00
Gavin Andresen cac6b389d1 Avoid crashes at shutdown due to printf() in global destructors. 2012-10-04 16:35:08 -04:00
Philip Kaufmann d210f4f5b8 fix -Wformat warnings all over the source 2012-10-01 19:45:42 +02:00
Wladimir J. van der Laan ac4e7f6269 HexStr: don't build a vector<char> first
Also const correctness for lookup tables in hex functions throughout the code.
2012-09-10 04:24:57 +02:00
Wladimir J. van der Laan 963af6449f Cleanup some unused macros from util.h
Encapsulate _snprintf/sprintf difference in implementation not header
2012-09-09 15:47:29 +02:00
Wladimir J. van der Laan b0a90fbb0c Add printf-style warnings to strprintf() and OutputDebugStringF()
This finds about ~150 potential problems with format characters on a 64 bit build.
2012-09-09 14:47:31 +02:00
Wladimir J. van der Laan 4d1d94c56c Rename CreateThread to NewThread
Prevent clash with win32 API symbol
2012-08-29 20:25:37 +02:00
Wladimir J. van der Laan 61d8507140 implement CreateThread with boost::thread
I'm not sure why this wasn't done before.

- Removes typedef of pthread_t on Windows, which fixes a native compile issue on mingw.
2012-08-29 20:02:07 +02:00
Wladimir J. van der Laan e95568b78d Handle locked pages more robustly (Fixes issue #1462)
Memory locks do not stack, that is, pages which have been locked several times by calls to mlock()
will be unlocked by a single call to munlock(). This can result in keying material ending up in swap when
those functions are used naively. In this commit a class "LockedPageManager" is added
that simulates stacking memory locks by keeping a counter per page.
2012-08-23 06:55:35 +02:00
Gavin Andresen cd58f05894 Restore OSX 10.5 compatibility (do not use pthread_setname_np) 2012-08-21 12:00:05 -04:00
Gavin Andresen 4d51be1cf3 Suppress output when running unit tests.
This does two things:
1) Now does not output to debug.log if -printtodebugger flag is passed
2) Unit tests set -printtodebugger so only test results are output to stdout

Note that -printtodebugger only actually prints to the debugger on Windows.
2012-08-20 11:33:20 -04:00
Jeff Garzik f81e6f779b Merge pull request #1632 from luke-jr/spelling
Fix spelling and grammar errors
2012-08-01 10:56:47 -07:00
Luke Dashjr b49f1398a1 Bugfix: Correct English grammar regarding "'s" 2012-08-01 17:50:00 +00:00
Philip Kaufmann e6bc9c35f3 Update Warning-strings to use a standard-format
- ensure warnings always start with "Warning:" and that the first
  character after ":" is written uppercase
- ensure the first sentence in warnings ends with an "!"
- remove unneeded spaces from Warning-strings
- add missing Warning-string translation
- remove a "\n" and replace with untranslatable "<br><br>"
2012-08-01 19:33:32 +02:00
Philip Kaufmann a7f82808c4 fix OpenSSL not written as proper noun in some comments 2012-07-21 12:44:54 +02:00
Gavin Andresen 92f6fb4cfa Teach RenameThread to work on OSX 2012-07-16 20:57:26 -04:00
Giel van Schijndel b277b0f100 Don't check for __linux__ specifically, check for PR_SET_NAME feature instead
Signed-off-by: Giel van Schijndel <me@mortis.eu>
2012-07-17 01:50:35 +02:00
Giel van Schijndel 304ca95508 Add support for renaming FreeBSD and OpenBSD threads
NOTE: This is currently disabled, until a developer with FreeBSD/OpenBSD
      can confirm that this works (without causing undefined behaviour
      preferrably).

Signed-off-by: Giel van Schijndel <me@mortis.eu>
2012-07-17 01:50:35 +02:00
Giel van Schijndel 96931d6f78 Give threads a recognisable name to aid in debugging
NOTE: These thread names are visible in gdb when using 'info threads'.
      Additionally both 'top' and 'ps' show these names *unless* told to
      display the command-line instead of task name.

Signed-off-by: Giel van Schijndel <me@mortis.eu>
2012-07-17 01:50:35 +02:00
fanquake e749405297 Fix a few typos 2012-06-29 17:26:45 +08:00
Gregory Maxwell 817ee0d826 Merge pull request #1174 from sipa/torhs
Tor hidden service support
2012-06-23 19:21:13 -07:00
Pieter Wuille 70f7f00385 Node support for Tor hidden services
This commit adds support for .onion addresses (mapped into the IPv6
by using OnionCat's range and encoding), and the ability to connect
to them via a SOCKS5 proxy.
2012-06-23 01:11:32 +02:00
Jeff Garzik d07eaba195 Introduce -debugnet option, thereby quieting some redundant debug messages
Prior to this change, each TX typically generated 3+ debug messages,

	askfor tx 8644cc97480ba1537214   0
	sending getdata: tx 8644cc97480ba1537214
	askfor tx 8644cc97480ba1537214   1339640761000000
	askfor tx 8644cc97480ba1537214   1339640881000000
	CTxMemPool::accept() : accepted 8644cc9748 (poolsz 6857)

After this change, there is only one message for each valid TX received

	CTxMemPool::accept() : accepted 22a73c5d8c (poolsz 42)

and two messages for each orphan tx received

	ERROR: FetchInputs() : 673dc195aa mempool Tx prev not found 1e439346fc
	stored orphan tx 673dc195aa (mapsz 19)

The -debugnet option, or its superset -debug, will restore the full debug
output.
2012-06-22 13:11:57 -04:00
Pieter Wuille c4c99ade65 Base32 encoding/decoding 2012-06-22 17:19:28 +02:00
Gavin Andresen feeb761ba0 Testnet, Mark III 2012-05-25 14:36:40 -04:00
Jeff Garzik 429039d45d Refactor: move runCommand() to util.cpp 2012-05-23 23:10:59 -04:00
Gavin Andresen d0e4051cd8 Merge branch 'optimize' 2012-05-22 11:13:00 -04:00
Pieter Wuille 63407fd6e2 Merge pull request #917 from mndrix/reopen-log-file
Reopen log file on SIGHUP
2012-05-21 10:04:26 -07:00
Pieter Wuille 46784d0826 Merge pull request #1354 from fanquake/master
Update Header Licenses
2012-05-20 12:27:50 -07:00
Wladimir J. van der Laan 239c11d0dd Make testcases build, prevent windows symbol collision 2012-05-20 10:44:50 +02:00
Wladimir J. van der Laan ab1b288fa7 Convert UI interface to boost::signals2.
- Signals now go directly from the core to WalletModel/ClientModel.
  - WalletModel subscribes to signals on CWallet: Prepares for multi-wallet support, by no longer assuming an implicit global wallet.
- Gets rid of noui.cpp, the few lines that were left are merged into init.cpp
- Rename wxXXX message flags to MF_XXX, to make them UI indifferent.
- ThreadSafeMessageBox no longer returns the value `4` which was never used, converted to void.
2012-05-20 10:44:50 +02:00
Wladimir J. van der Laan 01ecb074a7 Merge pull request #1302 from laanwj/2012_05_utilstrings
Get rid of snprintf (except one) with fixed buffers, shorten code
2012-05-20 01:30:18 -07:00
Michael Hendricks 9af080c351 Reopen debug.log on SIGHUP
The best log rotation method formerly available was to configure
logrotate with the copytruncate option.  As described in the logrotate
documentation, "there is a very small time slice between copying the
file and truncating it, so some logging data might be lost".

By sending SIGHUP to the server process, one can now reopen the debug
log file without losing any data.
2012-05-18 16:20:03 -06:00
Michael Hendricks fea25712ca Serialize access to debug.log stream
Acquire an exclusive, advisory lock before sending output to debug.log
and release it when we're done. This should avoid output from multiple
threads being interspersed in the log file.

We can't use CRITICAL_SECTION machinery for this because the debug log
is written during startup and shutdown when that machinery is not
available.

(Thanks to Gavin for pointing out the CRITICAL_SECTION problems based
on his earlier work in this area)
2012-05-18 16:19:09 -06:00
Pieter Wuille 660ff174f2 Use boost::thread locking instead of interprocess 2012-05-18 16:56:12 +02:00
Fordy 3a25a2b9b0 Update License in File Headers
I originally created a pull to replace the "COPYING" in crypter.cpp and
crypter.h, but it turned out that COPYING was actually the correct
file.
2012-05-18 22:02:28 +08:00
Gavin Andresen f718aedd9f Refactor: GetRandHash() method for util 2012-05-17 16:33:27 -04:00
Philip Kaufmann 5f9861953e fix RenameOver() and FileCommit() functions, to not generate compilation errors 2012-05-17 18:30:09 +02:00
Jeff Garzik 768e5d52fb Add new utility functions FileCommit(), RenameOver() 2012-05-16 19:25:25 -04:00
Wladimir J. van der Laan 29b79e4c0e Get rid of snprintf (except one) with fixed buffers, shorten code
- Use strprintf or vstrprintf instead of snprintf
2012-05-14 20:01:26 +02:00
Philip Kaufmann 0985816bf6 ensure that no double timestamps show up in the debug.log, by removing manual timestamps from the source (now only -logtimestamps parameter adds timestamps to debug.log) 2012-05-13 14:36:35 +02:00
Wladimir J. van der Laan 67d4cbab46 Move GetStartOnSystemStartup and SetStartOnSystemStartup to GUI code 2012-05-13 12:31:28 +02:00
Pieter Wuille 7f3ccb59da Split synchronization mechanisms from util.{h,cpp} 2012-05-11 18:13:51 +02:00
Gavin Andresen e6fd96f054 Fix osx build 2012-05-09 13:56:53 -04:00
Philip Kaufmann 3e468840bd util.h/.ccp: modifiy some comments / rename MyGetSpecialFolderPath() -> GetSpecialFolderPath(), set fCreate default to true and remove the fallback (not Win >= Vista compatible anyway) / remove namespace fs stuff where only used once / misc small changes' 2012-05-09 12:22:58 +02:00
Wladimir J. van der Laan 1f6f261ace Merge pull request #1187 from TheBlueMatt/win32_ie
Update to require IE 5.1 as it is required to build on mingw64.
2012-05-05 00:02:10 -07:00
Matt Corallo 234db30d66 Update to require IE 5.1 as it is required on mingw64.
We already require XP, this just fixes Mingw64 build.
2012-05-02 20:21:43 -04:00
Philip Kaufmann 1c94f88d5e fix compiler warning "suggest parentheses around assignment used as truth
value [-Wparentheses]" in util.cpp
2012-05-01 11:41:04 +02:00