<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://en.bitcoin.it/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Wickrick22</id>
	<title>Bitcoin Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://en.bitcoin.it/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Wickrick22"/>
	<link rel="alternate" type="text/html" href="https://en.bitcoin.it/wiki/Special:Contributions/Wickrick22"/>
	<updated>2026-04-29T03:38:29Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Bitcoind&amp;diff=17231</id>
		<title>Bitcoind</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Bitcoind&amp;diff=17231"/>
		<updated>2011-09-24T04:26:44Z</updated>

		<summary type="html">&lt;p&gt;Wickrick22: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:Bitcoin Original Client.png|thumb|350px|right|The bitcoin original client]]&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;Original Bitcoin client&#039;&#039;&#039; is the first [[bitcoin]] client in the network&#039;s history. It is also the official client of the bitcoin project. It&#039;s available under the [http://www.opensource.org/licenses/mit-license.php MIT license] for Windows, 32 and 64-bit GNU/Linux-based OSes and Mac OS X.&lt;br /&gt;
&lt;br /&gt;
The client comes with two executables, a GUI and an command line interface (CLI).&lt;br /&gt;
&lt;br /&gt;
== Executables ==&lt;br /&gt;
See [[Running_Bitcoin|running bitcoin]] for more detail and an example of the configuration file.&lt;br /&gt;
=== Bitcoin (GUI) ===&lt;br /&gt;
&lt;br /&gt;
The bitcoin GUI provides an easy to use wxWidgets-based interface. It allows to send coins and to monitor:&lt;br /&gt;
* transactions from and to the opened wallet&lt;br /&gt;
* block creations&lt;br /&gt;
* confirmations of transactions&lt;br /&gt;
* balance of the wallet&lt;br /&gt;
&lt;br /&gt;
=== Bitcoind (CLI) ===&lt;br /&gt;
&lt;br /&gt;
Bitcoind is both a headless daemon and a client for the same daemon.  It also provides a JSON-RPC interface, allowing it to be controlled locally (via bitcoind or another CLI client) or remotely.  [[Original Bitcoin client/API Calls list|Various commands]] are made available by the API.&lt;br /&gt;
&lt;br /&gt;
To use locally, first start the program in daemon mode:&lt;br /&gt;
:bitcoind -daemon&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then you can use the same program to execute [[Original Bitcoin client/API Calls list|API commands]], e.g.:&lt;br /&gt;
:bitcoind listreceivedbyaddress 0 true&lt;br /&gt;
:bitcoind getbalance&lt;br /&gt;
&lt;br /&gt;
To stop the bitcoin daemon, execute:&lt;br /&gt;
:bitcoind stop&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
&lt;br /&gt;
* Version 0.3.24 was released for all supported platforms on July 8th, 2011 &amp;lt;ref&amp;gt;[http://forum.bitcoin.org/index.php?topic=27187.0 Bitcoin version 0.3.24 released]&amp;lt;/ref&amp;gt;.&lt;br /&gt;
* Version 0.3.23 was released for all supported platforms on June 13th, 2011 &amp;lt;ref&amp;gt;[http://forum.bitcoin.org/index.php?topic=16553.0 Bitcoin version 0.3.23 released]&amp;lt;/ref&amp;gt;.&lt;br /&gt;
* Version 0.3.22 was released for all supported platforms on May 19th, 2011 &amp;lt;ref&amp;gt;[http://forum.bitcoin.org/index.php?topic=8894.0 Version 0.3.22]&amp;lt;/ref&amp;gt;.&lt;br /&gt;
* Version 0.3.20 was released for all supported platforms on February 21st, 2011&amp;lt;ref&amp;gt;[http://www.bitcoin.org/smf/index.php?topic=3704.0 Version 0.3.20]&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Theory of Operation==&lt;br /&gt;
&lt;br /&gt;
Satoshi&#039;s Original Bitcoin client is a multithreaded C++ program. It is designed to be portable across Windows, Mac, and Linux systems. The multithreaded aspect leads to some complexity and the use of certain code patterns to deal with concurrency that may be unfamiliar to many programmers. Also, the code is aggressive in the use of C++ constructs, so it will help to be fluent with map, multmap, set, string, vector, iostream, and templates. As typical of a C++ program, l a lot of code tends to end up in the header files so be sure to search both the .cpp and .h files when looking for a function.&lt;br /&gt;
&lt;br /&gt;
The client is oriented around several major operations, which are described in separate detailed articles and summarized in the following sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===[[Satoshi Client Initialization and Startup|Initialization and Startup]]===&lt;br /&gt;
Upon startup, the client performs various initilization routines including starting multiple threads to handle concurrent operations.&lt;br /&gt;
&lt;br /&gt;
===[[Satoshi Client Node Discovery|Node Discovery]]===&lt;br /&gt;
The client uses various techniques find out about other bitcoin nodes that may exist.&lt;br /&gt;
&lt;br /&gt;
===[[Satoshi Client Node Connectivity|Node Connectivity]]===&lt;br /&gt;
The client initiates and maintains connections to other nodes.&lt;br /&gt;
&lt;br /&gt;
===[[Satoshi Client Sockets and Messages|Sockets and Messages]]===&lt;br /&gt;
The client processes messages from other nodes and sends messages to other nodes using socket connections.&lt;br /&gt;
&lt;br /&gt;
===[[Satoshi Client Block Exchange|Block Exchange]]===&lt;br /&gt;
Nodes advertise their inventory of blocks to each other and exchange blocks to build block chains.&lt;br /&gt;
&lt;br /&gt;
===[[Satoshi Client Transaction Exchange|Transaction Exchange]]===&lt;br /&gt;
Nodes exchange and relay transactions with each other. The client associates transactions with bitcoin addresses in the local wallet.&lt;br /&gt;
&lt;br /&gt;
===Wallet Services===&lt;br /&gt;
The client can create transactions using the local wallet. The client associates transactions with bitcoin addresses in the local wallet. The client provides a service for managing the local wallet.&lt;br /&gt;
&lt;br /&gt;
===RPC Interface===&lt;br /&gt;
The client offers an JSON-RPC interface over HTTP over sockets to perform various operational functions and to manage the local wallet.&lt;br /&gt;
&lt;br /&gt;
===User Interface===&lt;br /&gt;
The user interface code is currently based on [http://www.wxwidgets.org wxWidgets] and is scheduled to be superseded by [[Bitcoin-qt]] in version 0.5.0. &lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
&lt;br /&gt;
* [[Original Bitcoin client/API calls list]]&lt;br /&gt;
* [[Protocol specification|Bitcoin network protocol]]&lt;br /&gt;
* [[Development process]]&lt;br /&gt;
* [[Changelog]]&lt;br /&gt;
&lt;br /&gt;
==External Links==&lt;br /&gt;
* [http://sourceforge.net/projects/bitcoin/ Bitcoin Client project on SourceForge]&lt;br /&gt;
* [https://github.com/bitcoin/bitcoin/ Bitcoin Client project on Github]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Nodes]]&lt;br /&gt;
[[Category:Wallets]]&lt;br /&gt;
[[Category:User Interfaces]]&lt;br /&gt;
[[Category:Clients]]&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Free Software]]&lt;br /&gt;
[[Category:License/MIT-X11]]&lt;br /&gt;
[[Category:Open Source]]&lt;/div&gt;</summary>
		<author><name>Wickrick22</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Satoshi_Client_Transaction_Exchange&amp;diff=17230</id>
		<title>Satoshi Client Transaction Exchange</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Satoshi_Client_Transaction_Exchange&amp;diff=17230"/>
		<updated>2011-09-24T04:16:51Z</updated>

		<summary type="html">&lt;p&gt;Wickrick22: Initial content&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
The Satoshi client advertises locally generated transactions and relays&lt;br /&gt;
transactions from other nodes. This article describes the operations&lt;br /&gt;
that deal with this exchange of transactions.&lt;br /&gt;
&lt;br /&gt;
See this article for more information on how transactions are validated:&lt;br /&gt;
[https://en.bitcoin.it/wiki/Protocol_rules#.22tx.22_messages Protocol Rules]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Wallet Send ==&lt;br /&gt;
&lt;br /&gt;
The client periodically calls SendMessages() (in main.cpp) which calls&lt;br /&gt;
ResendWalletTransactions to send transactions generated locallly.&lt;br /&gt;
This routine looks to see if there has been a new block since last time,&lt;br /&gt;
and if so, and the local transaction are still not in a block,&lt;br /&gt;
then the transactions are sent to all nodes.&lt;br /&gt;
This is done only about every 30 minutes.&lt;br /&gt;
&lt;br /&gt;
Transactions are only rebroadcast if they have a timestamp at least&lt;br /&gt;
5 minutes older than the last block was received. They are sorted&lt;br /&gt;
and sent oldest first.[1]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Periodic Advertisement ==&lt;br /&gt;
&lt;br /&gt;
The client periodically calls SendMessages() (in main.cpp) which&lt;br /&gt;
determines if a message should be sent to a remote node.&lt;br /&gt;
For each message processing iteration, one node is chosen as the&lt;br /&gt;
&amp;quot;trickle node&amp;quot;.[2]  This node is the only one chosen to receive&lt;br /&gt;
an &amp;quot;addr&amp;quot; message, if appropriate.[3]&lt;br /&gt;
&lt;br /&gt;
In the section for inventory, the client sends 1/4 of the transaction&lt;br /&gt;
inventory, determined randomly [4], UNLESS they are the trickle node,&lt;br /&gt;
in which case they receive ALL transactions.[5] Yes that seems reversed,&lt;br /&gt;
but it is what it is. If the node is to receive 1/4 (not all), then the&lt;br /&gt;
code also avoids sending any transactions that came from the local&lt;br /&gt;
wallet.[6]  The comments indicate this is intended to increase privacy.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Relay ==&lt;br /&gt;
&lt;br /&gt;
When the client receives a transaction via a &amp;quot;tx&amp;quot; messages,&lt;br /&gt;
it calls RelayMessage, which calls RelayInventory, which queues the&lt;br /&gt;
inventory to be sent to all other nodes.[7]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Footnotes==&lt;br /&gt;
&lt;br /&gt;
1. See CWallet::ResendWalletTransactions in wallet.cpp.&lt;br /&gt;
&lt;br /&gt;
2. See:&lt;br /&gt;
       pnodeTrickle = vNodesCopy[GetRand(vNodesCopy.size())];&lt;br /&gt;
and&lt;br /&gt;
       SendMessages(pnode, pnode == pnodeTrickle);&lt;br /&gt;
in ThreadMessageHandler2() in net.cpp.&lt;br /&gt;
&lt;br /&gt;
3. See:&lt;br /&gt;
        //&lt;br /&gt;
        // Message: addr&lt;br /&gt;
        //&lt;br /&gt;
        if (fSendTrickle)&lt;br /&gt;
        {  &lt;br /&gt;
in SendMessages() in main.cpp.&lt;br /&gt;
&lt;br /&gt;
4. See:&lt;br /&gt;
       bool fTrickleWait = ((hashRand &amp;amp; 3) != 0);&lt;br /&gt;
in SendMessages() in main.cpp.&lt;br /&gt;
&lt;br /&gt;
5. See:&lt;br /&gt;
        // trickle out tx inv to protect privacy&lt;br /&gt;
        if (inv.type == MSG_TX &amp;amp;&amp;amp; !fSendTrickle)&lt;br /&gt;
        {   &lt;br /&gt;
in SendMessages() in main.cpp.&lt;br /&gt;
&lt;br /&gt;
6. See:&lt;br /&gt;
        // always trickle our own transactions&lt;br /&gt;
        if (!fTrickleWait)&lt;br /&gt;
        {   &lt;br /&gt;
            CWalletTx wtx;&lt;br /&gt;
            if (GetTransaction(inv.hash, wtx))&lt;br /&gt;
               if (wtx.fFromMe)&lt;br /&gt;
                  fTrickleWait = true;&lt;br /&gt;
        }&lt;br /&gt;
in SendMessages() in main.cpp.&lt;br /&gt;
&lt;br /&gt;
7. Both RelayMessage and RelayInventory in net.h.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:Technical]]&lt;/div&gt;</summary>
		<author><name>Wickrick22</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Satoshi_Client_Block_Exchange&amp;diff=17118</id>
		<title>Satoshi Client Block Exchange</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Satoshi_Client_Block_Exchange&amp;diff=17118"/>
		<updated>2011-09-22T02:53:54Z</updated>

		<summary type="html">&lt;p&gt;Wickrick22: initial content&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
This article describes how blocks are exchanged between nodes.&lt;br /&gt;
See this article for more information on how blocks are validated:&lt;br /&gt;
https://en.bitcoin.it/wiki/Protocol_rules#Blocks&lt;br /&gt;
&lt;br /&gt;
Upon initial connection, if the connection was not inbound[1],&lt;br /&gt;
or in other words, if the connection was initiated by the local node,&lt;br /&gt;
the version message is queued for sending immediately. When the remote node&lt;br /&gt;
receives the version message it replies with its own version message.[2]&lt;br /&gt;
&lt;br /&gt;
When a node receives a &amp;quot;version&amp;quot; message, it may send a &amp;quot;getblocks&amp;quot; request&lt;br /&gt;
to the remote node if EITHER:&lt;br /&gt;
&lt;br /&gt;
# The node has never sent an initial getblocks request to any node yet.&lt;br /&gt;
# Or, this is the only active node connection. Presumably the node had zero connections prior to this connection, so maybe it was disconnected for a long time. So, it will ask for blocks to catch up.&lt;br /&gt;
&lt;br /&gt;
The getblocks message contains multiple block hashes that the requesting&lt;br /&gt;
node already possesses, in order to help the remote note find the latest&lt;br /&gt;
common block between the nodes.  The list of hashes starts with the latest&lt;br /&gt;
block and goes back ten and then doubles in an exponential progression&lt;br /&gt;
until the genesis block is reached.[3]  Since both nodes are hard coded&lt;br /&gt;
with the genesis block, they are guaranteed to a least start there.&lt;br /&gt;
If that block does not match for some reason, no blocks are exchanged.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Inventory Messages ==&lt;br /&gt;
&lt;br /&gt;
Note that the node receiving the getblocks request does not actually send&lt;br /&gt;
full blocks in response. The node sends an &amp;quot;inv&amp;quot; message containing just&lt;br /&gt;
the hashes of the series of blocks that fit the request, which verifies&lt;br /&gt;
that the node does indeed have blocks to send that the remote node does&lt;br /&gt;
not have (but does not presume the remote node wants the full blocks yet).&lt;br /&gt;
&lt;br /&gt;
When the local node receives the &amp;quot;inv&amp;quot; message, it will request the actual&lt;br /&gt;
blocks with a &amp;quot;getdata&amp;quot; message. See Below.&lt;br /&gt;
&lt;br /&gt;
But first, here is more detail how the remote node sends the &amp;quot;inv&amp;quot; message&lt;br /&gt;
in response to the &amp;quot;getblocks&amp;quot; request sent by the local node. The remote&lt;br /&gt;
node calls pFrom-&amp;gt;PushInventory which is a method on the CNode instance that&lt;br /&gt;
represents the node that requested the blocks (the local node in this&lt;br /&gt;
walkthrough), and PushInventory adds the block hash to the vInventoryToSend&lt;br /&gt;
variable of the CNode. The SendMessages function in main.cpp will take the&lt;br /&gt;
inv items out of vInventoryToSend and add it to a vInv variable which&lt;br /&gt;
means they are really ready for sending.[4]&lt;br /&gt;
The reason for the seperate variable is that some inventory items&lt;br /&gt;
(transactions only right now) may be &amp;quot;trickled&amp;quot; to the remote node,&lt;br /&gt;
which means they may kept from from being sent right away.&lt;br /&gt;
When the vInv variable fills up with 1000 entries, a message is queued&lt;br /&gt;
with those 1000 entries and the loop continues.  At the end, any&lt;br /&gt;
remaining entries are sent in a final &amp;quot;inv&amp;quot; message.&lt;br /&gt;
&lt;br /&gt;
When the local node receives the &amp;quot;inv&amp;quot; message, it will request the actual&lt;br /&gt;
block with a &amp;quot;getdata&amp;quot; message. To be precise, the node calls pfrom-&amp;gt;AskFor&lt;br /&gt;
to request the block, and that method queues the request for the blocks in&lt;br /&gt;
mapAskFor, and the multipurpose SendMessage() sends the &amp;quot;getdata&amp;quot; requests&lt;br /&gt;
in batches of 1000 entries from the map.[5]&lt;br /&gt;
&lt;br /&gt;
The code attempts to limit redundant requests to every 2 minutes for the&lt;br /&gt;
same block by using a map called mapAlreadyAskedFor to delay the message&lt;br /&gt;
if necessary.[6]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Block Batching ==&lt;br /&gt;
&lt;br /&gt;
The responding node to a &amp;quot;getblocks&amp;quot; request attempts to limit the response&lt;br /&gt;
to the requestor to 500 blocks.[7]&lt;br /&gt;
&lt;br /&gt;
However, in a peculiar twist, if the requestor appears to have diverged&lt;br /&gt;
from the main branch, the node will send as many blocks as necessary to&lt;br /&gt;
replace the entire bad chain of the requestor, from the lastest common block&lt;br /&gt;
between the nodes, up to the last block the requestor has (on their bad main&lt;br /&gt;
branch). That is in addition to the 500 &amp;quot;catch up&amp;quot; blocks for main branch&lt;br /&gt;
updates that will also be sent.[8]&lt;br /&gt;
&lt;br /&gt;
Note that in addition to a flat limit on the number of blocks queued for&lt;br /&gt;
sending, bitcoind also limits the total size of the blocks that are being&lt;br /&gt;
queued. This is currently limited to half the send buffer size[9], which is&lt;br /&gt;
10MB, for a limit of 5MB of queued blocks for send.[10]&lt;br /&gt;
&lt;br /&gt;
== Batch Continue Mechanism ==&lt;br /&gt;
&lt;br /&gt;
When a node is finished sending a batch of block inventory, it records the&lt;br /&gt;
hash of the last block in the batch.[11]  When the node receives a request&lt;br /&gt;
for that full block, it realizes the remove node is done with the current&lt;br /&gt;
batch and directly queues a special &amp;quot;inv&amp;quot; message (bypassing the normal&lt;br /&gt;
SendMessage mechanism) with one block hash entry containing the&lt;br /&gt;
latest block hash.[12] When the remote node receives that &amp;quot;inv&amp;quot; message,&lt;br /&gt;
it will see that it does not have that block and it it will ask for that&lt;br /&gt;
block as described above. However, this time when it receives the block&lt;br /&gt;
and processes it, it will notice that it does not have the previous block,&lt;br /&gt;
so it will record the latest block as an &amp;quot;orphan&amp;quot; block, and will request a&lt;br /&gt;
block update starting with the latest block it has up to the block before&lt;br /&gt;
the orphan [13], in order to fill in the gap. That goes out as a &amp;quot;getblocks&amp;quot;&lt;br /&gt;
request and the whole batch process repeats itself.&lt;br /&gt;
&lt;br /&gt;
However, there is a twist. When the next batch finishes, the remote node&lt;br /&gt;
sending the blocks will send the &amp;quot;inv&amp;quot; with latest block hash as usual, and&lt;br /&gt;
the local node will notice it already has this block in the orphan block&lt;br /&gt;
map this time and so it will skip requesting the block and directly ask&lt;br /&gt;
for a block update.[14] This process will continue until the last&lt;br /&gt;
block prior to the latest block is received. At the end of processing &lt;br /&gt;
that block, it will notice there is an orphan that pointed to this block&lt;br /&gt;
and will process the orphan block, (and any other orphans, recursively)&lt;br /&gt;
thus completing the entire process.[15]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Stall Recovery ==&lt;br /&gt;
&lt;br /&gt;
If the batching processes is interrupted for some reason, such as the&lt;br /&gt;
remote node failing to honor the &amp;quot;Batch Continue Mechanism&amp;quot; or if a &lt;br /&gt;
disconnection occurs, there is a way for the process to restart. When&lt;br /&gt;
a new block is solved and advertised around[16], any nodes that are&lt;br /&gt;
behind will notice the new block in the &amp;quot;inv&amp;quot; and that will trigger it&lt;br /&gt;
to request a &amp;quot;getblocks&amp;quot; update from the node that sent it the message.&lt;br /&gt;
That will cause blocks to be sent starting from wherever in the block&lt;br /&gt;
chain that the node that is behind is currently at.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Long Orphan Chains ==&lt;br /&gt;
&lt;br /&gt;
In various tests, it has proven relatively common (say more than one&lt;br /&gt;
in ten) to discover nodes that are significantly behind on the block&lt;br /&gt;
chain, probably because they are in the process of catching up as well.&lt;br /&gt;
Since a well connected node will have at least 8 and up to dozens of&lt;br /&gt;
connections, it is fairly likely that a new node will connect to&lt;br /&gt;
another node that is also catching up.&lt;br /&gt;
&lt;br /&gt;
Nodes that are catching up will advertise the blocks they are processing,&lt;br /&gt;
as they accept blocks into their main chain, to every other node.[16]&lt;br /&gt;
While there is code to prevent advertising old blocks before a certain&lt;br /&gt;
checkpoint, that code also has a clause that does advertise blocks to&lt;br /&gt;
remote nodes if the block height is over the remote node&#039;s current best&lt;br /&gt;
height minus 2000 blocks.[17] This appears to allow nodes to &amp;quot;help&amp;quot; other&lt;br /&gt;
nodes catch up, even if they are both processing old blocks.&lt;br /&gt;
&lt;br /&gt;
These advertisements cause the local node to request those blocks&lt;br /&gt;
from the remote node, which could be blocks well into the future compared&lt;br /&gt;
to what has been processed locally. Due to the way blocks are requested,&lt;br /&gt;
the remote node will send a large batch of blocks in response and will&lt;br /&gt;
continue sending blocks to the local node until it reaches the end.&lt;br /&gt;
Note that this is likely to occur at the same time the local node is&lt;br /&gt;
downloading earlier blocks on the main chain from another node. That&lt;br /&gt;
process may eventually catch up with the orphan chain and produce a &lt;br /&gt;
very, very long operation to revalidate and connect up all the orphan&lt;br /&gt;
blocks. Orphan chains over ten thousand blocks long, taking over an hour&lt;br /&gt;
to process are possible.&lt;br /&gt;
&lt;br /&gt;
Therefore, two nodes talking to each other that are both catching up can&lt;br /&gt;
lead to suboptimal interactions, especially when one both are far behind&lt;br /&gt;
and one is far ahead of the other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Flood Limit Effects ==&lt;br /&gt;
&lt;br /&gt;
Even with the batching mechanism described above, there are scenarios&lt;br /&gt;
that occur that result in the remote node overflowing the local receive&lt;br /&gt;
buffer while blocks are being exchanged.&lt;br /&gt;
&lt;br /&gt;
For example, if a remote node is &amp;quot;catching up&amp;quot;, it will advertise each block&lt;br /&gt;
it processes to the local node in certain circumstances (see above [17]).&lt;br /&gt;
The local node will request each of those blocks right away. There is no&lt;br /&gt;
protection against the local node requesting too many of these blocks.&lt;br /&gt;
The remote node will send all blocks requested. There is no protection&lt;br /&gt;
against the remote node sending too many blocks before the local node has&lt;br /&gt;
time to process them, in this circumstance.&lt;br /&gt;
&lt;br /&gt;
The local receive buffer can fill up. When the local node notices a receive&lt;br /&gt;
buffer is full, it disconnects that node connection.[18]&lt;br /&gt;
If sets the fDisconnect flag, and once the buffers are empty[19], the&lt;br /&gt;
socket is closed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Performance ==&lt;br /&gt;
&lt;br /&gt;
As of September 1, 2011, on a server class computer circa 2005 running&lt;br /&gt;
Ubuntu with a Comcast cable internet connection takes over 10 hours &lt;br /&gt;
to download and process the block chain. While it is debatable what&lt;br /&gt;
the bottleneck is early in the download process, it is clear from&lt;br /&gt;
the processing of recent blocks that the network is not the bottleneck&lt;br /&gt;
for all but the slowest internet connections.&lt;br /&gt;
&lt;br /&gt;
Blocks are taking over a second, on average, to process once downloaded.[20]&lt;br /&gt;
However, the average size of a block is only around 24 kilobytes&lt;br /&gt;
in August 2011. It certainly does not take 1 second to download 24K.&lt;br /&gt;
Also, testing reveals very large queues of blocks being processed per&lt;br /&gt;
message loop, which is not what you would expect if the thread was&lt;br /&gt;
pulling them out of the queue as they arrive on the sockets. &lt;br /&gt;
&lt;br /&gt;
There are a number of &amp;quot;false signals&amp;quot; that lead one to believe the problem&lt;br /&gt;
is with network performance. The first false signal is that, as of&lt;br /&gt;
August 2011, nearly all of the first 60 or 70% of  blocks downloaded are&lt;br /&gt;
very small. Recent average block sizes are around one hundred times bigger!&lt;br /&gt;
So, almost all of a sudden, the block rate goes from very fast to very slow.&lt;br /&gt;
It looks like something went wrong. In reality, if you measure the rate&lt;br /&gt;
of block processing by kilobyte, the rate remains relatively constant.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Another false signal is related to the fact that message queues are&lt;br /&gt;
processed to completion, one at a time per node. This can result in big&lt;br /&gt;
backups of messages from other nodes. So, a long period of increasing&lt;br /&gt;
blocks may freeze for long periods as other nodes are serviced. Consider&lt;br /&gt;
that block downloads typically come from just one remote node (at&lt;br /&gt;
least until a miner or other relaying or downloading node advertises&lt;br /&gt;
a late block and disrupts the process) and so all the work might&lt;br /&gt;
be on one node. Things go fast processing the blocks from a node,&lt;br /&gt;
and then that looks like it stops as &amp;quot;addr&amp;quot; messages are processed from&lt;br /&gt;
other nodes and other work is done. But it looks like something is wrong.&lt;br /&gt;
&lt;br /&gt;
Also, the orphaning effects described above can lead to excessive block&lt;br /&gt;
processing with nothing to show for it until the orphan chain is connected.&lt;br /&gt;
Also, you do ocassionally run into a node that is slow to respond, perhaps&lt;br /&gt;
because they are also processing blocks or because they have a slow machine&lt;br /&gt;
or connection.&lt;br /&gt;
&lt;br /&gt;
All of the above contributes to heavy &amp;quot;jitter&amp;quot; in the block download process,&lt;br /&gt;
and that is a more frustrating user experience than a constant download rate.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Footnotes==&lt;br /&gt;
1. See pfrom-&amp;gt;fInbound where pfrom is a CNode.&lt;br /&gt;
&lt;br /&gt;
2. See ProcessMessage() in main.cpp where strCommand == &amp;quot;version&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3. See CBlockLocator in main.h.&lt;br /&gt;
&lt;br /&gt;
4. See Message: inventory in SendMessage in main.cpp.&lt;br /&gt;
&lt;br /&gt;
5. See Message: getdata at the end of SendMessage in main.cpp.&lt;br /&gt;
&lt;br /&gt;
6. See CNode::AskFor in net.h.&lt;br /&gt;
&lt;br /&gt;
7. See ProcessMessage() in main.cpp where strCommand ==&amp;quot;getblocks&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
8. See&lt;br /&gt;
 int nLimit = 500 + locator.GetDistanceBack();&lt;br /&gt;
in ProcessMessage in main.cpp where strCommand ==&amp;quot;getblocks&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
9. See&lt;br /&gt;
 if (--nLimit &amp;lt;= 0 || nBytes &amp;gt;= SendBufferSize()/2)&lt;br /&gt;
in ProcessMessage() in main.cpp where strCommand ==&amp;quot;getblocks&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
10. See&lt;br /&gt;
 inline unsigned int SendBufferSize() {&lt;br /&gt;
        return 1000*GetArg(&amp;quot;-maxsendbuffer&amp;quot;, 10*1000); }&lt;br /&gt;
in net.h.&lt;br /&gt;
&lt;br /&gt;
11. See pfrom-&amp;gt;hashContinue = pindex-&amp;gt;GetBlockHash();&lt;br /&gt;
    in ProcessMessage() in main.cpp where strCommand ==&amp;quot;getblocks&amp;quot;.&lt;br /&gt;
12. See: if (inv.hash == pfrom-&amp;gt;hashContinue)&lt;br /&gt;
    in ProcessMessage() in main.cpp where strCommand ==&amp;quot;getdata&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
13. See:&lt;br /&gt;
        // Ask this guy to fill in what we&#039;re missing&lt;br /&gt;
        if (pfrom)&lt;br /&gt;
            pfrom-&amp;gt;PushGetBlocks(pindexBest, GetOrphanRoot(pblock2));&lt;br /&gt;
in ProcessBlock() in main.cpp.&lt;br /&gt;
&lt;br /&gt;
14. See:&lt;br /&gt;
        else if (inv.type == MSG_BLOCK &amp;amp;&amp;amp; mapOrphanBlocks.count(inv.hash))&lt;br /&gt;
            pfrom-&amp;gt;PushGetBlocks(pindexBest, GetOrphanRoot(mapOrphanBlocks[inv.hash]));&lt;br /&gt;
in ProcessMessage() in main.cpp where strCommand ==&amp;quot;inv&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
15. See:&lt;br /&gt;
    // Recursively process any orphan blocks that depended on this one&lt;br /&gt;
in ProcessBlock() in main.cpp.&lt;br /&gt;
&lt;br /&gt;
16. See the last block of code in AcceptBlock in main.cpp.&lt;br /&gt;
&lt;br /&gt;
17. See:&lt;br /&gt;
        if (nBestHeight &amp;gt; (pnode-&amp;gt;nStartingHeight != -1 ? pnode-&amp;gt;nStartingHeight - 2000 : 134444))&lt;br /&gt;
    in AcceptBlock() in main.cpp.&lt;br /&gt;
&lt;br /&gt;
18. See:&lt;br /&gt;
 if (nPos &amp;gt; ReceiveBufferSize()) {&lt;br /&gt;
in ThreadSocketHandler2() in net.cpp.&lt;br /&gt;
&lt;br /&gt;
19. See:&lt;br /&gt;
        if (pnode-&amp;gt;fDisconnect ||&lt;br /&gt;
            (pnode-&amp;gt;GetRefCount() &amp;lt;= 0 &amp;amp;&amp;amp; pnode-&amp;gt;vRecv.empty() &amp;amp;&amp;amp; pnode-&amp;gt;vSend.empty()))&lt;br /&gt;
in ThreadSocketHandler2() in net.cpp.&lt;br /&gt;
&lt;br /&gt;
20. This is from the authors experience and also&lt;br /&gt;
    see https://bitcointalk.org/index.php?topic=31376.0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:Technical]]&lt;/div&gt;</summary>
		<author><name>Wickrick22</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Satoshi_Client_Sockets_and_Messages&amp;diff=17117</id>
		<title>Satoshi Client Sockets and Messages</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Satoshi_Client_Sockets_and_Messages&amp;diff=17117"/>
		<updated>2011-09-22T02:43:06Z</updated>

		<summary type="html">&lt;p&gt;Wickrick22: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
The original bitcoin client uses a multithreaded approach to socket&lt;br /&gt;
handling and messages processing. There is one thread that handles&lt;br /&gt;
socket communication (ThreadSocketHandler) and one (ThreadMessageHandler)&lt;br /&gt;
which handles pulling messages off sockets and calling the&lt;br /&gt;
processing routines. Both of these threads are in net.cpp.&lt;br /&gt;
The message processing routines are in main.cpp, however.&lt;br /&gt;
&lt;br /&gt;
==Socket Thread==&lt;br /&gt;
The socket thread reads the sockets and places data into a CDataStream&lt;br /&gt;
associated with each node called vRecv. The Satoshi client uses C++&lt;br /&gt;
serialization operators &amp;gt;&amp;gt; and &amp;lt;&amp;lt; to read and write to a CDataStream&lt;br /&gt;
and then it uses generic routines to move the data between the streams&lt;br /&gt;
and sockets.&lt;br /&gt;
&lt;br /&gt;
==Message Thread==&lt;br /&gt;
The message thread reads and processes all messages from each node in&lt;br /&gt;
sequence, and then it sends messages to each node that should be sent&lt;br /&gt;
messages. That is all it does.&lt;br /&gt;
&lt;br /&gt;
Specifically, ThreadMessageHandler2 calls ProcessMessages(), which is&lt;br /&gt;
located in main.cpp, to pull messages off each node&#039;s socket and&lt;br /&gt;
process them. Then it calls SendMessages(), which is also located&lt;br /&gt;
in main.cpp to create and send any messages appropriate for each node.&lt;br /&gt;
&lt;br /&gt;
ProcessMessages() attempts to find a message start signature in the&lt;br /&gt;
vRecv stream. If it finds a message start, it deletes everything&lt;br /&gt;
prior to the start. Then it reads the header, extracts the message&lt;br /&gt;
type, and calls ProcessMessage on the message.&lt;br /&gt;
&lt;br /&gt;
SendMessages() actually creates and sends messages; it does not&lt;br /&gt;
just send preexisting queued messages. It goes through various&lt;br /&gt;
maps looking for work to do and produces a message and calls&lt;br /&gt;
PushMessage method of CNode to send the message. PushMessage&lt;br /&gt;
queues outbound data in the vSend data stream. (See PushMessage() in&lt;br /&gt;
net.cpp). The socket thread handler then pulls data off the&lt;br /&gt;
vSend data stream and calls send on the socket to send the data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:Technical]]&lt;/div&gt;</summary>
		<author><name>Wickrick22</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Satoshi_Client_Node_Connectivity&amp;diff=16803</id>
		<title>Satoshi Client Node Connectivity</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Satoshi_Client_Node_Connectivity&amp;diff=16803"/>
		<updated>2011-09-17T22:42:40Z</updated>

		<summary type="html">&lt;p&gt;Wickrick22: formatting&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==&amp;lt;br/&amp;gt;Overview==&lt;br /&gt;
&lt;br /&gt;
The Satoshi bitcoin client creates a thread to manage making&lt;br /&gt;
connections to other nodes. The code for that thread is in a&lt;br /&gt;
function called ThreadOpenConnections2 in net.cpp.&lt;br /&gt;
&lt;br /&gt;
The client also handles accepting new inbound connections and &lt;br /&gt;
disconnecting nodes when appropriate in a a thread called&lt;br /&gt;
ThreadSocketHandler2, which is also in net.cpp.&lt;br /&gt;
&lt;br /&gt;
The thread making connections does not discover the addresses of other&lt;br /&gt;
nodes. That information is gathered in various ways (See the article&lt;br /&gt;
on Node Discovery). The connection thread chooses among the available&lt;br /&gt;
addresses and makes connections and disconnects nodes when appropriate.&lt;br /&gt;
That is all it does.&lt;br /&gt;
&lt;br /&gt;
Node addresses are chosen based on the following set of rules.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Connection Rules==&lt;br /&gt;
&lt;br /&gt;
===Outbound Static Addresses===&lt;br /&gt;
&lt;br /&gt;
If the user specified addresses with -connect, the node uses &lt;br /&gt;
those addresses only. It tries to establish a connection to each node&lt;br /&gt;
and then sleeps for a half second, and then repeats that in a loop&lt;br /&gt;
until shut down. The code establishes a connection by calling&lt;br /&gt;
OpenNetworkConnection(addr). If the connection is already open,&lt;br /&gt;
OpenNetworkConnection just returns.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If the user specified addresses with -node, then connections are&lt;br /&gt;
made to those nodes (with a half second delay between each) upon&lt;br /&gt;
startup. After those connections are attempted, the code proceeds&lt;br /&gt;
to the regular connection handling code.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Outbound Limiting===&lt;br /&gt;
&lt;br /&gt;
The connection handling code is one loop that performs various functions until shutdown. The first thing the loop does is count&lt;br /&gt;
the number of outbound connections, and if the maximum has been&lt;br /&gt;
reached (8 or -maxconnections), then it goes into a 2 second delay&lt;br /&gt;
loop until the count is below the max.&lt;br /&gt;
&lt;br /&gt;
Assuming the number of connections is below the limit, the node attempts&lt;br /&gt;
to connect to another node. See the next section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Seed Nodes===&lt;br /&gt;
&lt;br /&gt;
If the node has not been able to learn about other addresses, presumably&lt;br /&gt;
because those methods have failed, the node will use an internal list&lt;br /&gt;
of 320 node addresses hard coded into the software to populate&lt;br /&gt;
the list of known node addresses.&lt;br /&gt;
&lt;br /&gt;
There is code to move away from seed nodes when possible. The presumption&lt;br /&gt;
is that this is to avoid overloading seed nodes. Once the local node has&lt;br /&gt;
enough addresses (presumably learned from the seed nodes), the&lt;br /&gt;
connection thread will close seed node connections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Outbound Random Selection===&lt;br /&gt;
&lt;br /&gt;
First the code puts the addresses into a.b.c.* buckets so only one&lt;br /&gt;
connection is made to each 24 bit netmasked network.&lt;br /&gt;
&lt;br /&gt;
Next, it loops through every address and determines whether it is &amp;quot;ready&amp;quot;,&lt;br /&gt;
and then, using a complex calculation, computes a score for every address.&lt;br /&gt;
The address with the highest score wins and OpenNetworkConnection is&lt;br /&gt;
called for it. Then the code completes the main loop of the thread and&lt;br /&gt;
continues.&lt;br /&gt;
&lt;br /&gt;
In order to determine readiness, the code hashes the IP and other entropy&lt;br /&gt;
into a deterministic random number between 1 and 3600. If the address&lt;br /&gt;
specifies a nonstandard port, a 2 hour (7200) penalty is added to the number.&lt;br /&gt;
This is an adjustment number to the retry interval.&lt;br /&gt;
&lt;br /&gt;
The main retry interval is basically the square root of the last time seen&lt;br /&gt;
plus the &amp;quot;random&amp;quot; adjustment from the previous paragraph. If the node&lt;br /&gt;
has been seen in the last hour, however, the retry interval is set to&lt;br /&gt;
ten minutes.  The following table is in the code:&lt;br /&gt;
&lt;br /&gt;
 // Last seen  Base retry frequency&lt;br /&gt;
 //   &amp;lt;1 hour   10 min&lt;br /&gt;
 //    1 hour    1 hour&lt;br /&gt;
 //    4 hours   2 hours&lt;br /&gt;
 //   24 hours   5 hours&lt;br /&gt;
 //   48 hours   7 hours&lt;br /&gt;
 //    7 days   13 hours&lt;br /&gt;
 //   30 days   27 hours&lt;br /&gt;
 //   90 days   46 hours&lt;br /&gt;
 //  365 days   93 hours&lt;br /&gt;
&lt;br /&gt;
After computing the interval, if the address has already been contacted in&lt;br /&gt;
the interval, the address is skipped.&lt;br /&gt;
&lt;br /&gt;
If the address is over a day old, we may skip it. If we are successfully&lt;br /&gt;
getting IRC addresses, and have node connections, then we skip it with&lt;br /&gt;
the assumption that we will see the address advertisement if it is really&lt;br /&gt;
active.&lt;br /&gt;
&lt;br /&gt;
Finally, for all addresses that appear to be ready for a retry, the&lt;br /&gt;
address that has not been contacted the longest is chosen with a maximum&lt;br /&gt;
of 24 hours. However, there is a twist. The calculation for the score is this:&lt;br /&gt;
 int64 nScore = min(nSinceLastTry, (int64)24 * 60 * 60) - nSinceLastSeen - nRandomizer;&lt;br /&gt;
So, the address is penalized for every second since it is last seen (and&lt;br /&gt;
a random adjustment).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Inbound Accepting and Disconnecting===&lt;br /&gt;
&lt;br /&gt;
The client handles accepting new inbound connections and disconnecting&lt;br /&gt;
nodes when appropriate in a a thread called ThreadSocketHandler2,&lt;br /&gt;
which is in net.cpp.&lt;br /&gt;
&lt;br /&gt;
The socket thread is simply a loop which disconnects sockets that&lt;br /&gt;
have the fDisconnect flag set on them (and have empty buffers),&lt;br /&gt;
prepares all sockets for &amp;quot;select&amp;quot; and calls &amp;quot;select&amp;quot;. &amp;quot;select&amp;quot; is &lt;br /&gt;
a system call which waits for activity on a set of sockets.&lt;br /&gt;
When that call returns, the node accepts any new connections,&lt;br /&gt;
receives and sends on any ready sockets, and marks any inactive sockets&lt;br /&gt;
for disconnect with the fDisconnect flag.&lt;br /&gt;
&lt;br /&gt;
Sockets are disconnected if they are 60 seconds old and have not sent&lt;br /&gt;
or received data.&lt;br /&gt;
&lt;br /&gt;
Sockets are disconnected if they have not sent or received data in&lt;br /&gt;
the last 90 minutes.&lt;br /&gt;
&lt;br /&gt;
Sockets are disconnected if the current inbound data exceeds a buffer limit.&lt;br /&gt;
(Search for: if (nPos &amp;gt; ReceiveBufferSize()) in net.cpp)&lt;br /&gt;
&lt;br /&gt;
Sockets are disconnected if the current outbound data exceeds a buffer limit.&lt;br /&gt;
(Search for: if (vSend.size() &amp;gt; SendBufferSize()) in net.cpp)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:Technical]]&lt;/div&gt;</summary>
		<author><name>Wickrick22</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Satoshi_Client_Node_Connectivity&amp;diff=16802</id>
		<title>Satoshi Client Node Connectivity</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Satoshi_Client_Node_Connectivity&amp;diff=16802"/>
		<updated>2011-09-17T22:34:18Z</updated>

		<summary type="html">&lt;p&gt;Wickrick22: formatting&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
The Satoshi bitcoin client creates a thread to manage making&lt;br /&gt;
connections to other nodes. The code for that thread is in a&lt;br /&gt;
function called ThreadOpenConnections2 in net.cpp.&lt;br /&gt;
&lt;br /&gt;
The client also handles accepting new inbound connections and &lt;br /&gt;
disconnecting nodes when appropriate in a a thread called&lt;br /&gt;
ThreadSocketHandler2, which is also in net.cpp.&lt;br /&gt;
&lt;br /&gt;
The thread making connections does not discover the addresses of other&lt;br /&gt;
nodes. That information is gathered in various ways (See the article&lt;br /&gt;
on Node Discovery). The connection thread chooses among the available&lt;br /&gt;
addresses and makes connections and disconnects nodes when appropriate.&lt;br /&gt;
That is all it does.&lt;br /&gt;
&lt;br /&gt;
Node addresses are chosen based on the following set of rules.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Connection Rules==&lt;br /&gt;
&lt;br /&gt;
===Outbound Static Addresses===&lt;br /&gt;
&lt;br /&gt;
If the user specified addresses with -connect, the node uses &lt;br /&gt;
those addresses only. It tries to establish a connection to each node&lt;br /&gt;
and then sleeps for a half second, and then repeats that in a loop&lt;br /&gt;
until shut down. The code establishes a connection by calling&lt;br /&gt;
OpenNetworkConnection(addr). If the connection is already open,&lt;br /&gt;
OpenNetworkConnection just returns.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If the user specified addresses with -node, then connections are&lt;br /&gt;
made to those nodes (with a half second delay between each) upon&lt;br /&gt;
startup. After those connections are attempted, the code proceeds&lt;br /&gt;
to the regular connection handling code.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Outbound Limiting===&lt;br /&gt;
&lt;br /&gt;
The connection handling code is one loop that performs various functions until shutdown. The first thing the loop does is count&lt;br /&gt;
the number of outbound connections, and if the maximum has been&lt;br /&gt;
reached (8 or -maxconnections), then it goes into a 2 second delay&lt;br /&gt;
loop until the count is below the max.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Assuming the number of connections is below the limit, the node attempts&lt;br /&gt;
to connect to another node. See the next section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Seed Nodes===&lt;br /&gt;
&lt;br /&gt;
If the node has not been able to learn about other addresses, presumably&lt;br /&gt;
because those methods have failed, the node will use an internal list&lt;br /&gt;
of 320 node addresses hard coded into the software to populate&lt;br /&gt;
the list of known node addresses.&lt;br /&gt;
&lt;br /&gt;
There is code to move away from seed nodes when possible. The presumption&lt;br /&gt;
is that this is to avoid overloading seed nodes. Once the local node has&lt;br /&gt;
enough addresses (presumably learned from the seed nodes), the&lt;br /&gt;
connection thread will close seed node connections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Outbound Random Selection===&lt;br /&gt;
&lt;br /&gt;
First the code puts the addresses into a.b.c.* buckets so only one&lt;br /&gt;
connection is made to each 24 bit netmasked network.&lt;br /&gt;
&lt;br /&gt;
Next, it loops through every address and determines whether it is &amp;quot;ready&amp;quot;,&lt;br /&gt;
and then, using a complex calculation, computes a score for every address.&lt;br /&gt;
The address with the highest score wins and OpenNetworkConnection is&lt;br /&gt;
called for it. Then the code completes the main loop of the thread and&lt;br /&gt;
continues.&lt;br /&gt;
&lt;br /&gt;
In order to determine readiness, the code hashes the IP and other entropy&lt;br /&gt;
into a deterministic random number between 1 and 3600. If the address&lt;br /&gt;
specifies a nonstandard port, a 2 hour (7200) penalty is added to the number.&lt;br /&gt;
This is an adjustment number to the retry interval.&lt;br /&gt;
&lt;br /&gt;
The main retry interval is basically the square root of the last time seen&lt;br /&gt;
plus the &amp;quot;random&amp;quot; adjustment from the previous paragraph. If the node&lt;br /&gt;
has been seen in the last hour, however, the retry interval is set to&lt;br /&gt;
ten minutes.  The following table is in the code:&lt;br /&gt;
&lt;br /&gt;
 // Last seen  Base retry frequency&lt;br /&gt;
 //   &amp;lt;1 hour   10 min&lt;br /&gt;
 //    1 hour    1 hour&lt;br /&gt;
 //    4 hours   2 hours&lt;br /&gt;
 //   24 hours   5 hours&lt;br /&gt;
 //   48 hours   7 hours&lt;br /&gt;
 //    7 days   13 hours&lt;br /&gt;
 //   30 days   27 hours&lt;br /&gt;
 //   90 days   46 hours&lt;br /&gt;
 //  365 days   93 hours&lt;br /&gt;
&lt;br /&gt;
After computing the interval, if the address has already been contacted in&lt;br /&gt;
the interval, the address is skipped.&lt;br /&gt;
&lt;br /&gt;
If the address is over a day old, we may skip it. If we are successfully&lt;br /&gt;
getting IRC addresses, and have node connections, then we skip it with&lt;br /&gt;
the assumption that we will see the address advertisement if it is really&lt;br /&gt;
active.&lt;br /&gt;
&lt;br /&gt;
Finally, for all addresses that appear to be ready for a retry, the&lt;br /&gt;
address that has not been contacted the longest is chosen with a maximum&lt;br /&gt;
of 24 hours. However, there is a twist. The calculation for the score is this:&lt;br /&gt;
 int64 nScore = min(nSinceLastTry, (int64)24 * 60 * 60) - nSinceLastSeen - nRandomizer;&lt;br /&gt;
So, the address is penalized for every second since it is last seen (and&lt;br /&gt;
a random adjustment).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Inbound Accepting and Disconnecting===&lt;br /&gt;
&lt;br /&gt;
The client handles accepting new inbound connections and disconnecting&lt;br /&gt;
nodes when appropriate in a a thread called ThreadSocketHandler2,&lt;br /&gt;
which is in net.cpp.&lt;br /&gt;
&lt;br /&gt;
The socket thread is simply a loop which disconnects sockets that&lt;br /&gt;
have the fDisconnect flag set on them (and have empty buffers),&lt;br /&gt;
prepares all sockets for &amp;quot;select&amp;quot; and calls &amp;quot;select&amp;quot;. &amp;quot;select&amp;quot; is &lt;br /&gt;
a system call which waits for activity on a set of sockets.&lt;br /&gt;
When that call returns, the node accepts any new connections,&lt;br /&gt;
receives and sends on any ready sockets, and marks any inactive sockets&lt;br /&gt;
for disconnect with the fDisconnect flag.&lt;br /&gt;
&lt;br /&gt;
Sockets are disconnected if they are 60 seconds old and have not sent&lt;br /&gt;
or received data.&lt;br /&gt;
&lt;br /&gt;
Sockets are disconnected if they have not sent or received data in&lt;br /&gt;
the last 90 minutes.&lt;br /&gt;
&lt;br /&gt;
Sockets are disconnected if the current inbound data exceeds a buffer limit.&lt;br /&gt;
(Search for: if (nPos &amp;gt; ReceiveBufferSize()) in net.cpp)&lt;br /&gt;
&lt;br /&gt;
Sockets are disconnected if the current outbound data exceeds a buffer limit.&lt;br /&gt;
(Search for: if (vSend.size() &amp;gt; SendBufferSize()) in net.cpp)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:Technical]]&lt;/div&gt;</summary>
		<author><name>Wickrick22</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Satoshi_Client_Node_Connectivity&amp;diff=16801</id>
		<title>Satoshi Client Node Connectivity</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Satoshi_Client_Node_Connectivity&amp;diff=16801"/>
		<updated>2011-09-17T22:29:20Z</updated>

		<summary type="html">&lt;p&gt;Wickrick22: Initial content&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
The Satoshi bitcoin client creates a thread to manage making&lt;br /&gt;
connections to other nodes. The code for that thread is in a&lt;br /&gt;
function called ThreadOpenConnections2 in net.cpp.&lt;br /&gt;
&lt;br /&gt;
The client also handles accepting new inbound connections and &lt;br /&gt;
disconnecting nodes when appropriate in a a thread called&lt;br /&gt;
ThreadSocketHandler2, which is also in net.cpp.&lt;br /&gt;
&lt;br /&gt;
The thread making connections does not discover the addresses of other&lt;br /&gt;
nodes. That information is gathered in various ways (See the article&lt;br /&gt;
on Node Discovery). The connection thread chooses among the available&lt;br /&gt;
addresses and makes connections and disconnects nodes when appropriate.&lt;br /&gt;
That is all it does.&lt;br /&gt;
&lt;br /&gt;
Node addresses are chosen based on the following set of rules.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Connection Rules==&lt;br /&gt;
&lt;br /&gt;
===Outbound Static Addresses===&lt;br /&gt;
&lt;br /&gt;
If the user specified addresses with -connect, the node uses &lt;br /&gt;
those addresses only. It tries to establish a connection to each node&lt;br /&gt;
and then sleeps for a half second, and then repeats that in a loop&lt;br /&gt;
until shut down. The code establishes a connection by calling&lt;br /&gt;
OpenNetworkConnection(addr). If the connection is already open,&lt;br /&gt;
OpenNetworkConnection just returns.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If the user specified addresses with -node, then connections are&lt;br /&gt;
made to those nodes (with a half second delay between each) upon&lt;br /&gt;
startup. After those connections are attempted, the code proceeds&lt;br /&gt;
to the regular connection handling code.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Outbound Limiting===&lt;br /&gt;
&lt;br /&gt;
The connection handling code is one loop that performs various&lt;br /&gt;
&lt;br /&gt;
functions until shutdown. The first thing the loop does is count&lt;br /&gt;
the number of outbound connections, and if the maximum has been&lt;br /&gt;
reached (8 or -maxconnections), then it goes into a 2 second delay&lt;br /&gt;
loop until the count is below the max.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Assuming the number of connections is below the limit, the node attempts&lt;br /&gt;
to connect to another node. See the next section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Seed Nodes===&lt;br /&gt;
&lt;br /&gt;
If the node has not been able to learn about other addresses, presumably&lt;br /&gt;
because those methods have failed, the node will use an internal list&lt;br /&gt;
of 320 node addresses hard coded into the software to populate&lt;br /&gt;
the list of known node addresses.&lt;br /&gt;
&lt;br /&gt;
There is code to move away from seed nodes when possible. The presumption&lt;br /&gt;
is that this is to avoid overloading seed nodes. Once the local node has&lt;br /&gt;
enough addresses (presumably learned from the seed nodes), the&lt;br /&gt;
connection thread will close seed node connections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Outbound Random Selection===&lt;br /&gt;
&lt;br /&gt;
First the code puts the addresses into a.b.c.* buckets so only one&lt;br /&gt;
connection is made to each 24 bit netmasked network.&lt;br /&gt;
&lt;br /&gt;
Next, it loops through every address and determines whether it is &amp;quot;ready&amp;quot;,&lt;br /&gt;
and then, using a complex calculation, computes a score for every address.&lt;br /&gt;
The address with the highest score wins and OpenNetworkConnection is&lt;br /&gt;
called for it. Then the code completes the main loop of the thread and&lt;br /&gt;
continues.&lt;br /&gt;
&lt;br /&gt;
In order to determine readiness, the code hashes the IP and other entropy&lt;br /&gt;
into a deterministic random number between 1 and 3600. If the address&lt;br /&gt;
specifies a nonstandard port, a 2 hour (7200) penalty is added to the number.&lt;br /&gt;
This is an adjustment number to the retry interval.&lt;br /&gt;
&lt;br /&gt;
The main retry interval is basically the square root of the last time seen&lt;br /&gt;
&lt;br /&gt;
plus the &amp;quot;random&amp;quot; adjustment from the previous paragraph. If the node&lt;br /&gt;
has been seen in the last hour, however, the retry interval is set to&lt;br /&gt;
ten minutes.  The following table is in the code:&lt;br /&gt;
&lt;br /&gt;
 // Last seen  Base retry frequency&lt;br /&gt;
 //   &amp;lt;1 hour   10 min&lt;br /&gt;
 //    1 hour    1 hour&lt;br /&gt;
 //    4 hours   2 hours&lt;br /&gt;
 //   24 hours   5 hours&lt;br /&gt;
 //   48 hours   7 hours&lt;br /&gt;
 //    7 days   13 hours&lt;br /&gt;
 //   30 days   27 hours&lt;br /&gt;
 //   90 days   46 hours&lt;br /&gt;
 //  365 days   93 hours&lt;br /&gt;
&lt;br /&gt;
After computing the interval, if the address has already been contacted in&lt;br /&gt;
the interval, the address is skipped.&lt;br /&gt;
&lt;br /&gt;
If the address is over a day old, we may skip it. If we are successfully&lt;br /&gt;
getting IRC addresses, and have node connections, then we skip it with&lt;br /&gt;
the assumption that we will see the address advertisement if it is really&lt;br /&gt;
active.&lt;br /&gt;
&lt;br /&gt;
Finally, for all addresses that appear to be ready for a retry, the&lt;br /&gt;
address that has not been contacted the longest is chosen with a maximum&lt;br /&gt;
of 24 hours. However, there is a twist. The calculation for the score is this:&lt;br /&gt;
 int64 nScore = min(nSinceLastTry, (int64)24 * 60 * 60) - nSinceLastSeen - nRandomizer;&lt;br /&gt;
So, the address is penalized for every second since it is last seen (and&lt;br /&gt;
a random adjustment).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Inbound Accepting and Disconnecting===&lt;br /&gt;
&lt;br /&gt;
The client handles accepting new inbound connections and disconnecting&lt;br /&gt;
&lt;br /&gt;
nodes when appropriate in a a thread called ThreadSocketHandler2,&lt;br /&gt;
which is in net.cpp.&lt;br /&gt;
&lt;br /&gt;
The socket thread is simply a loop which disconnects sockets that&lt;br /&gt;
have the fDisconnect flag set on them (and have empty buffers),&lt;br /&gt;
prepares all sockets for &amp;quot;select&amp;quot; and calls &amp;quot;select&amp;quot;. &amp;quot;select&amp;quot; is &lt;br /&gt;
a system call which waits for activity on a set of sockets.&lt;br /&gt;
When that call returns, the node accepts any new connections,&lt;br /&gt;
receives and sends on any ready sockets, and marks any inactive sockets&lt;br /&gt;
for disconnect with the fDisconnect flag.&lt;br /&gt;
&lt;br /&gt;
Sockets are disconnected if they are 60 seconds old and have not sent&lt;br /&gt;
or received data.&lt;br /&gt;
&lt;br /&gt;
Sockets are disconnected if they have not sent or received data in&lt;br /&gt;
the last 90 minutes.&lt;br /&gt;
&lt;br /&gt;
Sockets are disconnected if the current inbound data exceeds a buffer limit.&lt;br /&gt;
(Search for: if (nPos &amp;gt; ReceiveBufferSize()) in net.cpp)&lt;br /&gt;
&lt;br /&gt;
Sockets are disconnected if the current outbound data exceeds a buffer limit.&lt;br /&gt;
(Search for: if (vSend.size() &amp;gt; SendBufferSize()) in net.cpp)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:Technical]]&lt;/div&gt;</summary>
		<author><name>Wickrick22</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Satoshi_Client_Node_Discovery&amp;diff=16800</id>
		<title>Satoshi Client Node Discovery</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Satoshi_Client_Node_Discovery&amp;diff=16800"/>
		<updated>2011-09-17T22:21:58Z</updated>

		<summary type="html">&lt;p&gt;Wickrick22: Initial content&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
The Satoshi client discovers the IP address and port of nodes in several different ways.&lt;br /&gt;
&lt;br /&gt;
# Nodes discover their own external address by various methods.&lt;br /&gt;
# Nodes receive the callback address of remote nodes that connect to them.&lt;br /&gt;
# Nodes connect to IRC to receive addresses.&lt;br /&gt;
# Nodes makes DNS request to receive IP addresses.&lt;br /&gt;
# Nodes can use addresses hard coded into the software.&lt;br /&gt;
# Nodes exchange addresses with other nodes.&lt;br /&gt;
# Nodes store addresses in a database and read that database on startup.&lt;br /&gt;
# Nodes can be provided addresses as command line arguments&lt;br /&gt;
# Nodes read addresses from a user provided text file on startup&lt;br /&gt;
&lt;br /&gt;
A timestamp is kept for each address to keep track of when the node&lt;br /&gt;
address was last seen. The AddressCurrentlyConnected in net.cpp handles&lt;br /&gt;
updating the timestamp whenever a message is received from a node.&lt;br /&gt;
Timestamps are only updated on an address and saved to the database&lt;br /&gt;
when the timestamp is over 20 minutes old.&lt;br /&gt;
&lt;br /&gt;
See the Node Connectivity article for information on which type of&lt;br /&gt;
addresses take precedence when actually connecting to nodes.&lt;br /&gt;
&lt;br /&gt;
In the first section we will cover how a node handles a request for&lt;br /&gt;
addresses via the &amp;quot;getaddr&amp;quot; message. By understanding the role of&lt;br /&gt;
timestamps, it will become more clear why timestamps are kept the way&lt;br /&gt;
they are for each of the different ways an address is discovered.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Handling Message &amp;quot;getaddr&amp;quot;==&lt;br /&gt;
&lt;br /&gt;
When a node receives a &amp;quot;getaddr&amp;quot; request, it first figures out how many&lt;br /&gt;
addresses it has that have a timestamp in the last 3 hours.&lt;br /&gt;
Then it sends those addresses, but if there are more than 2500 addresses&lt;br /&gt;
seen in the last 3 hours, it selects around 2500 out of the available&lt;br /&gt;
recent addresses by using random selection.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now lets look at the ways a node finds out about node addresses.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Discovery Methods==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Local Client&#039;s External Address===&lt;br /&gt;
The client uses two methods to determine its own external, routable IP&lt;br /&gt;
address: it uses IRC, preferably, and if that does not succeed, it uses&lt;br /&gt;
public web services which return the information.&lt;br /&gt;
&lt;br /&gt;
From a thread created for this work (called ThreadIRCSeed in irc.cpp),&lt;br /&gt;
the client makes an IRC connection to 92.243.23.21 or irc.lfnet.org,&lt;br /&gt;
if the direct IP connection fails. The port is 6667.[1]&lt;br /&gt;
If the connection succeeds, the client issues a USERHOST command to&lt;br /&gt;
the IRC server, in order to get their own IP address.[2]&lt;br /&gt;
&lt;br /&gt;
The client also runs a thread called ThreadGetMyExternalIP (in net.cpp)&lt;br /&gt;
which attempts to determine the client&#039;s IP address as seen from the outside&lt;br /&gt;
world.  It gives the IRC thread a chance to discover the IP address&lt;br /&gt;
first, sleeping and checking periodically for 2 minutes, and then it&lt;br /&gt;
proceeds if the IRC method did not succeed.&lt;br /&gt;
&lt;br /&gt;
First, it attempts to connect to 91.198.22.70 port 80, which should be&lt;br /&gt;
the checkip.dyndns.org server. If connection fails, a DNS request is made&lt;br /&gt;
for checkip.dyndns.org and a connection is attempted to that address.&lt;br /&gt;
Next, it attemps to connect to 74.208.43.192 port 80, which should be&lt;br /&gt;
the www.showmyip.com server. If connection fails, a DNS request is made&lt;br /&gt;
for www.showmyip.com and a connection is attempted to that address.&lt;br /&gt;
&lt;br /&gt;
For each address attempted above, the client attempts to connect,&lt;br /&gt;
send a HTTP request, read the appropriate response line, and parse the&lt;br /&gt;
IP address from it.&lt;br /&gt;
If this succeeds, the IP is returned, it is advertised to any connected&lt;br /&gt;
nodes, and then the thread finishes (without proceeding to the next&lt;br /&gt;
address).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Connect Callback Address===&lt;br /&gt;
When a node receives an initial &amp;quot;version&amp;quot; message, and that node initiated&lt;br /&gt;
the connection, then the node advertises its address to the remote so&lt;br /&gt;
that it can connect back to the local node if it wants to.[3]&lt;br /&gt;
After sending its own address, it sends a &amp;quot;getaddr&amp;quot; request message&lt;br /&gt;
to the remote node to learn about more addresses, if the remote node&lt;br /&gt;
version is recent or if the local node does not yet have 1000 addresses.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===IRC Addresses===&lt;br /&gt;
&lt;br /&gt;
In addition to learning and sharing its own address, the node&lt;br /&gt;
learns about other node addresses via an IRC channel. See irc.cpp.&lt;br /&gt;
After learning its own address, a node encodes its own address into a string&lt;br /&gt;
to be used as a nickname. Then, it randomly joins an IRC channel named&lt;br /&gt;
between #bitcoin00 and #bitcoin99. Then it issues a WHO command.&lt;br /&gt;
The thread reads the lines as they appear in the channel and decodes&lt;br /&gt;
the IP addresses of other nodes in the channel. It does this in&lt;br /&gt;
a loop, forever, until the node is shutdown.&lt;br /&gt;
&lt;br /&gt;
When the client discovers an address from IRC, it sets the timestamp&lt;br /&gt;
on the address to the current time, but it uses a &amp;quot;penalty&amp;quot;&lt;br /&gt;
of 51 minutes, which means it looks like it was actually seen&lt;br /&gt;
almost an hour ago.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===DNS Addresses===&lt;br /&gt;
Upon startup, the client makes DNS requests to hard coded DNS names&lt;br /&gt;
in order to learn about the addresses of other nodes.[4] As of version&lt;br /&gt;
v0.3.24, these addresses were[5]:&lt;br /&gt;
&lt;br /&gt;
bitseed.xf2.org&lt;br /&gt;
bitseed.bitcoin.org.uk&lt;br /&gt;
dnsseed.bluematt.me&lt;br /&gt;
&lt;br /&gt;
A recent query of these addresses returned 48 nodes. Note that a&lt;br /&gt;
DNS reply can contain multiple IP addresses for a requested name.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Addresses discovered via DNS are initially given a zero timestamp,&lt;br /&gt;
therefore they are not advertised in response to a &amp;quot;getaddr&amp;quot; request.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Hard Coded &amp;quot;Seed&amp;quot; Addresses===&lt;br /&gt;
The client contains hard coded IP addresses that represent bitcoin nodes.[6]&lt;br /&gt;
These addresses are only used as a last resort, if no other method&lt;br /&gt;
has produced any addresses at all.[7]&lt;br /&gt;
When the loop in the connection handling thread ThreadOpenConnections2()&lt;br /&gt;
sees an empty address map, it uses the &amp;quot;seed&amp;quot; IP addresses as backup.&lt;br /&gt;
&lt;br /&gt;
There is code is move away from seed nodes when possible. The presumption&lt;br /&gt;
is that this is to avoid overloading those nodes. Once the local node has&lt;br /&gt;
enough addresses (presumably learned from the seed nodes), the&lt;br /&gt;
connection thread will close seed node connections.[8]&lt;br /&gt;
&lt;br /&gt;
Seed Addresses are initially given a zero timestamp,&lt;br /&gt;
therefore they are not advertised in response to a &amp;quot;getaddr&amp;quot; request.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Ongoing &amp;quot;addr&amp;quot; advertisements===&lt;br /&gt;
Nodes may receive addresses in an &amp;quot;addr&amp;quot; message after having&lt;br /&gt;
sent a &amp;quot;getaddr&amp;quot; request, or &amp;quot;addr&amp;quot; messages may arrive &lt;br /&gt;
unsolicited, because nodes advertise addresses gratuitously&lt;br /&gt;
when they relay addresses (see below), when they advertise&lt;br /&gt;
their own address periodically, and when a connection is made.&lt;br /&gt;
&lt;br /&gt;
If the address is from a really old version, it is ignored; if from&lt;br /&gt;
a not-so-old version, it is ignored if we have 1000 addresses already.&lt;br /&gt;
&lt;br /&gt;
If the sender sent over 1000 addresses, they are all ignored.&lt;br /&gt;
&lt;br /&gt;
Addresses received from an &amp;quot;addr&amp;quot; message have a timestamp, but the&lt;br /&gt;
timestamp is not necessarily honored directly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every address in the message:&lt;br /&gt;
# If the timestamp is too low or too high, it is set to 5 days ago.&lt;br /&gt;
# We subtract 2 hours from the timestamp and add the address.&lt;br /&gt;
&lt;br /&gt;
Note that when any address is added, for any reason, the code that calls&lt;br /&gt;
AddAddress() does not check to see if it already exists. The AddAddresss()&lt;br /&gt;
function in net.cpp will do that, and if the address already exists, further&lt;br /&gt;
processing is done to update the address record. If the advertised services&lt;br /&gt;
of the address have changed, that is updated and stored.&lt;br /&gt;
If the address has been seen in the last 24 hours and the timestamp is&lt;br /&gt;
currently over 60 minutes old, then it is updated to 60 minutes ago.&lt;br /&gt;
If the address has NOT been seen in the last 24 hours, and the timestamp is&lt;br /&gt;
currently over 24 hours old, then it is updated to 24 hours ago.&lt;br /&gt;
&lt;br /&gt;
====Address Relay====&lt;br /&gt;
&lt;br /&gt;
Once addresses are added from an &amp;quot;addr&amp;quot; message (see above), they then&lt;br /&gt;
may be relayed to the other nodes. First, the following criteria&lt;br /&gt;
must be set [9]:&lt;br /&gt;
&lt;br /&gt;
#The address timestamp, after processing, is within 60 minutes of the current time&lt;br /&gt;
#The &amp;quot;addr&amp;quot; message contains 10 addresses or less&lt;br /&gt;
#And fGetAddr is not set on the node. fGetAddr starts false, is set to true when we request addresses from a node, and it is cleared when we receive less than 1000 addresses from a node.&lt;br /&gt;
#The address must be routable.&lt;br /&gt;
&lt;br /&gt;
When they meet the above criteria, the node hashes all the eligible&lt;br /&gt;
node IP addresses, as well as the current day in the form of an integer,&lt;br /&gt;
and the two nodes with the lowest hash value are chosen to have&lt;br /&gt;
the address relayed to them.&lt;br /&gt;
&lt;br /&gt;
====Self broadcast====&lt;br /&gt;
&lt;br /&gt;
Every 24 hours, the node advertises its own address to all connected nodes.&lt;br /&gt;
It also clears the list of the addresses we think the remote node has, which&lt;br /&gt;
will trigger a refresh of sends to nodes. This code is in SendMessages()&lt;br /&gt;
in main.cpp.&lt;br /&gt;
&lt;br /&gt;
====Old Address Cleanup====&lt;br /&gt;
&lt;br /&gt;
In SendMessages() in main.cpp, there is code to remove old addresses.&lt;br /&gt;
This is done every ten minutes, as long as there are 3 active connections.&lt;br /&gt;
The node erases messages that have not been used in 14 days as&lt;br /&gt;
long as there are at least 1000 addresses in the map, and as long&lt;br /&gt;
as the erasing process has not taken more than 20 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Addresses stored in the Database===&lt;br /&gt;
Addresses are stored in the database when AddAddress() is called.&lt;br /&gt;
&lt;br /&gt;
Addresses are read on startup when AppInit2() calls LoadAddresses(),&lt;br /&gt;
which is located in db.cpp.&lt;br /&gt;
&lt;br /&gt;
Currently, it appears all addresses are stored all at once whenever&lt;br /&gt;
any address is stored or updated [10]. Indeed, AddAddress is seen&lt;br /&gt;
to take over .01 seconds in various testing and is typically called &lt;br /&gt;
tens of thousands of times in the initial 12 hours of running the&lt;br /&gt;
client.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Command Line Provided Addresses===&lt;br /&gt;
&lt;br /&gt;
The user can specify nodes to connect to with the -addnode &amp;lt;ip&amp;gt;&lt;br /&gt;
command line argument. Multiple nodes may be specified.&lt;br /&gt;
&lt;br /&gt;
Addresses provided on the command line are initially given a zero&lt;br /&gt;
timestamp, therefore they are not advertised in response to a &amp;quot;getaddr&amp;quot;&lt;br /&gt;
request.&lt;br /&gt;
&lt;br /&gt;
The user can also specify an address to connect to with the -connect &amp;lt;ip&amp;gt;&lt;br /&gt;
command line argument. Multiple nodes may be specified.&lt;br /&gt;
The -connect argument differs from -addnode in that -connect addresses&lt;br /&gt;
are not added to the address database and when -connect is specified,&lt;br /&gt;
only those addresses are used.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Text File Provided Addresses===&lt;br /&gt;
The client will automatically read a file named &amp;quot;addr.txt&amp;quot; in the&lt;br /&gt;
bitcoin data directory and will add any addresses it finds in there&lt;br /&gt;
as node addresses. These nodes are given no special preference over&lt;br /&gt;
other addresses. They are just added to the pool.&lt;br /&gt;
&lt;br /&gt;
Addresses loaded from the text file are initially given a zero timestamp,&lt;br /&gt;
therefore they are not advertised in response to a &amp;quot;getaddr&amp;quot; request.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Footnotes==&lt;br /&gt;
1. See: &lt;br /&gt;
 CAddress addrConnect(&amp;quot;92.243.23.21&amp;quot;, 6667); // irc.lfnet.org&lt;br /&gt;
in ThreadIRCSeed2() in irc.cpp.&lt;br /&gt;
&lt;br /&gt;
2. See:&lt;br /&gt;
 GetIPFromIRC()&lt;br /&gt;
in irc.cpp.&lt;br /&gt;
&lt;br /&gt;
3. See:&lt;br /&gt;
 // Advertise our address&lt;br /&gt;
in ProcessMessage() in main.cpp where strCommand == &amp;quot;version&amp;quot;&lt;br /&gt;
&lt;br /&gt;
4. See &lt;br /&gt;
 DNSAddressSeed()&lt;br /&gt;
in net.cpp.&lt;br /&gt;
&lt;br /&gt;
5. See &lt;br /&gt;
 static const char *strDNSSeed[] = {&lt;br /&gt;
in net.cpp&lt;br /&gt;
&lt;br /&gt;
6. See&lt;br /&gt;
  pnSeed &lt;br /&gt;
in net.cpp&lt;br /&gt;
&lt;br /&gt;
7. See:&lt;br /&gt;
        if (mapAddresses.empty() &amp;amp;&amp;amp; (GetTime() - nStart &amp;gt; 60 || fTOR) &amp;amp;&amp;amp; !fTestNet)&lt;br /&gt;
in ThreadOpenConnections2() in net.cpp.&lt;br /&gt;
&lt;br /&gt;
8. See:&lt;br /&gt;
            if (fSeedUsed &amp;amp;&amp;amp; mapAddresses.size() &amp;gt; ARRAYLEN(pnSeed) + 100)&lt;br /&gt;
            {   &lt;br /&gt;
                // Disconnect seed nodes&lt;br /&gt;
in ThreadOpenConnections2() in net.cpp.&lt;br /&gt;
&lt;br /&gt;
9. See:&lt;br /&gt;
 if (addr.nTime &amp;gt; nSince &amp;amp;&amp;amp; !pfrom-&amp;gt;fGetAddr &amp;amp;&amp;amp; vAddr.size() &amp;lt;= 10 &amp;amp;&amp;amp; addr.IsRoutable())&lt;br /&gt;
in ProcessMessage() in main.cpp where strCommand == &amp;quot;addr&amp;quot;&lt;br /&gt;
&lt;br /&gt;
10. See [https://bitcointalk.org/index.php?topic=26436.0 bitcointalk.org]&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:Technical]]&lt;/div&gt;</summary>
		<author><name>Wickrick22</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Satoshi_Client_Initialization_and_Startup&amp;diff=16799</id>
		<title>Satoshi Client Initialization and Startup</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Satoshi_Client_Initialization_and_Startup&amp;diff=16799"/>
		<updated>2011-09-17T22:01:31Z</updated>

		<summary type="html">&lt;p&gt;Wickrick22: Initial content&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
==Startup Process==&lt;br /&gt;
&lt;br /&gt;
The client uses a fixed number of threads that are created on startup. All of the reading and writing on active network sockets are handled by one thread.&lt;br /&gt;
&lt;br /&gt;
The main() entry point to the program is in init.cpp. Do not go looking in main.cpp for main() - you will not find it.&lt;br /&gt;
&lt;br /&gt;
The first thing main() does is call AppInit, which calls AppInit2 which performs a bunch of initialization busy work mostly related to how the application handles errors. At some point AppInit2 calls ParseParameters, and then some argument handling code processes some basic arguments.&lt;br /&gt;
&lt;br /&gt;
Now it checks to see if an existing GUI window is already present and if so, brings it to the foreground.&lt;br /&gt;
&lt;br /&gt;
Next it creates a lock file in the bitcoin directory and if bitcoin is already running, displays a message and exits.&lt;br /&gt;
&lt;br /&gt;
Next it attemps to listen on the bitcoin port, and if the port is already in user or other error, displays a message and exits.&lt;br /&gt;
&lt;br /&gt;
Next it loads IP addresses from a database, then it loads the block index, and then it loads the wallet.&lt;br /&gt;
&lt;br /&gt;
Next it gets the top block number from the wallet, or zero if -rescan is used. Then It scans the block chain from the block number above.&lt;br /&gt;
&lt;br /&gt;
Side Note:  printf has been redefined in util.h. So printf is really OutputDebugStringF which directs to a file if appropriate (see util.h and util.cpp). Also &amp;quot;loop&amp;quot; is defined in util.h as for (  ; ;  ).&lt;br /&gt;
&lt;br /&gt;
Then it does a bit more initialization and parameter processing and then it finally opens the GUI main window.&lt;br /&gt;
&lt;br /&gt;
Next it creates two threads:&lt;br /&gt;
&lt;br /&gt;
# StartNode()&lt;br /&gt;
# And if acting as server: ThreadRPCServer()&lt;br /&gt;
&lt;br /&gt;
This is the only place where these threads are created.&lt;br /&gt;
&lt;br /&gt;
StartNode() is in net.cpp and ThreadRPCServer() is in rpc.cpp.&lt;br /&gt;
&lt;br /&gt;
Last, if not compiled for the GUI it sleeps for 5 seonds in an infinite loop.&lt;br /&gt;
&lt;br /&gt;
== fClient Mode ==&lt;br /&gt;
&lt;br /&gt;
It is worth noting that there is code in the client to allow it to operate in a mode where it only downloads block headers. The implementation is intended to be used as a lightweight client mode which can operate without verifying and storing all blocks and transactions. This is controlled by the fClient variable in the code which is currently hard coded to false.  This is currently not considered to be finished code. This mode is known as fClient mode and the phrase Simplified Payment Verification (or SPV) mode has also been used to describe a lightweight client approach.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Thread StartNode() in net.cpp==&lt;br /&gt;
&lt;br /&gt;
StartNode is sort of a master networking thread.&lt;br /&gt;
&lt;br /&gt;
First it creates a CNode for the localhost 127.0.0.1 internal addresss to&lt;br /&gt;
handle communication.&lt;br /&gt;
&lt;br /&gt;
Next, it gets the local IP address. On windows, its a lookup using the&lt;br /&gt;
local host name. On Linux, it is the first IP address it finds on an&lt;br /&gt;
interface that is up and is not the loopback interface.&lt;br /&gt;
&lt;br /&gt;
Next it creates a thread (ThreadGetMyExternalIP) to confirm the local IP&lt;br /&gt;
address using 3rd party verification. If using a proxy, it does not&lt;br /&gt;
bother, because it will not take incoming connections.&lt;br /&gt;
&lt;br /&gt;
Next, if Universal Plug and Play is used, then a thread (ThreadMapPort)&lt;br /&gt;
to deal with port mapping is created.&lt;br /&gt;
&lt;br /&gt;
Next it creates a thread (ThreadIRCSeed) to exchange IP addresses.&lt;br /&gt;
&lt;br /&gt;
Next it creates a thread (ThreadSocketHandler) to &amp;quot;Send and receive from&lt;br /&gt;
sockets, accept connections&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Next it creates a thread (ThreadOpenConnections) to initiate outbound&lt;br /&gt;
connections.&lt;br /&gt;
&lt;br /&gt;
Next it creates a thread (ThreadMessageHandler) to process messages.&lt;br /&gt;
&lt;br /&gt;
Finally, if you have specified so, it will start a bitcoin mining thread.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Thread IRCSeed in net.cpp==&lt;br /&gt;
&lt;br /&gt;
Connects to 92.243.23.21 port 6667, JOINs the channel, and then&lt;br /&gt;
reads lines one at a time looking for other users.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Thread ThreadSocketHandler in net.cpp==&lt;br /&gt;
&lt;br /&gt;
Goes into an endless loop servicing sockets that need servicing.&lt;br /&gt;
Handles disconnected nodes.&lt;br /&gt;
Prepares &amp;quot;select&amp;quot; descriptor list and then calls select, waiting for&lt;br /&gt;
I/O on all the relevant sockets with a 50ms timeout.&lt;br /&gt;
Process new incoming connection on listening socket. Create a CNode for them.&lt;br /&gt;
Handle receiving and sending.&lt;br /&gt;
Set sockets that have not done anything to disconnected state.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Thread ThreadOpenConnecions in net.cpp==&lt;br /&gt;
&lt;br /&gt;
Figures out nodes from parameters, seeds, irc, etc, and then goes into a&lt;br /&gt;
loop, connecting to each one by one.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Thread ThreadMessageHandler in net.cpp==&lt;br /&gt;
&lt;br /&gt;
This thread goes through all the nodes and calls ProcessMessages(pnode) in&lt;br /&gt;
main.cpp which looks for valid messages on the node receive&lt;br /&gt;
queue (pFrom-&amp;gt;vRecv) and if it finds one, it calls &lt;br /&gt;
ProcessMessage(CNode* pfrom, string strCommand, CDataStream&amp;amp; vRecv), which&lt;br /&gt;
is also in main.cpp.&lt;br /&gt;
&lt;br /&gt;
Then the thread calls SendMessages for each node (which is in main.cpp)&lt;br /&gt;
which handles creating and sending any messages appropriate for that node.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Thread ThreadRPCServer in rpc.cpp==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This thread will be rather complicated in that it implements an&lt;br /&gt;
HTTP(S)+JSONRPC server using boost classes that are probably going&lt;br /&gt;
to be unfamiliar to most developers.&lt;br /&gt;
&lt;br /&gt;
You will see lines like this:&lt;br /&gt;
    acceptor.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));&lt;br /&gt;
&lt;br /&gt;
and this:&lt;br /&gt;
    boost::thread api_caller(ReadHTTP, boost::ref(stream), boost::ref(mapHeaders), boost::ref(strRequest));&lt;br /&gt;
    if (!api_caller.timed_join(boost::posix_time::seconds(GetArg(&amp;quot;-rpctimeout&amp;quot;, 30))))&lt;br /&gt;
&lt;br /&gt;
It appears the code above is creating a thread in order to apply 30&lt;br /&gt;
second timeout to reading an HTTPrequest.  When HTTP requests are&lt;br /&gt;
read, they are parsed, and then a routine corresponding to the&lt;br /&gt;
request command name is called to handle the request. This happens&lt;br /&gt;
in a loop until shutdown.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:Technical]]&lt;/div&gt;</summary>
		<author><name>Wickrick22</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Satoshi_Client_Transaction_Exchange&amp;diff=16794</id>
		<title>Satoshi Client Transaction Exchange</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Satoshi_Client_Transaction_Exchange&amp;diff=16794"/>
		<updated>2011-09-17T21:38:40Z</updated>

		<summary type="html">&lt;p&gt;Wickrick22: Initial stub&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{stub}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:Technical]]&lt;/div&gt;</summary>
		<author><name>Wickrick22</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Satoshi_Client_Block_Exchange&amp;diff=16793</id>
		<title>Satoshi Client Block Exchange</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Satoshi_Client_Block_Exchange&amp;diff=16793"/>
		<updated>2011-09-17T21:38:27Z</updated>

		<summary type="html">&lt;p&gt;Wickrick22: Initial stub&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{stub}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:Technical]]&lt;/div&gt;</summary>
		<author><name>Wickrick22</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Satoshi_Client_Sockets_and_Messages&amp;diff=16792</id>
		<title>Satoshi Client Sockets and Messages</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Satoshi_Client_Sockets_and_Messages&amp;diff=16792"/>
		<updated>2011-09-17T21:38:16Z</updated>

		<summary type="html">&lt;p&gt;Wickrick22: Created page with &amp;quot;{{stub}}  Category:Developer Category:Technical&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{stub}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:Technical]]&lt;/div&gt;</summary>
		<author><name>Wickrick22</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Satoshi_Client_Node_Connectivity&amp;diff=16791</id>
		<title>Satoshi Client Node Connectivity</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Satoshi_Client_Node_Connectivity&amp;diff=16791"/>
		<updated>2011-09-17T21:38:07Z</updated>

		<summary type="html">&lt;p&gt;Wickrick22: Initial stub&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{stub}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:Technical]]&lt;/div&gt;</summary>
		<author><name>Wickrick22</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Satoshi_Client_Node_Discovery&amp;diff=16790</id>
		<title>Satoshi Client Node Discovery</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Satoshi_Client_Node_Discovery&amp;diff=16790"/>
		<updated>2011-09-17T21:37:09Z</updated>

		<summary type="html">&lt;p&gt;Wickrick22: Initial stub&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{stub}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:Technical]]&lt;/div&gt;</summary>
		<author><name>Wickrick22</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Satoshi_Client_Initialization_and_Startup&amp;diff=16789</id>
		<title>Satoshi Client Initialization and Startup</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Satoshi_Client_Initialization_and_Startup&amp;diff=16789"/>
		<updated>2011-09-17T21:36:17Z</updated>

		<summary type="html">&lt;p&gt;Wickrick22: Initial stub&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{stub}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:Technical]]&lt;/div&gt;</summary>
		<author><name>Wickrick22</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Bitcoind&amp;diff=16788</id>
		<title>Bitcoind</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Bitcoind&amp;diff=16788"/>
		<updated>2011-09-17T21:28:41Z</updated>

		<summary type="html">&lt;p&gt;Wickrick22: Added Theory of Operation. (The dead links will be populated right away.)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:Bitcoin Original Client.png|thumb|350px|right|The bitcoin original client]]&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;Original Bitcoin client&#039;&#039;&#039; is the first [[bitcoin]] client in the network&#039;s history. It is also the official client of the bitcoin project. It&#039;s available under the [http://www.opensource.org/licenses/mit-license.php MIT license] for Windows, 32 and 64-bit GNU/Linux-based OSes and Mac OS X.&lt;br /&gt;
&lt;br /&gt;
The client comes with two executables, a GUI and an command line interface (CLI).&lt;br /&gt;
&lt;br /&gt;
== Executables ==&lt;br /&gt;
See [[Running_Bitcoin|running bitcoin]] for more detail and an example of the configuration file.&lt;br /&gt;
=== Bitcoin (GUI) ===&lt;br /&gt;
&lt;br /&gt;
The bitcoin GUI provides an easy to use wxWidgets-based interface. It allows to send coins and to monitor:&lt;br /&gt;
* transactions from and to the opened wallet&lt;br /&gt;
* block creations&lt;br /&gt;
* confirmations of transactions&lt;br /&gt;
* balance of the wallet&lt;br /&gt;
&lt;br /&gt;
=== Bitcoind (CLI) ===&lt;br /&gt;
&lt;br /&gt;
Bitcoind is both a headless daemon and a client for the same daemon.  It also provides a JSON-RPC interface, allowing it to be controlled locally (via bitcoind or another CLI client) or remotely.  [[Original Bitcoin client/API Calls list|Various commands]] are made available by the API.&lt;br /&gt;
&lt;br /&gt;
To use locally, first start the program in daemon mode:&lt;br /&gt;
:bitcoind -daemon&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then you can use the same program to execute [[Original Bitcoin client/API Calls list|API commands]], e.g.:&lt;br /&gt;
:bitcoind listreceivedbyaddress 0 true&lt;br /&gt;
:bitcoind getbalance&lt;br /&gt;
&lt;br /&gt;
To stop the bitcoin daemon, execute:&lt;br /&gt;
:bitcoind stop&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
&lt;br /&gt;
* Version 0.3.24 was released for all supported platforms on July 8th, 2011 &amp;lt;ref&amp;gt;[http://forum.bitcoin.org/index.php?topic=27187.0 Bitcoin version 0.3.24 released]&amp;lt;/ref&amp;gt;.&lt;br /&gt;
* Version 0.3.23 was released for all supported platforms on June 13th, 2011 &amp;lt;ref&amp;gt;[http://forum.bitcoin.org/index.php?topic=16553.0 Bitcoin version 0.3.23 released]&amp;lt;/ref&amp;gt;.&lt;br /&gt;
* Version 0.3.22 was released for all supported platforms on May 19th, 2011 &amp;lt;ref&amp;gt;[http://forum.bitcoin.org/index.php?topic=8894.0 Version 0.3.22]&amp;lt;/ref&amp;gt;.&lt;br /&gt;
* Version 0.3.20 was released for all supported platforms on February 21st, 2011&amp;lt;ref&amp;gt;[http://www.bitcoin.org/smf/index.php?topic=3704.0 Version 0.3.20]&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Theory of Operation==&lt;br /&gt;
&lt;br /&gt;
Satoshi&#039;s Original Bitcoin client is a multithreaded C++ program. It is designed to be portable across Windows, Mac, and Linux systems. The multithreaded aspect leads to some complexity and the use of certain code patterns to deal with concurrency that may be unfamiliar to many programmers. Also, the code is aggressive in the use of C++ constructs, so it will help to be fluent with map, multmap, set, string, vector, iostream, and templates. As typical of a C++ program, l a lot of code tends to end up in the header files so be sure to search both the .cpp and .h files when looking for a function.&lt;br /&gt;
&lt;br /&gt;
The client is oriented around several major operations, which are described in separate detailed articles and summarized in the following sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===[[Satoshi Client Initialization and Startup|Initialization and Startup]]===&lt;br /&gt;
Upon startup, the client performs various initilization routines including starting multiple threads to handle concurrent operations.&lt;br /&gt;
&lt;br /&gt;
===[[Satoshi Client Node Discovery|Node Discovery]]===&lt;br /&gt;
The client uses various techniques find out about other bitcoin nodes that may exist.&lt;br /&gt;
&lt;br /&gt;
===[[Satoshi Client Node Connectivity|Node Connectivity]]===&lt;br /&gt;
The client initiates and maintains connections to other nodes.&lt;br /&gt;
&lt;br /&gt;
===[[Satoshi Client Sockets and Messages|Sockets and Messages]]===&lt;br /&gt;
The client processes messages from other nodes and sends messages to other nodes using socket connections.&lt;br /&gt;
&lt;br /&gt;
===[[Satoshi Client Block Exchange|Block Exchange]]===&lt;br /&gt;
Nodes advertise their inventory of blocks to each other and exchange blocks to build block chains.&lt;br /&gt;
&lt;br /&gt;
===[[Satoshi Client Transaction Exchange|Transaction Exchange]]===&lt;br /&gt;
Nodes exchange and relay transactions with each other. The client associates transactions with bitcoin addresses in the local wallet.&lt;br /&gt;
&lt;br /&gt;
===[[Satoshi Client Wallet Services|Wallet Services]]===&lt;br /&gt;
The client can create transactions using the local wallet. The client associates transactions with bitcoin addresses in the local wallet. The client provides a service for managing the local wallet.&lt;br /&gt;
&lt;br /&gt;
===[[Satoshi Client RPC Interface|RPC Interface]]===&lt;br /&gt;
The client offers an JSON-RPC interface over HTTP over sockets to perform various operational functions and to manage the local wallet.&lt;br /&gt;
&lt;br /&gt;
===User Interface===&lt;br /&gt;
The user interface code is currently based on [http://www.wxwidgets.org wxWidgets] and is scheduled to be superseded by [[Bitcoin-qt]] in version 0.5.0. &lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
&lt;br /&gt;
* [[Original Bitcoin client/API calls list]]&lt;br /&gt;
* [[Protocol specification|Bitcoin network protocol]]&lt;br /&gt;
* [[Development process]]&lt;br /&gt;
* [[Changelog]]&lt;br /&gt;
&lt;br /&gt;
==External Links==&lt;br /&gt;
* [http://sourceforge.net/projects/bitcoin/ Bitcoin Client project on SourceForge]&lt;br /&gt;
* [https://github.com/bitcoin/bitcoin/ Bitcoin Client project on Github]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Nodes]]&lt;br /&gt;
[[Category:Wallets]]&lt;br /&gt;
[[Category:User Interfaces]]&lt;br /&gt;
[[Category:Clients]]&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Free Software]]&lt;br /&gt;
[[Category:License/MIT-X11]]&lt;br /&gt;
[[Category:Open Source]]&lt;/div&gt;</summary>
		<author><name>Wickrick22</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Controlled_supply&amp;diff=14896</id>
		<title>Controlled supply</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Controlled_supply&amp;diff=14896"/>
		<updated>2011-08-13T23:20:00Z</updated>

		<summary type="html">&lt;p&gt;Wickrick22: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
In a centralized economy, currency is issued by a central bank, at a rate &lt;br /&gt;
that is supposed to match the growth of the amount of physical goods that &lt;br /&gt;
are exchanged, so that these goods can be traded with stable prices. The &lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Money_supply money supply]&amp;lt;/span&amp;gt; is controlled by a central bank through &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Open_market_operations Open Market Operations]&amp;lt;/span&amp;gt;. In the United States, the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Federal_Reserve_System Fed]&amp;lt;/span&amp;gt; sets the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Federal_Funds_Rate Federal Funds]&amp;lt;/span&amp;gt; rate, and more recently, prints money electronically in a process called &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Quantitative_easing Quantitative Easing]&amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In a fully decentralized monetary system, there is no central authority that regulates the amount of currency in circulation. Instead, currency is created by the nodes of a peer-to-peer network. The Bitcoin generation algorithm defines, in advance, how currency will be created and at what rate. Any currency that is generated by a malicious user that does not follow the rules will be rejected by the network and thus is worthless.&lt;br /&gt;
&lt;br /&gt;
==Currency with Finite Supply==&lt;br /&gt;
&lt;br /&gt;
[[File:total_bitcoins_over_time_graph.png|thumb|Number of bitcoins over time]]&lt;br /&gt;
&lt;br /&gt;
Bitcoins are created each time a user discovers a new [[block]]. &lt;br /&gt;
The rate of block creation is approximately constant over time: 6 per hour. The &lt;br /&gt;
number of Bitcoins generated per block is set to decrease geometrically, with a 50% reduction every 4 years. The result is that the number of Bitcoins in existence will &lt;br /&gt;
never exceed 21 million&amp;lt;ref&amp;gt;[http://www.bitcoin.org/smf/index.php?topic=3366.msg47522#msg47522 21 million cap]&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Projected Bitcoins Short Term ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!    Block!!Reward Era!!   BTC/block!!    Year!!         Start BTC!!         BTC Added!!           End BTC!!    BTC Increase|| End BTC % of Limit&lt;br /&gt;
|-&lt;br /&gt;
|0||1||50.00||2009||0||2625000||2625000||infinite||12.500%&lt;br /&gt;
|-&lt;br /&gt;
|52500||1||50.00||2010||2625000||2625000||5250000||100.00%||25.000%&lt;br /&gt;
|-&lt;br /&gt;
|105000||1||50.00||2011||5250000||2625000||7875000||50.00%||37.500%&lt;br /&gt;
|-&lt;br /&gt;
|157500||1||50.00||2012||7875000||2625000||10500000||33.33%||50.000%&lt;br /&gt;
|-&lt;br /&gt;
|210000||2||25.00||2013||10500000||1312500||11812500||12.50%||56.250%&lt;br /&gt;
|-&lt;br /&gt;
|262500||2||25.00||2014||11812500||1312500||13125000||11.11%||62.500%&lt;br /&gt;
|-&lt;br /&gt;
|315000||2||25.00||2015||13125000||1312500||14437500||10.00%||68.750%&lt;br /&gt;
|-&lt;br /&gt;
|367500||2||25.00||2016||14437500||1312500||15750000||9.09%||75.000%&lt;br /&gt;
|-&lt;br /&gt;
|420000||3||12.50||2017||15750000||656250||16406250||4.17%||78.125%&lt;br /&gt;
|-&lt;br /&gt;
|472500||3||12.50||2018||16406250||656250||17062500||4.00%||81.250%&lt;br /&gt;
|-&lt;br /&gt;
|525000||3||12.50||2019||17062500||656250||17718750||3.85%||84.375%&lt;br /&gt;
|-&lt;br /&gt;
|577500||3||12.50||2020||17718750||656250||18375000||3.70%||87.500%&lt;br /&gt;
|-&lt;br /&gt;
|630000||4||6.25||2021||18375000||328125||18703125||1.79%||89.063%&lt;br /&gt;
|-&lt;br /&gt;
|682500||4||6.25||2022||18703125||328125||19031250||1.75%||90.625%&lt;br /&gt;
|-&lt;br /&gt;
|735000||4||6.25||2023||19031250||328125||19359375||1.72%||92.188%&lt;br /&gt;
|-&lt;br /&gt;
|787500||4||6.25||2024||19359375||328125||19687500||1.69%||93.750%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Projected Bitcoins Long Term ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!    Block!!Reward Era!!   BTC/block!!    Year!!         Start BTC!!         BTC Added!!           End BTC!!    BTC Increase||  End BTC % of Limit&lt;br /&gt;
|-&lt;br /&gt;
|        0||  1|| 50.00000000||2009.007||        0.00000000|| 10500000.00000000|| 10500000.00000000||        infinite||       50.00000006%&lt;br /&gt;
|-&lt;br /&gt;
|   210000||  2|| 25.00000000||2013.000|| 10500000.00000000||  5250000.00000000|| 15750000.00000000||    50.00000000%||       75.00000008%&lt;br /&gt;
|-&lt;br /&gt;
|   420000||  3|| 12.50000000||2016.993|| 15750000.00000000||  2625000.00000000|| 18375000.00000000||    16.66666667%||       87.50000010%&lt;br /&gt;
|-&lt;br /&gt;
|   630000||  4||  6.25000000||2020.986|| 18375000.00000000||  1312500.00000000|| 19687500.00000000||     7.14285714%||       93.75000010%&lt;br /&gt;
|-&lt;br /&gt;
|   840000||  5||  3.12500000||2024.978|| 19687500.00000000||   656250.00000000|| 20343750.00000000||     3.33333333%||       96.87500011%&lt;br /&gt;
|-&lt;br /&gt;
|  1050000||  6||  1.56250000||2028.971|| 20343750.00000000||   328125.00000000|| 20671875.00000000||     1.61290323%||       98.43750011%&lt;br /&gt;
|-&lt;br /&gt;
|  1260000||  7||  0.78125000||2032.964|| 20671875.00000000||   164062.50000000|| 20835937.50000000||     0.79365079%||       99.21875011%&lt;br /&gt;
|-&lt;br /&gt;
|  1470000||  8||  0.39062500||2036.956|| 20835937.50000000||    82031.25000000|| 20917968.75000000||     0.39370079%||       99.60937511%&lt;br /&gt;
|-&lt;br /&gt;
|  1680000||  9||  0.19531250||2040.949|| 20917968.75000000||    41015.62500000|| 20958984.37500000||     0.19607843%||       99.80468761%&lt;br /&gt;
|-&lt;br /&gt;
|  1890000|| 10||  0.09765625||2044.942|| 20958984.37500000||    20507.81250000|| 20979492.18750000||     0.09784736%||       99.90234386%&lt;br /&gt;
|-&lt;br /&gt;
|  2100000|| 11||  0.04882812||2048.934|| 20979492.18750000||    10253.90520000|| 20989746.09270000||     0.04887585%||       99.95117198%&lt;br /&gt;
|-&lt;br /&gt;
|  2310000|| 12||  0.02441406||2052.927|| 20989746.09270000||     5126.95260000|| 20994873.04530000||     0.02442599%||       99.97558604%&lt;br /&gt;
|-&lt;br /&gt;
|  2520000|| 13||  0.01220703||2056.920|| 20994873.04530000||     2563.47630000|| 20997436.52160000||     0.01221001%||       99.98779307%&lt;br /&gt;
|-&lt;br /&gt;
|  2730000|| 14||  0.00610351||2060.913|| 20997436.52160000||     1281.73710000|| 20998718.25870000||     0.00610426%||       99.99389658%&lt;br /&gt;
|-&lt;br /&gt;
|  2940000|| 15||  0.00305175||2064.905|| 20998718.25870000||      640.86750000|| 20999359.12620000||     0.00305194%||       99.99694833%&lt;br /&gt;
|-&lt;br /&gt;
|  3150000|| 16||  0.00152587||2068.898|| 20999359.12620000||      320.43270000|| 20999679.55890000||     0.00152592%||       99.99847420%&lt;br /&gt;
|-&lt;br /&gt;
|  3360000|| 17||  0.00076293||2072.891|| 20999679.55890000||      160.21530000|| 20999839.77420000||     0.00076294%||       99.99923713%&lt;br /&gt;
|-&lt;br /&gt;
|  3570000|| 18||  0.00038146||2076.883|| 20999839.77420000||       80.10660000|| 20999919.88080001||     0.00038146%||       99.99961859%&lt;br /&gt;
|-&lt;br /&gt;
|  3780000|| 19||  0.00019073||2080.876|| 20999919.88080001||       40.05330000|| 20999959.93410001||     0.00019073%||       99.99980932%&lt;br /&gt;
|-&lt;br /&gt;
|  3990000|| 20||  0.00009536||2084.869|| 20999959.93410001||       20.02560000|| 20999979.95970001||     0.00009536%||       99.99990468%&lt;br /&gt;
|-&lt;br /&gt;
|  4200000|| 21||  0.00004768||2088.861|| 20999979.95970001||       10.01280000|| 20999989.97250001||     0.00004768%||       99.99995236%&lt;br /&gt;
|-&lt;br /&gt;
|  4410000|| 22||  0.00002384||2092.854|| 20999989.97250001||        5.00640000|| 20999994.97890001||     0.00002384%||       99.99997620%&lt;br /&gt;
|-&lt;br /&gt;
|  4620000|| 23||  0.00001192||2096.847|| 20999994.97890001||        2.50320000|| 20999997.48210001||     0.00001192%||       99.99998812%&lt;br /&gt;
|-&lt;br /&gt;
|  4830000|| 24||  0.00000596||2100.840|| 20999997.48210001||        1.25160000|| 20999998.73370001||     0.00000596%||       99.99999408%&lt;br /&gt;
|-&lt;br /&gt;
|  5040000|| 25||  0.00000298||2104.832|| 20999998.73370001||        0.62580000|| 20999999.35950001||     0.00000298%||       99.99999706%&lt;br /&gt;
|-&lt;br /&gt;
|  5250000|| 26||  0.00000149||2108.825|| 20999999.35950001||        0.31290000|| 20999999.67240001||     0.00000149%||       99.99999855%&lt;br /&gt;
|-&lt;br /&gt;
|  5460000|| 27||  0.00000074||2112.818|| 20999999.67240001||        0.15540000|| 20999999.82780001||     0.00000074%||       99.99999929%&lt;br /&gt;
|-&lt;br /&gt;
|  5670000|| 28||  0.00000037||2116.810|| 20999999.82780001||        0.07770000|| 20999999.90550001||     0.00000037%||       99.99999966%&lt;br /&gt;
|-&lt;br /&gt;
|  5880000|| 29||  0.00000018||2120.803|| 20999999.90550001||        0.03780000|| 20999999.94330001||     0.00000018%||       99.99999984%&lt;br /&gt;
|-&lt;br /&gt;
|  6090000|| 30||  0.00000009||2124.796|| 20999999.94330001||        0.01890000|| 20999999.96220000||     0.00000009%||       99.99999993%&lt;br /&gt;
|-&lt;br /&gt;
|  6300000|| 31||  0.00000004||2128.788|| 20999999.96220000||        0.00840000|| 20999999.97060001||     0.00000004%||       99.99999997%&lt;br /&gt;
|-&lt;br /&gt;
|  6510000|| 32||  0.00000002||2132.781|| 20999999.97060001||        0.00420000|| 20999999.97480001||     0.00000002%||       99.99999999%&lt;br /&gt;
|-&lt;br /&gt;
|  6720000|| 33||  0.00000001||2136.774|| 20999999.97480001||        0.00210000|| 20999999.97690000||     0.00000001%||      100.00000000%&lt;br /&gt;
|-&lt;br /&gt;
|  6930000|| 34||  0.00000000||2140.767|| 20999999.97690000||        0.00000000|| 20999999.97690000||     0.00000000%||      100.00000000%&lt;br /&gt;
|}&lt;br /&gt;
==Inflation and Deflation==&lt;br /&gt;
&lt;br /&gt;
While the number of bitcoins in existence will never exceed 21 million, the [http://en.wikipedia.org/wiki/Money_supply money supply] of bitcoins can greatly exceed 21 million due to [http://en.wikipedia.org/wiki/Fractional-reserve_banking Fractional-reserve Banking]. So while the limited number of &amp;quot;hard&amp;quot; bitcoins will cause deflation in the long term due to positive non-zero reserve requirements, a fast increase in the money supply due to an adoption of Fractional-reserve banking can cause inflation in the medium term.&lt;br /&gt;
&lt;br /&gt;
Worth noting are the Keynesian economic arguments against [[Deflationary spiral|deflation]]; such that deflation tends to reduce profits and hence provides a dis-incentive for entrepreneurs to continue their operations. The &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Austrian_School Austrian school]&amp;lt;/span&amp;gt; of thought adequately counters this theory, as deflation occurs in all stages of production and entrepreneurs also benefit from it. As a result, profit ratios tend to stay the same, only their magnitudes change. In other words, in a deflationary environment, goods and services decrease in price, but at the same time the cost for the production of these goods and services tend to decrease proportionally, effectively not affecting profits at all.&lt;br /&gt;
&lt;br /&gt;
Price deflation encourages an increase in hoarding - hence savings - which in turn tends to lower interest rates and increase the incentive for entrepreneurs to invest in projects of longer term.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [http://www.econlib.org/library/Columns/y2006/Friedmantranscript.html Milton Friedman interview], where he proposed to replace the central bank with a computer, and to fix the money supply growth at 4% annually&lt;br /&gt;
* [[Deflationary spiral]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Economics]]&lt;/div&gt;</summary>
		<author><name>Wickrick22</name></author>
	</entry>
</feed>