Skip to content

Commit

Permalink
feat: integration torrent (GopeedLab#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyWie authored Aug 11, 2022
1 parent 43378c7 commit 0341373
Show file tree
Hide file tree
Showing 20 changed files with 926 additions and 140 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
steps:
- uses: actions/setup-go@v2
with:
go-version: '^1.15.2'
go-version: '^1.18'
- uses: actions/checkout@v2
- name: Build Cli
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
# steps:
# - uses: actions/setup-go@v2
# with:
# go-version: '^1.15.2'
# go-version: '^1.18'
# - uses: actions/checkout@v2
# - name: Lint Go Code
# run: |
Expand All @@ -34,7 +34,7 @@ jobs:
steps:
- uses: actions/setup-go@v2
with:
go-version: '^1.15.2'
go-version: '^1.18'
- uses: actions/checkout@v2
- name: Run Unit tests.
run: go test ./... -v -covermode=count -coverprofile=coverage.txt
Expand All @@ -50,7 +50,7 @@ jobs:
steps:
- uses: actions/setup-go@v2
with:
go-version: '^1.15.2'
go-version: '^1.18'
- uses: actions/checkout@v2
- name: Build
run: go build -ldflags="-s -w" -o gopeed cmd/gopeed/*
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@

debug

.idea/
.idea/

bin/
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ go install github.com/monkeyWie/gopeed-core
## TODO

- [x] HTTP 下载实现
- [ ] BitTorrent 下载实现
- [x] BitTorrent 下载实现
- [x] .torrent 文件解析
- [x] tracker 协议实现
- [x] peer wire protocol 协议实现
- [ ] DHT 协议实现
- [ ] 磁力链接支持
- [ ] uTP 协议实现
- [x] DHT 协议实现
- [x] 磁力链接支持
- [x] uTP 协议实现
- [x] 下载接口抽象(不关心具体协议)
- [ ] 支持自定义配置
- [ ] 限速功能实现
Expand Down
2 changes: 1 addition & 1 deletion cmd/gopeed/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func parse() *args {
}
var args args
args.connections = flag.Int("C", 16, "Concurrent connections.")
args.dir = flag.String("D", dir, "Save directory.")
args.dir = flag.String("D", dir, "Store directory.")
flag.Parse()
t := flag.Args()
if len(t) > 0 {
Expand Down
34 changes: 24 additions & 10 deletions cmd/gopeed/gopeed.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/monkeyWie/gopeed-core/pkg/base"
"github.com/monkeyWie/gopeed-core/pkg/download"
"github.com/monkeyWie/gopeed-core/pkg/util"
"path/filepath"
"strings"
"sync"
)

Expand All @@ -31,9 +31,9 @@ func main() {
printProgress(event.Task, title)
fmt.Println()
if event.Err != nil {
gPrint("reason: " + event.Err.Error())
fmt.Printf("reason: %s", event.Err.Error())
} else {
gPrint("saving file " + filepath.Join(*args.dir, event.Task.Res.Files[0].Name))
fmt.Printf("saving path: %s", *args.dir)
}
wg.Done()
}
Expand All @@ -49,18 +49,32 @@ func main() {
wg.Wait()
}

func printProgress(task *download.TaskInfo, title string) {
rate := float64(task.Progress.Downloaded) / float64(task.Res.TotalSize)
var (
lastLineLen = 0
sb = new(strings.Builder)
)

func printProgress(task *download.Task, title string) {
rate := float64(task.Progress.Downloaded) / float64(task.Res.Length)
completeWidth := int(progressWidth * rate)
speed := util.ByteFmt(task.Progress.Speed)
totalSize := util.ByteFmt(task.Res.TotalSize)
fmt.Printf("\r%s [", title)
totalSize := util.ByteFmt(task.Res.Length)
sb.WriteString(fmt.Sprintf("\r%s [", title))
for i := 0; i < progressWidth; i++ {
if i < completeWidth {
fmt.Print("■")
sb.WriteString("■")
} else {
fmt.Print("□")
sb.WriteString("□")
}
}
sb.WriteString(fmt.Sprintf("] %.1f%% %s/s %s", rate*100, speed, totalSize))
if lastLineLen != 0 {
paddingLen := lastLineLen - sb.Len()
if paddingLen > 0 {
sb.WriteString(strings.Repeat(" ", paddingLen))
}
}
fmt.Printf("] %.1f%% %s/s %s", rate*100, speed, totalSize)
lastLineLen = sb.Len()
fmt.Print(sb.String())
sb.Reset()
}
66 changes: 63 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,69 @@
module github.com/monkeyWie/gopeed-core

go 1.15
go 1.18

require (
github.com/google/uuid v1.1.1
golang.org/x/net v0.0.0-20200707034311-ab3426394381
github.com/anacrolix/torrent v1.46.0
github.com/google/uuid v1.3.0
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
)

require (
crawshaw.io/sqlite v0.3.3-0.20210127221821-98b1f83c5508 // indirect
github.com/RoaringBitmap/roaring v1.0.1-0.20220510143707-3f418c4f42a4 // indirect
github.com/ajwerner/btree v0.0.0-20211221152037-f427b3e689c0 // indirect
github.com/anacrolix/chansync v0.3.0 // indirect
github.com/anacrolix/dht/v2 v2.16.2-0.20220311024416-dd658f18fd51 // indirect
github.com/anacrolix/envpprof v1.2.1 // indirect
github.com/anacrolix/generics v0.0.0-20220618083756-f99e35403a60 // indirect
github.com/anacrolix/go-libutp v1.2.0 // indirect
github.com/anacrolix/log v0.13.1 // indirect
github.com/anacrolix/missinggo v1.3.0 // indirect
github.com/anacrolix/missinggo/perf v1.0.0 // indirect
github.com/anacrolix/missinggo/v2 v2.7.0 // indirect
github.com/anacrolix/mmsg v1.0.0 // indirect
github.com/anacrolix/multiless v0.2.1-0.20211218050420-533661eef5dc // indirect
github.com/anacrolix/stm v0.3.0 // indirect
github.com/anacrolix/sync v0.4.0 // indirect
github.com/anacrolix/upnp v0.1.3-0.20220123035249-922794e51c96 // indirect
github.com/anacrolix/utp v0.1.0 // indirect
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/benbjohnson/immutable v0.3.0 // indirect
github.com/bits-and-blooms/bitset v1.2.0 // indirect
github.com/bradfitz/iter v0.0.0-20191230175014-e8f45d346db8 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/edsrzf/mmap-go v1.1.0 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/lispad/go-generics-tools v1.0.0 // indirect
github.com/mschoch/smat v0.2.0 // indirect
github.com/pion/datachannel v1.5.2 // indirect
github.com/pion/dtls/v2 v2.1.2 // indirect
github.com/pion/ice/v2 v2.1.20 // indirect
github.com/pion/interceptor v0.1.7 // indirect
github.com/pion/logging v0.2.2 // indirect
github.com/pion/mdns v0.0.5 // indirect
github.com/pion/randutil v0.1.0 // indirect
github.com/pion/rtcp v1.2.9 // indirect
github.com/pion/rtp v1.7.4 // indirect
github.com/pion/sctp v1.8.2 // indirect
github.com/pion/sdp/v3 v3.0.4 // indirect
github.com/pion/srtp/v2 v2.0.5 // indirect
github.com/pion/stun v0.3.5 // indirect
github.com/pion/transport v0.13.0 // indirect
github.com/pion/turn/v2 v2.0.6 // indirect
github.com/pion/udp v0.1.1 // indirect
github.com/pion/webrtc/v3 v3.1.24-0.20220208053747-94262c1b2b38 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rs/dnscache v0.0.0-20210201191234-295bba877686 // indirect
github.com/tidwall/btree v1.3.1 // indirect
go.etcd.io/bbolt v1.3.6 // indirect
golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838 // indirect
golang.org/x/exp v0.0.0-20220428152302-39d4317da171 // indirect
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
)
Loading

0 comments on commit 0341373

Please sign in to comment.