mirror of
https://github.com/sot-tech/mochi.git
synced 2026-06-12 15:53:32 -07:00
Fix varinterval panic if request IH is not provided
This commit is contained in:
committed by
Lawrence, Rendall
parent
9122aefdd7
commit
239a642bfc
+2
-2
@@ -148,7 +148,7 @@ func RootRunCmdFunc(cmd *cobra.Command, _ []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
quit := make(chan os.Signal)
|
||||
quit := make(chan os.Signal, 1)
|
||||
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
||||
reload := makeReloadChan()
|
||||
@@ -209,7 +209,7 @@ func RootPreRunCmdFunc(cmd *cobra.Command, _ []string) error {
|
||||
|
||||
// RootPostRunCmdFunc handles clean up of any state initialized by command line
|
||||
// flags.
|
||||
func RootPostRunCmdFunc(cmd *cobra.Command, args []string) error {
|
||||
func RootPostRunCmdFunc(_ *cobra.Command, _ []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func makeReloadChan() <-chan os.Signal {
|
||||
reload := make(chan os.Signal)
|
||||
reload := make(chan os.Signal, 1)
|
||||
signal.Notify(reload, syscall.SIGUSR1)
|
||||
return reload
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ func NewFrontend(logic frontend.TrackerLogic, provided Config) (*Frontend, error
|
||||
}
|
||||
}
|
||||
|
||||
if cfg.HTTPSAddr == "" || f.tlsCfg == nil {
|
||||
if (cfg.HTTPSAddr == "") != (f.tlsCfg == nil) {
|
||||
return nil, errors.New("must specify both https_addr, tls_cert_path and tls_key_path")
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +21,7 @@ func TestWriteError(t *testing.T) {
|
||||
for _, tt := range table {
|
||||
t.Run(fmt.Sprintf("%s expecting %s", tt.reason, tt.expected), func(t *testing.T) {
|
||||
r := httptest.NewRecorder()
|
||||
err := WriteError(r, bittorrent.ClientError(tt.reason))
|
||||
require.Nil(t, err)
|
||||
WriteError(r, bittorrent.ClientError(tt.reason))
|
||||
require.Equal(t, r.Body.String(), tt.expected)
|
||||
})
|
||||
}
|
||||
@@ -38,8 +37,7 @@ func TestWriteStatus(t *testing.T) {
|
||||
for _, tt := range table {
|
||||
t.Run(fmt.Sprintf("%s expecting %s", tt.reason, tt.expected), func(t *testing.T) {
|
||||
r := httptest.NewRecorder()
|
||||
err := WriteError(r, bittorrent.ClientError(tt.reason))
|
||||
require.Nil(t, err)
|
||||
WriteError(r, bittorrent.ClientError(tt.reason))
|
||||
require.Equal(t, r.Body.String(), tt.expected)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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