Skip to content

Commit

Permalink
ADD: wrap TorrentTask
Browse files Browse the repository at this point in the history
  • Loading branch information
archeryue committed May 14, 2022
1 parent ba8b3fc commit 4547ef8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
19 changes: 17 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ import (
"github.com/archeryue/go-torrent/torrent"
)

func buildTask(tf *torrent.TorrentFile, peerId [20]byte, peers []torrent.PeerInfo) *torrent.TorrentTask {
var task torrent.TorrentTask
task.PeerId = peerId
task.PeerList = peers
task.FileName = tf.FileName
task.FileLen = tf.FileLen
task.InfoSHA = tf.InfoSHA
task.PieceLen = tf.PieceLen
task.PieceSHA = tf.PieceSHA
return &task
}

func main() {
//parse torrent file
file, err := os.Open(os.Args[1])
Expand All @@ -33,8 +45,11 @@ func main() {
peers := torrent.FindPeers(tf, peerId)
if len(peers) == 0 {
fmt.Println("can not find peers")
return
}
// build torrent task
task := buildTask(tf, peerId, peers)
//download from peers & make file
torrent.Download(tf, peerId, peers)
torrent.MakeFile(tf)
torrent.Download(task)
torrent.MakeFile(task.FileName)
}
14 changes: 12 additions & 2 deletions torrent/download.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
package torrent

func Download(tf *TorrentFile, peerId [20]byte, peers []PeerInfo) error {
type TorrentTask struct {
PeerId [20]byte
PeerList []PeerInfo
InfoSHA [SHALEN]byte
FileName string
FileLen int
PieceLen int
PieceSHA [][SHALEN]byte
}

func Download(task *TorrentTask) error {
//TODO: check local tmp file
//TODO: download piceces and check
//TODO: write picece bytes into local tmp file
return nil
}

func MakeFile(tf *TorrentFile) {
func MakeFile(name string) {
//TODO: assemble tmp to file
}

0 comments on commit 4547ef8

Please sign in to comment.