Code Monkey home page Code Monkey logo

bencode-torrent's Introduction

BEncode Torrent

PHP library for encoding and decoding BitTorrent BEncode data, focused around Gazelle.

BEncode is the encoding used by BitTorrent to store and transmitting loosely structured data. It supports

  • byte strings
  • integers
  • lists
  • dictionaries (associative arrays, where keys are sorted alphabetically)

You can see more information about how these types are supported at BitTorrentSpecification#Bencoding.

In addition to the above, torrent files are expected to be BEncoded dictionaries that contain minimally the keys announce (byte string) and info (dictionary). Within the info dictionary, we then expect piece length (integer) and pieces (byte string). If the torrent has only a single file, we then expect name (byte string) and length (integer), whereas for a multi-file torrent, we'll have name (byte string) and files (list) where each element is a dictionary that has the keys length (integer) and path (list of strings).

As such, this library will make some checks when loading data that these mandatory fields exist or else an Exception is raised. More information on these fields can be found at BitTorrentSpecification#Metainfo_File_Structure.

Finally, this library is primarily aimed at being used within the Gazelle so we have some utility functions within the library that make sense there to accomplish the following things:

  • Ensuring torrent files are marked as 'private'
  • Setting a 'source' on torrents (to ensure unique info hash)
  • Cleaning out unnecessary fields that also reveal stuff about a user (like announce list and created by)
  • Generate string file lists as expected by Gazelle for display

This is based (loosely) off the code in the two separate BEncode libraries within WCD's Gazelle (bencodetorrent.class.php and torrent.class.php), but without the necessary 32bit shims as well as make it a unified library used for both uploading and downloading the torrent files.

bencode-torrent's People

Watchers

James Cloos 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.