bitcoin 接続事始め

前回は bitcoin で通信を始める時のピアを得る方法を学びました。

kawachi.hatenablog.com

今回は通信してみたいと思います。

接続するとまず最初に version 番号を交換することになっているようです。 人に出会ったらまず挨拶をしましょうということですね。

今回は、DNS から得た seed peer に接続して、version メッセージを送って、version メッセージを受け取ってみます。

バイナリフォーマットのメッセージですが、scodec という便利ライブラリの bitcoin ようメッセージを定義している bitcoin-scodec というのがあったので、使ってみました。

github.com

適当に書いたコードがこれです。

github.com

受け取った version を最後に集計してみました。 DNS で返される peer の seed node 群は代表的な bitcoin プログラムが動作していると予想されます。

gist1a241b14b083c087400d

Satoshi というのが githubbitcoin/bitcoin ぽいですね。 ここで設定されているのが見えます。

bitcoin/clientversion.cpp at ad57b310bac44a7e470cf66276421f2bbc61b1f0 · bitcoin/bitcoin · GitHub

version は 0.9.1 から 0.11.99 までレポートされていますが、大半が Satoshi でした。

Bitcoin XT というのはこれのことかな。

bitcoinxt.software

Bitcoin XT is an implementation of a Bitcoin full node that embraces Bitcoin's original vision of simple, reliable, low-cost transactions for everyone in the world. It is based upon the source code of Bitcoin Core, and is built by taking the latest stable Core release, applying a series of patches, and then doing deterministic builds so anyone can check the downloads correspond to the source code.

あとは /Satoshi:0.11.1/ljr:20150921/ というのも見えます。 Bitcoin LJR のことですかね。

Bitcoin LJR is a fork of Bitcoin Core (since 2011 December) with a collection of improvements maintained out of the master git tree. It comes in a "functional" flavour with only improvements to the software itself, and a "combined" flavour which also includes enhancements to relay and mining policy code.

peer から順にたどっていけば他のノードにアクセスできるので、全ノードのシェアもある程度簡単に集計できそうですね。