MyNixOS website logo
Description

A concurrent bittorrent client.

HaskellTorrent provides a BitTorrent client, based on the CML library for concurrency. This is an early preview release which is capable of downloading files from various torrent trackers, but have not yet demonstrated to be correct in all aspects. It is expected that the package currently contains numerous and even grave bugs. Patches to fix any problem are welcome!

Haskell Torrent - a haskell bittorrent client.

Introduction

This is a Haskell bittorrent client. I am the introduction document and I need to be written by some generous soul!

Installation

Here is what I do to install haskell torrrent locally on my machine:

cabal install --prefix=$HOME --user

Since we are using the magnificient cabal, this is enough to install haskell torrent in our $HOME/bin directory.

Usage

Haskell torrent can currently only do one very simple thing. If you call it with

HaskellTorrent foo.torrent

then it will begin downloading the file in foo.torrent to the current directory via the Bittorrent protocol. Note: Currently we have no support for multifile torrents.

Protocol support

Currently haskell-torrent supports the following BEPs (See the BEP Process document for an explanation of these)

  • 004, 020,

Haskell-torrent is not supporting these BEPs, but strives to do so one day:

  • 003, 005, 006, 007, 010, 012, 015, 009, 023, 018, 021, 022, 024, 026, 027, 028, 029, 030, 031, 032

Haskell-torrent will probably never support these BEPs:

  • 016, 017, 019

Debugging

For debugging, jlouis tends to use the following:

make conf build test

This builds HaskellTorrent with the Debug flag set and also builds the software with profiling by default so it is easy to hunt down performance regressions. It also runs the internal test-suite for various values.

Reading material for hacking HaskellTorrent:

  • Protocol specification - BEP0003: This is the original protocol specification, tracked into the BEP process. It is worth reading because it explains the general overview and the precision with which the original protocol was written down.

  • Bittorrent Enhancement Process - BEP0000 The BEP process is an official process for adding extensions on top of the BitTorrent protocol. It allows implementors to mix and match the extensions making sense for their client and it allows people to discuss extensions publicly in a forum. It also provisions for the deprecation of certain features in the long run as they prove to be of less value.

  • wiki.theory.org An alternative description of the protocol. This description is in general much more detailed than the BEP structure. It is worth a read because it acts somewhat as a historic remark and a side channel. Note that there are some commentary on these pages which can be disputed quite a lot.

  • "Concurrent Programming in ML" - John. H. Reppy This book describes the CML system which HaskellTorrent uses. The basic idea of CML is that of higher order events. That is, events which can be abstractly manipulated before being synchronized on. For instance, CML events are a Functor instance, though the code currently does not reflect that. This also provisions for fair selective receives with dynamic choice of which events may fire.

  • "A Concurrent ML library in Concurrent Haskell" - Avik Chaudhuri, ICFP 2009 The paper behind the CML library which HaskellTorrent uses. It describes a way to transform the first-order MVar and ForkIO structures of concurrent haskell into a higher order CML language by use of a clever matchmaking algorithm.

  • "Supervisor Behaviour" From the Erlang documentation. How the Erlang Supervisor behaviour works. The Supervisor and process structure of HaskellTorrent is somewhat inspired by the Erlang ditto.

Source code Hierarchy

  • Data: Data structures.

    • Queue: Functional queues. Standard variant with two lists.
  • Process: Process definitions for the different processes comprising Haskell Torrent

    • ChokeMgr: Manages choking and unchoking of peers, based upon the current speed of the peer and its current state. Global for multiple torrents.
    • Console: Simple console process. Only responds to 'quit' at the moment.
    • FS: Process managing the file system.
    • Listen: Not used at the moment. Step towards listening sockets.
    • Peer: Several process definitions for handling peers. Two for sending, one for receiving and one for controlling the peer and handle the state.
    • PeerMgr: Management of a set of peers for a single torrent.
    • PieceMgr: Keeps track of what pieces have been downloaded and what are missing. Also hands out blocks for downloading to the peers.
    • Status: Keeps track of uploaded/downloaded/left bytes for a single torrent. Could be globalized.
    • Timer: Timer events.
    • Tracker: Communication with the tracker.
  • Protocol: Modules for interacting with the various bittorrent protocols.

    • BCode: The bittorrent BCode coding. Used by several protocols.
    • Wire: The protocol used for communication between peers.
  • Top Level:

    • Digest: SHA1 digests as used in the bittorrent protocol.
    • FS: Low level Filesystem code. Interacts with files.
    • HaskellTorrent: Main entry point to the code. Sets up processes.
    • Logging: Logging interface.
    • LoggingTypes: Types and instances used by the Logging framework.
    • PeerTypes: Types used by peers.
    • Process: Code for Erlang-inspired processes.
    • RateCalc: Rate calculations for a network socket. We use this to keep track of the current speed of a peer in one direction.
    • Supervisor: Erlang-inspired Supervisor processes.
    • Torrent: Various helpers and types for Torrents.
    • Version.hs.in: Generates Version.hs via the configure script.
    • Test.hs: Code for test-framework
    • TestInstance.hs: Various helper instances not present in the test framework by default

Known bugs

"PieceMgrP"(Fatal):	Process exiting due to ex: user error (P/Blk (655,Block {blockOffset = 81920, blockSize = 16384}) is in the HaveBlocks set)
"ConsoleP"(Info):	Process Terminated by Supervisor

vim: filetype=none tw=76 expandtab.

Metadata

Version

0.1.1

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows