mirror of
https://github.com/sot-tech/mochi.git
synced 2026-04-25 23:29:57 -07:00
* 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
59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
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 (
|
|
testIh1, testIh2 bittorrent.InfoHash
|
|
testPeerID0, testPeerID1, testPeerID2, testPeerID3 bittorrent.PeerID
|
|
testData []hashPeer
|
|
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 = randIH(false)
|
|
testIh2 = randIH(true)
|
|
testPeerID0 = randPeerID()
|
|
testPeerID1 = randPeerID()
|
|
testPeerID2 = randPeerID()
|
|
testPeerID3 = randPeerID()
|
|
testData = []hashPeer{
|
|
{
|
|
testIh1,
|
|
bittorrent.Peer{ID: testPeerID0, AddrPort: netip.MustParseAddrPort("1.1.1.1:1")},
|
|
},
|
|
{
|
|
testIh2,
|
|
bittorrent.Peer{ID: testPeerID1, AddrPort: netip.MustParseAddrPort("[abab::0001]:2")},
|
|
},
|
|
}
|
|
|
|
v4Peer = bittorrent.Peer{ID: testPeerID2, AddrPort: netip.MustParseAddrPort("99.99.99.99:9994")}
|
|
v6Peer = bittorrent.Peer{ID: testPeerID3, AddrPort: netip.MustParseAddrPort("[fc00::0001]:9996")}
|
|
}
|