Coder Social home page Coder Social logo

btc-handshake's Introduction

Bitcoin Handshake

A PoC implementation of the Bitcoin handshake, performed between two nodes. To simplify connecting to nodes, the implementation takes a DNS seed and gets a list of nodes to connect to and perform the handshake, as shown in the diagram below.

sequenceDiagram
    btc-handshake->>DNSSeed: resolve
    DNSSeed->>btc-handshake: peers
    btc-handshake->>Node: version
    Node->>btc-handshake: version
    btc-handshake->>Node: verack
    Node->>btc-handshake: verack
    Node-->>btc-handshake: (other messages)

Description

The code is split into two parts, the library containing the data structures relating to the protocol, and a CLI tool to actually perform the handshake.

Usage

Usage: btc-handshake [OPTIONS] <DNS_SEED>

Arguments:
  <DNS_SEED>  Bitcoin DNS seed domain

Options:
  -p, --port <PORT>        Target's TCP port [default: 8333]
  -t, --timeout <TIMEOUT>  Handshake timeout, in seconds [default: 5]
  -n, --network <NETWORK>  Target network [default: mainnet] [possible values: mainnet, testnet, testnet3, signet]
  -h, --help               Print help

Example

$ btc-handshake seed.bitcoin.sipa.be.

2024-02-22T19:27:28.069121Z  INFO btc_handshake: Resolving DNS seed: seed.bitcoin.sipa.be.:8333
2024-02-22T19:27:28.193436Z  WARN version{network=Mainnet address=88.198.57.103:8333}: btc_handshake: received version (70015) which is lower than the currently implemented one (70012) trying to proceed
2024-02-22T19:27:28.604618Z  WARN verack{network=Mainnet}: btc_handshake: server skipped verack message
2024-02-22T19:27:33.076413Z  WARN btc_handshake: command mismatch: expected verack got Ok("sendcmpct\0\0\0")
2024-02-22T19:27:33.076653Z  WARN btc_handshake: failed to fill whole buffer
2024-02-22T19:27:33.076683Z  WARN btc_handshake: command mismatch: expected verack got Ok("sendcmpct\0\0\0")
2024-02-22T19:27:33.076711Z  WARN btc_handshake: command mismatch: expected verack got Ok("sendheaders\0")
2024-02-22T19:27:33.076736Z  WARN btc_handshake: command mismatch: expected verack got Ok("sendheaders\0")
2024-02-22T19:27:33.076760Z  WARN btc_handshake: command mismatch: expected verack got Ok("sendcmpct\0\0\0")
2024-02-22T19:27:33.076788Z  WARN btc_handshake: command mismatch: expected verack got Ok("sendcmpct\0\0\0")
2024-02-22T19:27:33.076811Z  WARN btc_handshake: command mismatch: expected verack got Ok("sendheaders\0")
2024-02-22T19:27:33.076834Z  WARN btc_handshake: command mismatch: expected verack got Ok("sendcmpct\0\0\0")
2024-02-22T19:27:33.076860Z  WARN btc_handshake: failed to fill whole buffer
2024-02-22T19:27:33.076884Z  WARN btc_handshake: deadline has elapsed
2024-02-22T19:27:33.076904Z  WARN btc_handshake: command mismatch: expected verack got Ok("sendheaders\0")
2024-02-22T19:27:33.076927Z  WARN btc_handshake: command mismatch: expected verack got Ok("sendcmpct\0\0\0")
2024-02-22T19:27:33.077164Z  WARN btc_handshake: command mismatch: expected verack got Ok("sendheaders\0")
2024-02-22T19:27:33.077270Z  WARN btc_handshake: command mismatch: expected verack got Ok("sendcmpct\0\0\0")
2024-02-22T19:27:33.077295Z  WARN btc_handshake: command mismatch: expected verack got Ok("sendheaders\0")
2024-02-22T19:27:33.077318Z  WARN btc_handshake: command mismatch: expected verack got Ok("sendcmpct\0\0\0")
2024-02-22T19:27:33.077342Z  WARN btc_handshake: command mismatch: expected verack got Ok("sendcmpct\0\0\0")
2024-02-22T19:27:33.077366Z  WARN btc_handshake: command mismatch: expected verack got Ok("sendcmpct\0\0\0")
2024-02-22T19:27:33.077390Z  WARN btc_handshake: command mismatch: expected verack got Ok("sendcmpct\0\0\0")
2024-02-22T19:27:33.077506Z  INFO btc_handshake: finished with 5 SUCCESS & 20 FAILED

As we can see, some clients will skip the verack by sending an empty buffer (marked by server skipped verack message), other clients will ignore the verack and start sending other messagess straight away.

DNS Seeds

Here you can find a list of seeds the official Bitcoin node will attempt to resolve. You can find the list on bitcoin/bitcoin.

seed.bitcoin.sipa.be.
dnsseed.bluematt.me.
dnsseed.bitcoin.dashjr.org.
seed.bitcoinstats.com.
seed.bitcoin.jonasschnelli.ch.
seed.btc.petertodd.net.
seed.bitcoin.sprovoost.nl.
dnsseed.emzy.de.
seed.bitcoin.wiz.biz.

btc-handshake's People

Contributors

jmg-duarte avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.