8000 GitHub - teshomenbret/dsp_torrent: A torrent cliant implementation in go
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

teshomenbret/dsp_torrent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

[Torrent]

BitTorrent is a peer-to-peer (P2P) file sharing protocol that enables users to distribute and download large files quickly and efficiently. The technology was developed by Bram Cohen in 2001 and has since become one of the most popular methods of sharing files over the internet.

[A torrent cliant implementation in go]

Installation

1 Clone the repository

Using the torrent

---write this command on the terminal

go run main.go debian-edu-11.6.0-amd64-netinst.iso.torrent

some word about BitTorrent

BitTorrent is a peer-to-peer (P2P) file sharing protocol that enables users to distribute and download large files quickly and efficiently. The technology was developed by Bram Cohen in 2001 and has since become one of the most popular methods of sharing files over the internet.

Process in Downloading Torrent file

Parsing a .torrent file

In order to use BitTorrent to download content, you must first obtain a torrent file. This file includes details about the data you want to download and provides information about the location of the tracker. for this assignment we use debian-edu-11.6.0-amd64-netinst.iso torrent downloader. The .torrent file contains metadata for the torrent encoded using Bencode, Bencode is a simple and efficient format that represents data as a series of key-value pairs and uses a compact binary representation.

Get Peers from Tracker

To participate in a BitTorrent swarm and start downloading or sharing content, you need to communicate with a tracker. This is done by sending a GET request to the announce URL specified in the .torrent file, along with some query parameters. The tracker's role is to keep track of all the peers participating in the swarm and to provide the requesting peer with a list of other available peers.

Parsing the tracker response

After sending a GET request to the tracker's announce URL, the tracker will respond with an interval and a list of available peers in the swarm. To be able to use this information for later operations, you will need to parse the response and extract the relevant data.

The interval represents the number of seconds that should elapse before the client sends another request to the tracker. The list of peers contains information about other clients participating in the swarm, such as their IP address, port number, and peer ID.

Downloading from peers(Peer to Peer Communication)

To start downloading pieces from the list of peers provided by the tracker, we need to follow a few steps. For each peer in the list, we will:

1 Initiate a TCP connection with the peer.

2 Perform a two-way BitTorrent handshake with the peer to establish a connection. This handshake includes sending and receiving information about the client's capabilities, such as the BitTorrent protocol version and supported extensions.

3 Exchange messages with the peer to request and download pieces. This involves sending messages that specify which pieces are needed and receiving messages that contain the actual data. The peer will also request pieces from the client in exchange.

Handshake

After establishing a TCP connection with a peer, it's important to perform a BitTorrent handshake to validate certain assumptions about the peer. The handshake process serves several purposes:

1 Verify that the peer can communicate using the BitTorrent protocol: By exchanging handshake messages, both parties can confirm that they are speaking the same protocol and that they can understand each other's messages.

2 Confirm that the peer is able to understand and respond to our messages: The handshake also allows both parties to negotiate the specifics of the data transfer, such as the size of the pieces being exchanged and the order in which they will be requested.

3 Verify that the peer has the desired content, or at least knows what we're talking about: By exchanging information about the content being shared, both parties can confirm that they are talking about the same file and that the peer actually has the desired content available.

Performing a BitTorrent handshake with a peer involves exchanging a set of five key parameters, which include:

1 Length of the protocol identifier: This parameter is always 19 bytes long (0x13 in hex) and serves as a fixed-length identifier for the protocol being used.

2 Protocol identifier (pstr): This is always "BitTorrent protocol" and identifies the specific version of the BitTorrent protocol being used.

3 Reserved bytes: These are eight bytes that are reserved for future use and are currently set to 0. Some of these bytes can be flipped to 1 to indicate support for certain extensions, but since we do not support any extensions, we will keep them at 0.

4 Infohash: This is the hash value that was calculated earlier to identify the specific file being requested.

5 Peer ID: This is a unique identifier that is generated by the client to identify itself to other peers in the swarm.

By performing a handshake with each peer in the swarm, you can ensure that you are communicating effectively and efficiently with other participants and maximize your chances of successfully downloading the desired content.

Send and receive messages

After completing the initial handshake with a peer, both parties can begin exchanging messages. However, it's important to note that one peer may not be ready to receive messages immediately after the handshake. In this state, the other peer is considered "choked", meaning that it's not yet ready to exchange data.

To initiate data exchange, the choked peer must send an unchoke message to indicate that it's ready to receive messages. By default, we assume that we're choked until we receive an unchoke message from the other peer.

Once unchoked, we can then begin sending requests for specific pieces of the shared file, and the other peer can respond with messages containing those pieces. This process continues until all pieces have been exchanged and the file is complete. By exchanging data in this way, BitTorrent allows for efficient and decentralized distribution of large files across a network of peers.

About

A torrent cliant implementation in go

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0