9

In version 0.8.6 of Bitcoin, I see that peers.dat file is a custom database format declared in db.h:317 (class CAddrDB) and defined in dh.cpp:485. Any ideas on how I could go about reading the data from peers.dat with PHP or Python? I'd like to keep track of all peers that the bitcoin daemon sees and connects to. Or is there a better way?

1 Answer 1

3

The easiest way to get peer information is via the JSON RPC interface has a command getpeerinfo. Each peer returns a JSON object containing peer IP address info, connection time, version and subversion of the client.

You would probably be interested in this: Bitcoind API

Edit: Although this is not a way to read the database I presume that the data feeding the peers.dat file is pulled from both the IRC channels and the DNS seeds. If you reported data on those nodes, you could use this data in combination with logs from the debug file to perhaps learn how your node discovered its peers.

3
  • Thanks, but that only lists the 8 peers I'm connected to. I know that peers.dat contains a lot more data than that because: 1) it's rather large file (almost 1MB) 2) I see messages like the following in the debug.log: "2013-12-30 03:05:34 Added 1 addresses from xxx.xxx.xxx.xxx: 62 tried, 14738 new"
    – Konstantin
    Dec 30, 2013 at 3:07
  • "peers.dat is a flat file with a bitcoin-specific file format, unrelated to any database system." bitcointalk.org/index.php?topic=119525.msg1287284#msg1287284 looks like unless there's another implementation of it you would have to attempt to rebuild the code in the language you require.
    – Mark S.
    Dec 30, 2013 at 3:12
  • 1
    I also found this: Bitnodes. I will investigate his code and learn from it. Thanks!
    – Konstantin
    Dec 30, 2013 at 4:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.