mirror of
https://github.com/sot-tech/mochi.git
synced 2026-05-16 21:04:51 -07:00
More thorough peer purging test, and tidy some style things
This commit is contained in:
@@ -154,8 +154,7 @@ func handleEvent(c tracker.Conn, a *models.Announce, p *models.Peer, u *models.U
|
||||
return
|
||||
}
|
||||
delete(t.Seeders, p.Key())
|
||||
}
|
||||
if t.InLeecherPool(p) {
|
||||
} else if t.InLeecherPool(p) {
|
||||
err = c.DeleteLeecher(t.Infohash, p.Key())
|
||||
if err != nil {
|
||||
return
|
||||
|
||||
@@ -30,6 +30,7 @@ func TestPrivateAnnounce(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
defer srv.Close()
|
||||
baseURL := srv.URL
|
||||
|
||||
|
||||
@@ -72,8 +72,7 @@ func TestTorrentPurging(t *testing.T) {
|
||||
_, status, err := fetchPath(torrentApiPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if status != http.StatusOK {
|
||||
} else if status != http.StatusOK {
|
||||
t.Fatalf("expected torrent to exist (got %s)", http.StatusText(status))
|
||||
}
|
||||
|
||||
@@ -85,8 +84,7 @@ func TestTorrentPurging(t *testing.T) {
|
||||
_, status, err = fetchPath(torrentApiPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if status != http.StatusNotFound {
|
||||
} else if status != http.StatusNotFound {
|
||||
t.Fatalf("expected torrent to have been purged (got %s)", http.StatusText(status))
|
||||
}
|
||||
}
|
||||
@@ -110,19 +108,25 @@ func TestStalePeerPurging(t *testing.T) {
|
||||
_, status, err := fetchPath(torrentApiPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if status != http.StatusOK {
|
||||
} else if status != http.StatusOK {
|
||||
t.Fatalf("expected torrent to exist (got %s)", http.StatusText(status))
|
||||
}
|
||||
|
||||
// Let them expire.
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
// Add a leecher.
|
||||
peer = makePeerParams("peer2", false)
|
||||
expected := makeResponse(1, 1, bencode.List{
|
||||
makePeerResponse("peer1"),
|
||||
})
|
||||
expected["interval"] = int64(0)
|
||||
checkAnnounce(peer, expected, srv, t)
|
||||
|
||||
// Let them both expire.
|
||||
time.Sleep(30 * time.Millisecond)
|
||||
|
||||
_, status, err = fetchPath(torrentApiPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if status != http.StatusNotFound {
|
||||
} else if status != http.StatusNotFound {
|
||||
t.Fatalf("expected torrent to have been purged (got %s)", http.StatusText(status))
|
||||
}
|
||||
}
|
||||
|
||||
1
main.go
1
main.go
@@ -60,6 +60,7 @@ func Boot() {
|
||||
if err != nil {
|
||||
glog.Fatalf("Failed to parse configuration file: %s\n", err)
|
||||
}
|
||||
|
||||
if cfg == &config.DefaultConfig {
|
||||
glog.V(1).Info("Using default config")
|
||||
} else {
|
||||
|
||||
@@ -250,6 +250,7 @@ func NewAnnounceDelta(a *Announce, p *Peer, u *User, t *Torrent, created, snatch
|
||||
if rawDeltaUp < 0 {
|
||||
rawDeltaUp = 0
|
||||
}
|
||||
|
||||
if rawDeltaDown < 0 {
|
||||
rawDeltaDown = 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user