-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (44 loc) · 1.01 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
44
45
46
47
48
49
50
51
52
package main
import (
"io/ioutil"
"log"
"net"
"os"
"github.com/chandlerswift/femtotorrent/libfemtotorrent/peer"
"github.com/chandlerswift/femtotorrent/libfemtotorrent/torrentfile"
"github.com/chandlerswift/femtotorrent/libfemtotorrent/tracker"
)
func main() {
file, err := os.Open("debian-11.2.0-amd64-netinst.iso.torrent")
if err != nil {
log.Fatal(err)
}
defer file.Close()
b, err := ioutil.ReadAll(file)
tf, err := torrentfile.DecodeTorrentFile(b)
if err != nil {
panic(err)
}
peers, interval, err := tracker.GetPeers(tf)
if err != nil {
panic(err)
}
log.Println(peers, interval)
for _, peer := range peers {
log.Printf("%v:%d", string(peer.IPAddress), peer.Port)
}
localPeer := peer.Peer{
IPAddress: net.ParseIP("127.0.0.1"),
Port: 51413,
}
log.Printf("Writing to %v", tf.Info.Name)
f, err := os.OpenFile(tf.Info.Name, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
panic(err)
}
defer f.Close()
err = localPeer.Handle(tf, f)
if err != nil {
panic(err)
}
}