mirror of
https://github.com/ap-pauloafonso/ratio-spoof.git
synced 2026-05-18 15:51:44 +00:00
fix info hash
This commit is contained in:
parent
fe5c6bde7a
commit
d16bfcdded
2 changed files with 29 additions and 5 deletions
|
|
@ -10,9 +10,9 @@ import (
|
||||||
"math"
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
@ -367,8 +367,8 @@ func (R *ratioSpoofState) changeCurrentTimer(newAnnounceRate int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (R *ratioSpoofState) tryMakeRequest(query string) *trackerResponse {
|
func (R *ratioSpoofState) tryMakeRequest(query string) *trackerResponse {
|
||||||
for idx, url := range R.torrentInfo.trackerInfo.urls {
|
for idx, baseUrl := range R.torrentInfo.trackerInfo.urls {
|
||||||
completeURL := url + "?" + strings.TrimLeft(query, "?")
|
completeURL := buildFullUrl(baseUrl, query)
|
||||||
R.lastAnounceRequest = completeURL
|
R.lastAnounceRequest = completeURL
|
||||||
req, _ := http.NewRequest("GET", completeURL, nil)
|
req, _ := http.NewRequest("GET", completeURL, nil)
|
||||||
for header, value := range R.bitTorrentClient.Headers() {
|
for header, value := range R.bitTorrentClient.Headers() {
|
||||||
|
|
@ -402,6 +402,13 @@ func (R *ratioSpoofState) tryMakeRequest(query string) *trackerResponse {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func buildFullUrl(baseurl, query string) string {
|
||||||
|
if len(strings.Split(baseurl, "?")) > 1 {
|
||||||
|
return baseurl + "&" + strings.TrimLeft(query, "&")
|
||||||
|
}
|
||||||
|
return baseurl + "?" + strings.TrimLeft(query, "?")
|
||||||
|
}
|
||||||
|
|
||||||
func calculateNextTotalSizeByte(speedBytePerSecond, currentByte, pieceSizeByte, seconds, limitTotalBytes int) int {
|
func calculateNextTotalSizeByte(speedBytePerSecond, currentByte, pieceSizeByte, seconds, limitTotalBytes int) int {
|
||||||
if speedBytePerSecond == 0 {
|
if speedBytePerSecond == 0 {
|
||||||
return currentByte
|
return currentByte
|
||||||
|
|
@ -421,7 +428,16 @@ func extractInfoHashURLEncoded(rawData []byte, torrentData map[string]interface{
|
||||||
h := sha1.New()
|
h := sha1.New()
|
||||||
h.Write([]byte(rawData[byteOffsets[0]:byteOffsets[1]]))
|
h.Write([]byte(rawData[byteOffsets[0]:byteOffsets[1]]))
|
||||||
ret := h.Sum(nil)
|
ret := h.Sum(nil)
|
||||||
return url.QueryEscape(string(ret))
|
var buf bytes.Buffer
|
||||||
|
re := regexp.MustCompile(`[a-zA-Z0-9\.\-\_\~]`)
|
||||||
|
for _, b := range ret {
|
||||||
|
if re.Match([]byte{b}) {
|
||||||
|
buf.WriteByte(b)
|
||||||
|
} else {
|
||||||
|
buf.WriteString(fmt.Sprintf("%%%02x", b))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return buf.String()
|
||||||
|
|
||||||
}
|
}
|
||||||
func extractTotalSize(torrentData map[string]interface{}) int {
|
func extractTotalSize(torrentData map[string]interface{}) int {
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
func assertAreEqual(t *testing.T, got, want interface{}) {
|
func assertAreEqual(t *testing.T, got, want interface{}) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
if got != want {
|
if got != want {
|
||||||
t.Errorf("\ngot: %v\n want: %v", got, want)
|
t.Errorf("\ngot : %v\nwant: %v", got, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -55,3 +55,11 @@ func TestClculateNextTotalSizeByte(T *testing.T) {
|
||||||
// want := "%60N%7d%1f%8b%3a%9bT%d5%fc%ad%d1%27%ab5%02%1c%fb%03%b0"
|
// want := "%60N%7d%1f%8b%3a%9bT%d5%fc%ad%d1%27%ab5%02%1c%fb%03%b0"
|
||||||
// assertAreEqual(T, got, want)
|
// assertAreEqual(T, got, want)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
// func TestUrlEncodeInfoHash2(T *testing.T) {
|
||||||
|
|
||||||
|
// b, _ := ioutil.ReadFile("")
|
||||||
|
// got := extractInfoHashURLEncoded(b, beencode.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)
|
||||||
|
// }
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue