mirror of
https://github.com/sot-tech/mochi.git
synced 2026-06-21 11:48:27 -07:00
Fix varinterval panic if request IH is not provided
This commit is contained in:
committed by
Lawrence, Rendall
parent
9122aefdd7
commit
239a642bfc
@@ -10,8 +10,10 @@ import (
|
||||
// AnnounceRequest.
|
||||
//
|
||||
// Calling DeriveEntropyFromRequest multiple times yields the same values.
|
||||
func DeriveEntropyFromRequest(req *bittorrent.AnnounceRequest) (uint64, uint64) {
|
||||
v0 := binary.BigEndian.Uint64([]byte(req.InfoHash[:8])) + binary.BigEndian.Uint64([]byte(req.InfoHash[8:16]))
|
||||
v1 := binary.BigEndian.Uint64(req.Peer.ID[:8]) + binary.BigEndian.Uint64(req.Peer.ID[8:16])
|
||||
return v0, v1
|
||||
func DeriveEntropyFromRequest(req *bittorrent.AnnounceRequest) (v0 uint64, v1 uint64) {
|
||||
if len(req.InfoHash) >= bittorrent.InfoHashV1Len {
|
||||
v0 = binary.BigEndian.Uint64([]byte(req.InfoHash[:8])) + binary.BigEndian.Uint64([]byte(req.InfoHash[8:16]))
|
||||
}
|
||||
v1 = binary.BigEndian.Uint64(req.Peer.ID[:8]) + binary.BigEndian.Uint64(req.Peer.ID[8:16])
|
||||
return
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ func TestHandleAnnounce(t *testing.T) {
|
||||
require.NotNil(t, h)
|
||||
|
||||
ctx := context.Background()
|
||||
req := &bittorrent.AnnounceRequest{}
|
||||
req := &bittorrent.AnnounceRequest{InfoHash: "1234567890ABCDEF0000"}
|
||||
resp := &bittorrent.AnnounceResponse{}
|
||||
|
||||
nCtx, err := h.HandleAnnounce(ctx, req, resp)
|
||||
|
||||
Reference in New Issue
Block a user