parent
0ceefca9c1
commit
140a738162
4 changed files with 22 additions and 31 deletions
|
@ -205,7 +205,7 @@ func (s Server) serveAnnounce(w http.ResponseWriter, r *http.Request) {
|
|||
} else {
|
||||
// If they're leeching, prioritize giving them seeders
|
||||
count += writeSeeders(w, user, torrent, numWant, compact)
|
||||
count += writeLeechers(w, user, torrent, numWant - count, compact)
|
||||
count += writeLeechers(w, user, torrent, numWant-count, compact)
|
||||
}
|
||||
|
||||
if compact && peerCount != count {
|
||||
|
|
|
@ -127,10 +127,15 @@ func validateUser(conn tracker.Conn, dir string) (*storage.User, error) {
|
|||
|
||||
// Takes a peer_id and returns a ClientID
|
||||
func parsePeerID(peerID string) (clientID string) {
|
||||
if peerID[0] == '-' {
|
||||
clientID = peerID[1:7]
|
||||
} else {
|
||||
clientID = peerID[0:6]
|
||||
length := len(peerID)
|
||||
if length >= 6 {
|
||||
if peerID[0] == '-' {
|
||||
if length >= 7 {
|
||||
clientID = peerID[1:7]
|
||||
}
|
||||
} else {
|
||||
clientID = peerID[0:6]
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ type PeerClientPair struct {
|
|||
}
|
||||
|
||||
var (
|
||||
AzTestClients = []PeerClientPair{
|
||||
TestClients = []PeerClientPair{
|
||||
{"-AZ3034-6wfG2wk6wWLc", "AZ3034"},
|
||||
{"-AZ3042-6ozMq5q6Q3NX", "AZ3042"},
|
||||
{"-BS5820-oy4La2MWGEFj", "BS5820"},
|
||||
|
@ -33,15 +33,11 @@ var (
|
|||
{"-A~0010-a9mn9DFkj39J", "A~0010"},
|
||||
{"-UT2300-MNu93JKnm930", "UT2300"},
|
||||
{"-UT2300-KT4310KT4301", "UT2300"},
|
||||
}
|
||||
|
||||
ShadowTestClients = []PeerClientPair{
|
||||
{"T03A0----f089kjsdf6e", "T03A0-"},
|
||||
{"S58B-----nKl34GoNb75", "S58B--"},
|
||||
{"M4-4-0--9aa757Efd5Bl", "M4-4-0"},
|
||||
}
|
||||
|
||||
OtherTestClients = []PeerClientPair{
|
||||
{"AZ2500BTeYUzyabAfo6U", "AZ2500"}, // BitTyrant
|
||||
{"exbc0JdSklm834kj9Udf", "exbc0J"}, // Old BitComet
|
||||
{"FUTB0L84j542mVc84jkd", "FUTB0L"}, // Alt BitComet
|
||||
|
@ -53,29 +49,20 @@ var (
|
|||
{"Q1-10-0-Yoiumn39BDfO", "Q1-10-"}, // Queen Bee Alt
|
||||
{"346------SDFknl33408", "346---"}, // TorreTopia
|
||||
{"QVOD0054ABFFEDCCDEDB", "QVOD00"}, // Qvod
|
||||
|
||||
{"", ""},
|
||||
{"-", ""},
|
||||
{"12345", ""},
|
||||
{"-12345", ""},
|
||||
{"123456", "123456"},
|
||||
{"-123456", "123456"},
|
||||
}
|
||||
)
|
||||
|
||||
func TestParseAZClientID(t *testing.T) {
|
||||
for _, pair := range AzTestClients {
|
||||
if pair.clientId != parsePeerID(pair.peerId) {
|
||||
t.Error("PeerID incorrectly parsed", pair)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseShadowClientID(t *testing.T) {
|
||||
for _, pair := range ShadowTestClients {
|
||||
if pair.clientId != parsePeerID(pair.peerId) {
|
||||
t.Error("PeerID incorrectly parsed", pair)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseOtherClientID(t *testing.T) {
|
||||
for _, pair := range OtherTestClients {
|
||||
if pair.clientId != parsePeerID(pair.peerId) {
|
||||
t.Error("PeerID incorrectly parsed", pair)
|
||||
func TestParseClientID(t *testing.T) {
|
||||
for _, pair := range TestClients {
|
||||
if parsedId := parsePeerID(pair.peerId); parsedId != pair.clientId {
|
||||
t.Error("Incorrectly parsed peer ID", pair.peerId, "as", parsedId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,4 +26,3 @@ func (d *driver) New(conf *config.DataStore) tracker.Pool {
|
|||
func init() {
|
||||
tracker.Register("mock", &driver{})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue