-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
93 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
cmd/mybittorrent/btencoding/decoder_test.go → cmd/mybittorrent/bt/encoding/decoder_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package btencoding | ||
package encoding | ||
|
||
import ( | ||
"reflect" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
cmd/mybittorrent/btencoding/reader.go → cmd/mybittorrent/bt/encoding/reader.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package btencoding | ||
package encoding | ||
|
||
import ( | ||
"bytes" | ||
|
2 changes: 1 addition & 1 deletion
2
cmd/mybittorrent/btencoding/reader_test.go → cmd/mybittorrent/bt/encoding/reader_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package btencoding | ||
package encoding | ||
|
||
import ( | ||
"fmt" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package bt | ||
|
||
import ( | ||
"crypto/sha1" | ||
|
||
"github.com/codecrafters-io/bittorrent-starter-go/cmd/mybittorrent/bt/encoding" | ||
"github.com/codecrafters-io/bittorrent-starter-go/cmd/mybittorrent/bt/types" | ||
) | ||
|
||
func InfoHash(m *types.FileMeta) ([20]byte, error) { | ||
w := encoding.NewBenEncoder() | ||
data, err := w.Encode(m.InfoDict()) | ||
if err != nil { | ||
return [20]byte{}, err | ||
} | ||
return sha1.Sum(data), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package tracker | ||
|
||
import "github.com/codecrafters-io/bittorrent-starter-go/cmd/mybittorrent/bt/types" | ||
|
||
type TrackerClient struct{} | ||
|
||
type TrackerRequest struct{} | ||
type TrackerResponse struct{} | ||
|
||
func (t *TrackerClient) PeerRequest(m *types.FileInfo) (*TrackerResponse, error) { | ||
return nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package types | ||
|
||
import "strings" | ||
|
||
type FileInfo struct { | ||
Length int | ||
Paths []string | ||
} | ||
|
||
type FileMeta struct { | ||
Announce string | ||
Name string | ||
PieceLength int | ||
Pieces []string | ||
Length int | ||
Files []*FileInfo | ||
Hash []byte | ||
RawInfo map[string]interface{} | ||
} | ||
|
||
func (m *FileMeta) InfoDict() map[string]interface{} { | ||
var info map[string]interface{} | ||
if len(m.Files) == 0 { | ||
info = map[string]interface{}{ | ||
"name": m.Name, | ||
"length": m.Length, | ||
"piece length": m.PieceLength, | ||
"pieces": strings.Join(m.Pieces, ""), | ||
} | ||
} else { | ||
info = map[string]interface{}{ | ||
"name": m.Name, | ||
"piece length": m.PieceLength, | ||
"pieces": strings.Join(m.Pieces, ""), | ||
"files": m.Files, | ||
} | ||
} | ||
|
||
return info | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters