Giter Club home page Giter Club logo

btc's Introduction

BitTorrent Client

BitTorrent protocol:

  • BitTorrent is a peer to peer (P2P) protocol, for sharing files.
  • It is based on passing messages directly between peers.

Bencoding:

  • Bencoding is a way to specify and organize data in a terse format. It supports the following types: byte strings, integers, lists, and dictionaries.
  • example: d3:cow3:moo4:spam4:eggse represents the dictionary { "cow" => "moo", "spam" => "eggs" }

Metainfo file structure:

  • All data in a metainfo file is bencoded. The content of a metainfo file (the file ending in ".torrent") is a bencoded dictionary, containing at least keys listed below.
  • announce url
  • info dictionary

Peer wire protocol

  • Messages:
0 - choke
1 - unchoke
2 - interested
3 - not interested
4 - have
5 - bitfield
6 - request
7 - piece
8 - cancel
  • Besides those, there is one more important message, namely Handshake messake. Handshake is exactly 68 bytes long and consists of <info_hash><peer_id>

    -> always 19, 1 byte -> b"BitTorrent protocol -> 8 reserved bytes. For our purposes always 0. <info_hash> -> 20 byte SHA1 hash value of 'info' key. <peer_id> -> 20 byte string representing unique ID.

Tracker protocol:

  • Tracker is a simple HTTP server that keeps 'track' of the state of the swarm.

  • As a response tracker sends compact byte string which contains all tuples of peer's ip and port.

  • Example tracker http request:

    • /unnounce?info_hash={}&peer_id={}&port={}&uploaded={}&downloaded={}&left={}&event={}&compact=1

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.