]> Sergey Matveev's repositories - btrtrc.git/blobdiff - webtorrent/tracker_protocol.go
Pool webtorrent tracker websockets at the Client level
[btrtrc.git] / webtorrent / tracker_protocol.go
index 548122ffe2f4061671f3f70fe004030d7ed8c5bf..167044a6315510e833634c0b9fcb1d93f95787f6 100644 (file)
@@ -1,6 +1,9 @@
 package webtorrent
 
 import (
+       "fmt"
+       "math"
+
        "github.com/pion/webrtc/v2"
 )
 
@@ -43,3 +46,21 @@ func binaryToJsonString(b []byte) string {
        }
        return string(seq)
 }
+
+func jsonStringToInfoHash(s string) (ih [20]byte, err error) {
+       defer func() {
+               r := recover()
+               if r == nil {
+                       return
+               }
+               panic(fmt.Sprintf("%q", s))
+       }()
+       for i, c := range []rune(s) {
+               if c < 0 || c > math.MaxUint8 {
+                       err = fmt.Errorf("bad infohash string: %v", s)
+                       return
+               }
+               ih[i] = byte(c)
+       }
+       return
+}