diff --git a/beencode/beencode.go b/bencode/bencode.go similarity index 97% rename from beencode/beencode.go rename to bencode/bencode.go index 8fcbe74..3885fc3 100644 --- a/beencode/beencode.go +++ b/bencode/bencode.go @@ -1,4 +1,4 @@ -package beencode +package bencode import ( "bytes" @@ -25,7 +25,7 @@ const ( torrentDictOffsetsKey = "byte_offsets" ) -// TorrentInfo contains all relevant information extracted from a beencode file +// TorrentInfo contains all relevant information extracted from a bencode file type TorrentInfo struct { Name string PieceSize int @@ -44,7 +44,7 @@ type torrentDict struct { resultMap map[string]interface{} } -//TorrentDictParse decodes the beencoded bytes and builds the torrentInfo file +//TorrentDictParse decodes the bencoded bytes and builds the torrentInfo file func TorrentDictParse(dat []byte) (*TorrentInfo, error) { dict, _ := mapParse(0, &dat) torrentMap := torrentDict{resultMap: dict} @@ -133,7 +133,7 @@ func findParse(currentIdx int, data *[]byte) (result interface{}, nextIdx int) { case token >= byte('0') || token <= byte('9'): return stringParse(currentIdx, data) default: - panic("Error decoding beencode") + panic("Error decoding bencode") } } diff --git a/beencode/beencode_test.go b/bencode/bencode_test.go similarity index 99% rename from beencode/beencode_test.go rename to bencode/bencode_test.go index 1197d5b..5cd24a2 100644 --- a/beencode/beencode_test.go +++ b/bencode/bencode_test.go @@ -1,4 +1,4 @@ -package beencode +package bencode import ( "io/ioutil" diff --git a/beencode/torrent_files_test/Fedora-Workstation-Live-x86_64-33.torrent b/bencode/torrent_files_test/Fedora-Workstation-Live-x86_64-33.torrent similarity index 100% rename from beencode/torrent_files_test/Fedora-Workstation-Live-x86_64-33.torrent rename to bencode/torrent_files_test/Fedora-Workstation-Live-x86_64-33.torrent diff --git a/beencode/torrent_files_test/Slackware 14.2 x86_64 DVD ISO (Includes everything except for source code -- see the Slackware 14.2 source code DVD ISO above for source code).torrent b/bencode/torrent_files_test/Slackware 14.2 x86_64 DVD ISO (Includes everything except for source code -- see the Slackware 14.2 source code DVD ISO above for source code).torrent similarity index 100% rename from beencode/torrent_files_test/Slackware 14.2 x86_64 DVD ISO (Includes everything except for source code -- see the Slackware 14.2 source code DVD ISO above for source code).torrent rename to bencode/torrent_files_test/Slackware 14.2 x86_64 DVD ISO (Includes everything except for source code -- see the Slackware 14.2 source code DVD ISO above for source code).torrent diff --git a/beencode/torrent_files_test/ubuntu-20.04.1-desktop-amd64.iso.torrent b/bencode/torrent_files_test/ubuntu-20.04.1-desktop-amd64.iso.torrent similarity index 100% rename from beencode/torrent_files_test/ubuntu-20.04.1-desktop-amd64.iso.torrent rename to bencode/torrent_files_test/ubuntu-20.04.1-desktop-amd64.iso.torrent diff --git a/ratiospoof/ratiospoof.go b/ratiospoof/ratiospoof.go index 36c21bd..cf2c4e7 100644 --- a/ratiospoof/ratiospoof.go +++ b/ratiospoof/ratiospoof.go @@ -17,7 +17,7 @@ import ( "syscall" "time" - "github.com/ap-pauloafonso/ratio-spoof/beencode" + "github.com/ap-pauloafonso/ratio-spoof/bencode" "github.com/gammazero/deque" ) @@ -31,7 +31,7 @@ var validSpeedSufixes = [...]string{"kbps", "mbps"} type ratioSpoofState struct { mutex *sync.Mutex httpClient HttpClient - torrentInfo *beencode.TorrentInfo + torrentInfo *bencode.TorrentInfo input *inputParsed trackerState *httpTracker bitTorrentClient TorrentClientEmulation @@ -51,7 +51,7 @@ type httpTracker struct { urls []string } -func newHttpTracker(torrentInfo *beencode.TorrentInfo) (*httpTracker, error) { +func newHttpTracker(torrentInfo *bencode.TorrentInfo) (*httpTracker, error) { var result []string for _, url := range torrentInfo.TrackerInfo.Urls { @@ -91,7 +91,7 @@ type inputParsed struct { debug bool } -func (I *InputArgs) parseInput(torrentInfo *beencode.TorrentInfo) (*inputParsed, error) { +func (I *InputArgs) parseInput(torrentInfo *bencode.TorrentInfo) (*inputParsed, error) { downloaded, err := extractInputInitialByteCount(I.InitialDownloaded, torrentInfo.TotalSize, true) if err != nil { return nil, err @@ -129,7 +129,7 @@ func NewRatioSPoofState(input InputArgs, torrentClient TorrentClientEmulation, h return nil, err } - torrentInfo, err := beencode.TorrentDictParse(dat) + torrentInfo, err := bencode.TorrentDictParse(dat) if err != nil { panic(err) } @@ -389,7 +389,7 @@ func (R *ratioSpoofState) tryMakeRequest(query string) *trackerResponse { gzipReader.Close() } R.lastTackerResponse = string(bytesR) - decodedResp := beencode.Decode(bytesR) + decodedResp := bencode.Decode(bytesR) if idx != 0 { R.trackerState.SwapFirst(idx) } diff --git a/ratiospoof/ratiospoof_test.go b/ratiospoof/ratiospoof_test.go index 2db0e0a..ab8fc8d 100644 --- a/ratiospoof/ratiospoof_test.go +++ b/ratiospoof/ratiospoof_test.go @@ -51,7 +51,7 @@ func TestClculateNextTotalSizeByte(T *testing.T) { // func TestUrlEncodeInfoHash(T *testing.T) { // b, _ := ioutil.ReadFile("") -// got := extractInfoHashURLEncoded(b, beencode.Decode(b)) +// 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) // } @@ -59,7 +59,7 @@ func TestClculateNextTotalSizeByte(T *testing.T) { // func TestUrlEncodeInfoHash2(T *testing.T) { // b, _ := ioutil.ReadFile("") -// got := extractInfoHashURLEncoded(b, beencode.Decode(b)) +// 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) // }