/torronto

BitTorrent client in Go

Primary LanguageGo

torronto - A BitTorrent Implementation in Go

Torronto Messaging Documentation

Using json for data interchange

Each message is a header with some max size

Interface Actions

  Join   = 0
  Leave  = 1
  Insert = 2
  Query  = 3

Peer Actions

  Add      = 4
  Remove   = 5
  Files    = 6
  Download = 7
  Upload   = 8
  Have     = 9

Error Codes

  ErrOK            = 0
  ErrConnected     = 1
  ErrDisconnected  = 2
  ErrFileExists    = 3
  ErrFileMissing   = 4
  ErrBadPermission = 5

Interface Messaging

We tell the peer to join the network.

Joining network

{
  "HostName": "<HostName>",
  "PortNumber": "<PortNumber>",
  "Action": 0,
}

We tell the peer to leave the network

Leaving network

{
  "HostName": "<HostName>",
  "PortNumber": "<PortNumber>",
  "Action": 1
}

Giving the peer the path to a file to insert

Inserting a file

{
  "HostName": "<HostName>",
  "PortNumber": "<PortNumber>",
  "Action": 2,
  "Files":
    [
      {
        "FileName": "<FileName>",
      }
    ]
}

We tell the peer to leave the network

Querying status

{
  "HostName": "<HostName>",
  "PortNumber": "<PortNumber>",
  "Action": 3
}

The peers responds with a status json object

Response to a query

{
  "numFiles": <numFiles>,
  "local": [<frActionPresentLocally>, <frActionPresentLocally>, ...],
  "system": [<frActionPresent>, <frActionPresent>, ...],
  "leastReplication": [<minimumReplicationLevel>, <minimumReplicationLevel>, ...],
  "weightedLeastReplication": [<averageReplicationLevel>, <averageReplicationLevel>, ...]
}

Peer Messaging

When a joins the network, it send out a message that it's joining and a list of its Files.

Joining network

{
  "HostName": "<HostName>",
  "PortNumber": "<PortNumber>",
  "Action": 4,
}

This is followed by the file list

{
  "Files":
    [
      {
        "file": "<FileName>",
        "chunks": "[<chunkNumber>, <chunkNumber>, ...]"
      },
      {
        "file": "<FileName>",
        "chunks": "[<chunkNumber>, <chunkNumber>, ...]"
      }, ...
    ]
}

Leaving network

{
  "HostName": "<HostName>",
  "PortNumber": "<PortNumber>",
  "Action": 5
}

The peers respond with a file list.

Returning file list

{
  "HostName": "<HostName>",
  "PortNumber": "<PortNumber>",
  "Action": 6,
}

This is followed by the file list

{
  "Files":
    [
      {
        "FileName": "<FileName>",
        "chunks": "[<chunkNumber>, <chunkNumber>, ...]"
      },
      {
        "FileName": "<FileName>",
        "chunks": "[<chunkNumber>, <chunkNumber>, ...]"
      }, ...
    ]
}

Each peer will then update the status of the Files it has, and send out requests to download the Files it doesn't have

Request to download Files

{
  "HostName": "<HostName>",
  "PortNumber": "<PortNumber>",
  "Action": 7,
  "Files":
    [
      {
        "FileName": "<FileName>",
        "chunks": [<Filesize>, <chunkNumber>]
      }
    ]
}

Sending a file chunk (this is followed by the payload)

{
  "HostName": "<HostName>",
  "PortNumber": "<PortNumber>",
  "Action": 8,
  "Files":
    [
      {
        "FileName": "<FileName>",
        "chunks": [<Filesize>, <chunkNumber>]
      }
    ]
}

Peer messages whenever it receives a new chunk

Have a new file

{
  "HostName": "<HostName>",
  "PortNumber": "<PortNumber>",
  "Action": 9,
  "Files":
    [
      {
        "FileName": "<FileName>",
        "chunks": [<Filesize>, <chunkNumber>]
      }
    ]
}