mirror of
https://github.com/sot-tech/mochi.git
synced 2026-04-25 23:29:57 -07:00
(tested) fix redis to pass tests
* delete info hash count key from redis (replaced with SCARD on infohash set) * add GC test * add peer.Addr() functio to always return unwrapped address if 4to6 appear
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"net/netip"
|
||||
|
||||
"github.com/sot-tech/mochi/bittorrent"
|
||||
// used for seeding global math.Rand
|
||||
_ "github.com/sot-tech/mochi/pkg/randseed"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -13,13 +16,32 @@ var (
|
||||
v4Peer, v6Peer bittorrent.Peer
|
||||
)
|
||||
|
||||
func randIH(v2 bool) (ih bittorrent.InfoHash) {
|
||||
var b []byte
|
||||
if v2 {
|
||||
b = make([]byte, bittorrent.InfoHashV2Len)
|
||||
} else {
|
||||
b = make([]byte, bittorrent.InfoHashV1Len)
|
||||
}
|
||||
rand.Read(b)
|
||||
ih, _ = bittorrent.NewInfoHash(b)
|
||||
return
|
||||
}
|
||||
|
||||
func randPeerID() (ih bittorrent.PeerID) {
|
||||
b := make([]byte, bittorrent.PeerIDLen)
|
||||
rand.Read(b)
|
||||
ih, _ = bittorrent.NewPeerID(b)
|
||||
return
|
||||
}
|
||||
|
||||
func init() {
|
||||
testIh1, _ = bittorrent.NewInfoHash("00000000000000000001")
|
||||
testIh2, _ = bittorrent.NewInfoHash("00000000000000000002")
|
||||
testPeerID0, _ = bittorrent.NewPeerID([]byte("00000000000000000001"))
|
||||
testPeerID1, _ = bittorrent.NewPeerID([]byte("00000000000000000002"))
|
||||
testPeerID2, _ = bittorrent.NewPeerID([]byte("99999999999999999994"))
|
||||
testPeerID3, _ = bittorrent.NewPeerID([]byte("99999999999999999996"))
|
||||
testIh1 = randIH(false)
|
||||
testIh2 = randIH(true)
|
||||
testPeerID0 = randPeerID()
|
||||
testPeerID1 = randPeerID()
|
||||
testPeerID2 = randPeerID()
|
||||
testPeerID3 = randPeerID()
|
||||
testData = []hashPeer{
|
||||
{
|
||||
testIh1,
|
||||
|
||||
Reference in New Issue
Block a user