outdated torrent samples update, fix readme link

This commit is contained in:
paulo 2023-07-03 15:05:45 -03:00
parent 00a239e02e
commit 5dd3724a53
29 changed files with 53 additions and 71 deletions

3
.gitignore vendored
View file

@ -131,4 +131,5 @@ dmypy.json
#vscode folder
/.vscode
out/
out/
.idea/

View file

@ -2,14 +2,14 @@ test:
go test ./... --cover
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:
@if test -z "$(rsversion)"; then echo "usage: make release rsversion=v1.2"; exit 1; fi
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=linux GOARCH=amd64 go build -v -o ./out/linux/ratio-spoof github.com/ap-pauloafonso/ratio-spoof/cmd
env GOOS=windows GOARCH=amd64 go build -v -o ./out/windows/ratio-spoof.exe 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 .
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 .

View file

@ -54,5 +54,5 @@ The default client emulation is qbittorrent v4.0.3, however you can change it by
## Resources
http://www.bittorrent.org/beps/bep_0003.html
https://wiki.theory.org/index.php/BitTorrentSpecification
https://wiki.theory.org/BitTorrentSpecification

View file

@ -3,9 +3,8 @@ package emulation
import (
"embed"
"encoding/json"
generator2 "github.com/ap-pauloafonso/ratio-spoof/generator"
"io"
"github.com/ap-pauloafonso/ratio-spoof/internal/generator"
)
type ClientInfo struct {
@ -52,17 +51,17 @@ func NewEmulation(code string) (*Emulation, error) {
return nil, err
}
peerG, err := generator.NewRegexPeerIdGenerator(c.PeerID.Regex)
peerG, err := generator2.NewRegexPeerIdGenerator(c.PeerID.Regex)
if err != nil {
return nil, err
}
keyG, err := generator.NewDefaultKeyGenerator()
keyG, err := generator2.NewDefaultKeyGenerator()
if err != nil {
return nil, err
}
roudingG, err := generator.NewDefaultRoudingGenerator()
roudingG, err := generator2.NewDefaultRoudingGenerator()
if err != nil {
return nil, err
}

9
go.mod
View file

@ -1,13 +1,16 @@
module github.com/ap-pauloafonso/ratio-spoof
go 1.16
go 1.20
require (
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/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/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
)

View file

@ -3,11 +3,10 @@ package input
import (
"errors"
"fmt"
"github.com/ap-pauloafonso/ratio-spoof/bencode"
"math"
"strconv"
"strings"
"github.com/ap-pauloafonso/ratio-spoof/internal/bencode"
)
const (
@ -95,7 +94,7 @@ func extractInputInitialByteCount(initialSizeInput string, totalBytes int, error
return byteCount, nil
}
//Takes an dirty speed input and returns the bytes per second based on the suffixes
// Takes an dirty speed input and returns the bytes per second based on the suffixes
// example 1kbps(string) > 1024 bytes per second (int)
func extractInputByteSpeed(initialSpeedInput string) (int, error) {
ok, suffix := checkSpeedSufix(initialSpeedInput)

View file

@ -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)
// }

View file

@ -3,12 +3,11 @@ package main
import (
"flag"
"fmt"
"github.com/ap-pauloafonso/ratio-spoof/input"
"github.com/ap-pauloafonso/ratio-spoof/printer"
"github.com/ap-pauloafonso/ratio-spoof/ratiospoof"
"log"
"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() {

View file

@ -2,13 +2,13 @@ package printer
import (
"fmt"
"github.com/ap-pauloafonso/ratio-spoof/ratiospoof"
"os"
"os/exec"
"runtime"
"strings"
"time"
"github.com/ap-pauloafonso/ratio-spoof/internal/ratiospoof"
"github.com/olekukonko/ts"
)

View file

@ -3,6 +3,10 @@ package ratiospoof
import (
"errors"
"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"
"math/rand"
"os"
@ -11,10 +15,6 @@ import (
"syscall"
"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"
)
@ -103,7 +103,6 @@ func (r *RatioSpoof) gracefullyExit() {
}
func (r *RatioSpoof) Run() {
rand.Seed(time.Now().UnixNano())
sigCh := make(chan os.Signal)
signal.Notify(sigCh, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
@ -161,13 +160,15 @@ func (r *RatioSpoof) generateNextAnnounce() {
var downloadCandidate int
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 {
downloadCandidate = r.TorrentInfo.TotalSize
}
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)
@ -176,12 +177,11 @@ func (r *RatioSpoof) generateNextAnnounce() {
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 {
return currentByte
}
totalCandidate := currentByte + (speedBytePerSecond * seconds)
randomPieces := rand.Intn(10-1) + 1
totalCandidate = totalCandidate + (pieceSizeByte * randomPieces)
if limitTotalBytes != 0 && totalCandidate > limitTotalBytes {

View 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)
}
}

View file

@ -4,12 +4,11 @@ import (
"bytes"
"compress/gzip"
"errors"
"github.com/ap-pauloafonso/ratio-spoof/bencode"
"io"
"net/http"
"strings"
"time"
"github.com/ap-pauloafonso/ratio-spoof/internal/bencode"
)
type HttpTracker struct {

View file

@ -1,10 +1,9 @@
package tracker
import (
"github.com/ap-pauloafonso/ratio-spoof/bencode"
"reflect"
"testing"
"github.com/ap-pauloafonso/ratio-spoof/internal/bencode"
)
func TestNewHttpTracker(t *testing.T) {