mirror of
https://github.com/sot-tech/mochi.git
synced 2026-05-20 23:04:47 -07:00
Initial torrentV2 hash support
This commit is contained in:
committed by
Lawrence, Rendall
parent
823b92fe83
commit
2f092bad45
@@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
@@ -73,19 +72,10 @@ func ParseConfigFile(path string) (*ConfigFile, error) {
|
||||
f, err := os.Open(os.ExpandEnv(path))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
defer f.Close()
|
||||
cfgFile := new(ConfigFile)
|
||||
err = yaml.NewDecoder(f).Decode(cfgFile)
|
||||
return cfgFile, err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
contents, err := ioutil.ReadAll(f)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var cfgFile ConfigFile
|
||||
err = yaml.Unmarshal(contents, &cfgFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &cfgFile, nil
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"github.com/anacrolix/torrent/tracker"
|
||||
@@ -54,28 +54,22 @@ func EndToEndRunCmdFunc(cmd *cobra.Command, args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func generateInfohash() [20]byte {
|
||||
func generateInfohash() bittorrent.InfoHash {
|
||||
b := make([]byte, 20)
|
||||
|
||||
n, err := rand.Read(b)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if n != 20 {
|
||||
panic(fmt.Errorf("not enough randomness? Got %d bytes", n))
|
||||
}
|
||||
|
||||
return bittorrent.InfoHashFromBytes(b)
|
||||
rand.Read(b)
|
||||
ih, _ := bittorrent.InfoHashFromBytes(b)
|
||||
return ih
|
||||
}
|
||||
|
||||
func test(addr string, delay time.Duration) error {
|
||||
ih := generateInfohash()
|
||||
ih, _ := generateInfohash().BytesV1()
|
||||
return testWithInfohash(ih, addr, delay)
|
||||
}
|
||||
|
||||
func testWithInfohash(infoHash [20]byte, url string, delay time.Duration) error {
|
||||
var ih [20]byte
|
||||
req := tracker.AnnounceRequest{
|
||||
InfoHash: infoHash,
|
||||
InfoHash: ih,
|
||||
PeerId: [20]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20},
|
||||
Downloaded: 50,
|
||||
Left: 100,
|
||||
|
||||
Reference in New Issue
Block a user