/
main.go
43 lines (38 loc) · 1.05 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"fmt"
"github.com/arberiii/bittorrent-client/client"
"github.com/arberiii/bittorrent-client/peers"
"github.com/arberiii/bittorrent-client/torrent"
"net/http"
)
func main() {
httpClient := &http.Client{}
torrent_, err := torrent.GetTorrentInfoFromFile("torrent/sample.torrent")
if err != nil {
fmt.Println("Failed to get torrent")
return
}
peers_, err := peers.GetTrackingPeers(torrent_, httpClient)
if err != nil {
fmt.Println("Failed to get peers")
return
}
torrentClient := client.TorrentClient{Torrent: torrent_, Peers: peers_}
torrentConnection := torrentClient.DoHandshake(0)
if torrentConnection == nil {
fmt.Println("Failed to establish connection")
return
}
torrentConnection = torrentClient.WriteInterested(torrentConnection)
if torrentConnection == nil {
fmt.Println("Failed to write interested")
return
}
torrentConnection = torrentClient.ReadUnchoke(torrentConnection)
if torrentConnection == nil {
fmt.Println("Failed to read unchoke")
return
}
torrentClient.Download(torrentConnection)
}