mirror of
https://github.com/ap-pauloafonso/ratio-spoof.git
synced 2026-04-21 16:41:57 +00:00
outdated torrent samples update, fix readme link
This commit is contained in:
parent
00a239e02e
commit
5dd3724a53
29 changed files with 53 additions and 71 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -132,3 +132,4 @@ dmypy.json
|
||||||
/.vscode
|
/.vscode
|
||||||
|
|
||||||
out/
|
out/
|
||||||
|
.idea/
|
||||||
8
Makefile
8
Makefile
|
|
@ -2,14 +2,14 @@ test:
|
||||||
go test ./... --cover
|
go test ./... --cover
|
||||||
|
|
||||||
torrent-test:
|
torrent-test:
|
||||||
go run cmd/main.go -c qbit-4.3.3 -t internal/bencode/torrent_files_test/Fedora-Workstation-Live-x86_64-33.torrent -d 0% -ds 100kbps -u 0% -us 100kbps -debug
|
go run main.go -c qbit-4.3.3 -t bencode/torrent_files_test/debian-12.0.0-amd64-DVD-1.iso.torrent -d 0% -ds 100kbps -u 0% -us 100kbps
|
||||||
|
|
||||||
release:
|
release:
|
||||||
@if test -z "$(rsversion)"; then echo "usage: make release rsversion=v1.2"; exit 1; fi
|
@if test -z "$(rsversion)"; then echo "usage: make release rsversion=v1.2"; exit 1; fi
|
||||||
rm -rf ./out
|
rm -rf ./out
|
||||||
|
|
||||||
env GOOS=darwin GOARCH=amd64 go build -v -o ./out/mac/ratio-spoof github.com/ap-pauloafonso/ratio-spoof/cmd
|
env GOOS=darwin GOARCH=amd64 go build -v -o ./out/mac/ratio-spoof .
|
||||||
env GOOS=linux GOARCH=amd64 go build -v -o ./out/linux/ratio-spoof github.com/ap-pauloafonso/ratio-spoof/cmd
|
env GOOS=linux GOARCH=amd64 go build -v -o ./out/linux/ratio-spoof .
|
||||||
env GOOS=windows GOARCH=amd64 go build -v -o ./out/windows/ratio-spoof.exe github.com/ap-pauloafonso/ratio-spoof/cmd
|
env GOOS=windows GOARCH=amd64 go build -v -o ./out/windows/ratio-spoof.exe .
|
||||||
|
|
||||||
cd out/ ; zip ratio-spoof-$(rsversion)\(linux-mac-windows\).zip -r .
|
cd out/ ; zip ratio-spoof-$(rsversion)\(linux-mac-windows\).zip -r .
|
||||||
|
|
@ -54,5 +54,5 @@ The default client emulation is qbittorrent v4.0.3, however you can change it by
|
||||||
## Resources
|
## Resources
|
||||||
http://www.bittorrent.org/beps/bep_0003.html
|
http://www.bittorrent.org/beps/bep_0003.html
|
||||||
|
|
||||||
https://wiki.theory.org/index.php/BitTorrentSpecification
|
https://wiki.theory.org/BitTorrentSpecification
|
||||||
|
|
||||||
|
|
|
||||||
BIN
bencode/torrent_files_test/debian-12.0.0-amd64-DVD-1.iso.torrent
Normal file
BIN
bencode/torrent_files_test/debian-12.0.0-amd64-DVD-1.iso.torrent
Normal file
Binary file not shown.
|
|
@ -3,9 +3,8 @@ package emulation
|
||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
generator2 "github.com/ap-pauloafonso/ratio-spoof/generator"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/ap-pauloafonso/ratio-spoof/internal/generator"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ClientInfo struct {
|
type ClientInfo struct {
|
||||||
|
|
@ -52,17 +51,17 @@ func NewEmulation(code string) (*Emulation, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
peerG, err := generator.NewRegexPeerIdGenerator(c.PeerID.Regex)
|
peerG, err := generator2.NewRegexPeerIdGenerator(c.PeerID.Regex)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
keyG, err := generator.NewDefaultKeyGenerator()
|
keyG, err := generator2.NewDefaultKeyGenerator()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
roudingG, err := generator.NewDefaultRoudingGenerator()
|
roudingG, err := generator2.NewDefaultRoudingGenerator()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
9
go.mod
9
go.mod
|
|
@ -1,13 +1,16 @@
|
||||||
module github.com/ap-pauloafonso/ratio-spoof
|
module github.com/ap-pauloafonso/ratio-spoof
|
||||||
|
|
||||||
go 1.16
|
go 1.20
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/gammazero/deque v0.0.0-20201010052221-3932da5530cc
|
github.com/gammazero/deque v0.0.0-20201010052221-3932da5530cc
|
||||||
github.com/google/gxui v0.0.0-20151028112939-f85e0a97b3a4 // indirect
|
|
||||||
github.com/olekukonko/ts v0.0.0-20171002115256-78ecb04241c0
|
github.com/olekukonko/ts v0.0.0-20171002115256-78ecb04241c0
|
||||||
|
github.com/zach-klippenstein/goregen v0.0.0-20160303162051-795b5e3961ea
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/google/gxui v0.0.0-20151028112939-f85e0a97b3a4 // indirect
|
||||||
github.com/smartystreets/goconvey v1.6.4 // indirect
|
github.com/smartystreets/goconvey v1.6.4 // indirect
|
||||||
github.com/stretchr/testify v1.7.0 // indirect
|
github.com/stretchr/testify v1.7.0 // indirect
|
||||||
github.com/zach-klippenstein/goregen v0.0.0-20160303162051-795b5e3961ea
|
|
||||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 // indirect
|
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 // indirect
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,10 @@ package input
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/ap-pauloafonso/ratio-spoof/bencode"
|
||||||
"math"
|
"math"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/ap-pauloafonso/ratio-spoof/internal/bencode"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -1,36 +0,0 @@
|
||||||
package ratiospoof
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func assertAreEqual(t *testing.T, got, want interface{}) {
|
|
||||||
t.Helper()
|
|
||||||
if got != want {
|
|
||||||
t.Errorf("\ngot : %v\nwant: %v", got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestClculateNextTotalSizeByte(T *testing.T) {
|
|
||||||
|
|
||||||
got := calculateNextTotalSizeByte(100*1024, 0, 512, 30, 87979879)
|
|
||||||
want := 3075072
|
|
||||||
|
|
||||||
assertAreEqual(T, got, want)
|
|
||||||
}
|
|
||||||
|
|
||||||
// func TestUrlEncodeInfoHash(T *testing.T) {
|
|
||||||
|
|
||||||
// b, _ := ioutil.ReadFile("")
|
|
||||||
// got := extractInfoHashURLEncoded(b, bencode.Decode(b))
|
|
||||||
// want := "%60N%7d%1f%8b%3a%9bT%d5%fc%ad%d1%27%ab5%02%1c%fb%03%b0"
|
|
||||||
// assertAreEqual(T, got, want)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func TestUrlEncodeInfoHash2(T *testing.T) {
|
|
||||||
|
|
||||||
// b, _ := ioutil.ReadFile("")
|
|
||||||
// got := extractInfoHashURLEncoded(b, bencode.Decode(b))
|
|
||||||
// want := "%02r%fd%fe%bf%fbt%d0%0f%cf%d9%8c%e0%a9%97%f8%08%9b%00%b2"
|
|
||||||
// assertAreEqual(T, got, want)
|
|
||||||
// }
|
|
||||||
|
|
@ -3,12 +3,11 @@ package main
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/ap-pauloafonso/ratio-spoof/input"
|
||||||
|
"github.com/ap-pauloafonso/ratio-spoof/printer"
|
||||||
|
"github.com/ap-pauloafonso/ratio-spoof/ratiospoof"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/ap-pauloafonso/ratio-spoof/internal/input"
|
|
||||||
"github.com/ap-pauloafonso/ratio-spoof/internal/printer"
|
|
||||||
"github.com/ap-pauloafonso/ratio-spoof/internal/ratiospoof"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
@ -2,13 +2,13 @@ package printer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/ap-pauloafonso/ratio-spoof/ratiospoof"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ap-pauloafonso/ratio-spoof/internal/ratiospoof"
|
|
||||||
"github.com/olekukonko/ts"
|
"github.com/olekukonko/ts"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -3,6 +3,10 @@ package ratiospoof
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/ap-pauloafonso/ratio-spoof/bencode"
|
||||||
|
"github.com/ap-pauloafonso/ratio-spoof/emulation"
|
||||||
|
"github.com/ap-pauloafonso/ratio-spoof/input"
|
||||||
|
"github.com/ap-pauloafonso/ratio-spoof/tracker"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -11,10 +15,6 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ap-pauloafonso/ratio-spoof/internal/bencode"
|
|
||||||
"github.com/ap-pauloafonso/ratio-spoof/internal/emulation"
|
|
||||||
"github.com/ap-pauloafonso/ratio-spoof/internal/input"
|
|
||||||
"github.com/ap-pauloafonso/ratio-spoof/internal/tracker"
|
|
||||||
"github.com/gammazero/deque"
|
"github.com/gammazero/deque"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -103,7 +103,6 @@ func (r *RatioSpoof) gracefullyExit() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RatioSpoof) Run() {
|
func (r *RatioSpoof) Run() {
|
||||||
rand.Seed(time.Now().UnixNano())
|
|
||||||
sigCh := make(chan os.Signal)
|
sigCh := make(chan os.Signal)
|
||||||
|
|
||||||
signal.Notify(sigCh, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
|
signal.Notify(sigCh, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
|
||||||
|
|
@ -161,13 +160,15 @@ func (r *RatioSpoof) generateNextAnnounce() {
|
||||||
var downloadCandidate int
|
var downloadCandidate int
|
||||||
|
|
||||||
if currentDownloaded < r.TorrentInfo.TotalSize {
|
if currentDownloaded < r.TorrentInfo.TotalSize {
|
||||||
downloadCandidate = calculateNextTotalSizeByte(r.Input.DownloadSpeed, currentDownloaded, r.TorrentInfo.PieceSize, r.AnnounceInterval, r.TorrentInfo.TotalSize)
|
randomPiecesDownload := rand.Intn(10-1) + 1
|
||||||
|
downloadCandidate = calculateNextTotalSizeByte(r.Input.DownloadSpeed, currentDownloaded, r.TorrentInfo.PieceSize, r.AnnounceInterval, r.TorrentInfo.TotalSize, randomPiecesDownload)
|
||||||
} else {
|
} else {
|
||||||
downloadCandidate = r.TorrentInfo.TotalSize
|
downloadCandidate = r.TorrentInfo.TotalSize
|
||||||
}
|
}
|
||||||
|
|
||||||
currentUploaded := lastAnnounce.Uploaded
|
currentUploaded := lastAnnounce.Uploaded
|
||||||
uploadCandidate := calculateNextTotalSizeByte(r.Input.UploadSpeed, currentUploaded, r.TorrentInfo.PieceSize, r.AnnounceInterval, 0)
|
randomPiecesUpload := rand.Intn(10-1) + 1
|
||||||
|
uploadCandidate := calculateNextTotalSizeByte(r.Input.UploadSpeed, currentUploaded, r.TorrentInfo.PieceSize, r.AnnounceInterval, 0, randomPiecesUpload)
|
||||||
|
|
||||||
leftCandidate := calculateBytesLeft(downloadCandidate, r.TorrentInfo.TotalSize)
|
leftCandidate := calculateBytesLeft(downloadCandidate, r.TorrentInfo.TotalSize)
|
||||||
|
|
||||||
|
|
@ -176,12 +177,11 @@ func (r *RatioSpoof) generateNextAnnounce() {
|
||||||
r.addAnnounce(d, u, l, (float32(d)/float32(r.TorrentInfo.TotalSize))*100)
|
r.addAnnounce(d, u, l, (float32(d)/float32(r.TorrentInfo.TotalSize))*100)
|
||||||
}
|
}
|
||||||
|
|
||||||
func calculateNextTotalSizeByte(speedBytePerSecond, currentByte, pieceSizeByte, seconds, limitTotalBytes int) int {
|
func calculateNextTotalSizeByte(speedBytePerSecond, currentByte, pieceSizeByte, seconds, limitTotalBytes, randomPieces int) int {
|
||||||
if speedBytePerSecond == 0 {
|
if speedBytePerSecond == 0 {
|
||||||
return currentByte
|
return currentByte
|
||||||
}
|
}
|
||||||
totalCandidate := currentByte + (speedBytePerSecond * seconds)
|
totalCandidate := currentByte + (speedBytePerSecond * seconds)
|
||||||
randomPieces := rand.Intn(10-1) + 1
|
|
||||||
totalCandidate = totalCandidate + (pieceSizeByte * randomPieces)
|
totalCandidate = totalCandidate + (pieceSizeByte * randomPieces)
|
||||||
|
|
||||||
if limitTotalBytes != 0 && totalCandidate > limitTotalBytes {
|
if limitTotalBytes != 0 && totalCandidate > limitTotalBytes {
|
||||||
19
ratiospoof/ratiospoof_test.go
Normal file
19
ratiospoof/ratiospoof_test.go
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
package ratiospoof
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCalculateNextTotalSizeByte(t *testing.T) {
|
||||||
|
randomPieces := 8
|
||||||
|
randomPiecesUpload := rand.Intn(10-1) + 1
|
||||||
|
fmt.Print(randomPiecesUpload)
|
||||||
|
got := calculateNextTotalSizeByte(100*1024, 0, 512, 30, 87979879, randomPieces)
|
||||||
|
want := 3076096
|
||||||
|
|
||||||
|
if got != want {
|
||||||
|
t.Errorf("\ngot : %v\nwant: %v", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,12 +4,11 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"errors"
|
"errors"
|
||||||
|
"github.com/ap-pauloafonso/ratio-spoof/bencode"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ap-pauloafonso/ratio-spoof/internal/bencode"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type HttpTracker struct {
|
type HttpTracker struct {
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
package tracker
|
package tracker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/ap-pauloafonso/ratio-spoof/bencode"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/ap-pauloafonso/ratio-spoof/internal/bencode"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewHttpTracker(t *testing.T) {
|
func TestNewHttpTracker(t *testing.T) {
|
||||||
Loading…
Reference in a new issue