mirror of
https://github.com/LBRYFoundation/tracker.git
synced 2025-08-27 07:23:26 +00:00
Merge branch 'develop'
This commit is contained in:
commit
8c25e1ade3
6 changed files with 31 additions and 16 deletions
|
@ -20,7 +20,7 @@ changes in.
|
||||||
|
|
||||||
The average contribution flow is as follows:
|
The average contribution flow is as follows:
|
||||||
|
|
||||||
- Create a topic branch from where you want to base your work. This is usually master.
|
- Create a topic branch from where you want to base your work. This is usually `develop`.
|
||||||
- Make commits of logical units.
|
- Make commits of logical units.
|
||||||
- Make sure your commit messages are in the [proper format]
|
- Make sure your commit messages are in the [proper format]
|
||||||
- Push your changes to a topic branch in your fork of the repository.
|
- Push your changes to a topic branch in your fork of the repository.
|
||||||
|
|
2
Godeps/_workspace/src/golang.org/x/net/netutil/listen.go
generated
vendored
2
Godeps/_workspace/src/golang.org/x/net/netutil/listen.go
generated
vendored
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
// Package netutil provides network utility functions, complementing the more
|
// Package netutil provides network utility functions, complementing the more
|
||||||
// common ones in the net package.
|
// common ones in the net package.
|
||||||
package netutil // import "golang.org/x/net/netutil"
|
package netutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
|
|
@ -53,6 +53,10 @@ type Conn interface {
|
||||||
// down the driver
|
// down the driver
|
||||||
Close() error
|
Close() error
|
||||||
|
|
||||||
|
// Ping just checks to see if the database is still alive. This is typically
|
||||||
|
// used for health checks.
|
||||||
|
Ping() error
|
||||||
|
|
||||||
// RecordAnnounce is called once per announce, and is passed the delta in
|
// RecordAnnounce is called once per announce, and is passed the delta in
|
||||||
// statistics for the client peer since its last announce.
|
// statistics for the client peer since its last announce.
|
||||||
RecordAnnounce(delta *models.AnnounceDelta) error
|
RecordAnnounce(delta *models.AnnounceDelta) error
|
||||||
|
|
|
@ -14,6 +14,8 @@ import (
|
||||||
|
|
||||||
type driver struct{}
|
type driver struct{}
|
||||||
|
|
||||||
|
// NoOp is a backend driver for Chihaya that does nothing. This is used by
|
||||||
|
// public trackers.
|
||||||
type NoOp struct{}
|
type NoOp struct{}
|
||||||
|
|
||||||
// New returns a new Chihaya backend driver that does nothing.
|
// New returns a new Chihaya backend driver that does nothing.
|
||||||
|
@ -26,6 +28,11 @@ func (n *NoOp) Close() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ping returns nil.
|
||||||
|
func (n *NoOp) Ping() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// RecordAnnounce returns nil.
|
// RecordAnnounce returns nil.
|
||||||
func (n *NoOp) RecordAnnounce(delta *models.AnnounceDelta) error {
|
func (n *NoOp) RecordAnnounce(delta *models.AnnounceDelta) error {
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -33,6 +33,10 @@ func handleError(err error) (int, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) check(w http.ResponseWriter, r *http.Request, p httprouter.Params) (int, error) {
|
func (s *Server) check(w http.ResponseWriter, r *http.Request, p httprouter.Params) (int, error) {
|
||||||
|
// Ping the backend if private tracker is enabled.
|
||||||
|
if err := s.tracker.Backend.Ping(); s.config.PrivateEnabled && err != nil {
|
||||||
|
return handleError(err)
|
||||||
|
}
|
||||||
_, err := w.Write([]byte("STILL-ALIVE"))
|
_, err := w.Write([]byte("STILL-ALIVE"))
|
||||||
return handleError(err)
|
return handleError(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,14 +48,14 @@ func (s *Storage) Len() int {
|
||||||
return int(atomic.LoadInt32(&s.size))
|
return int(atomic.LoadInt32(&s.size))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) GetShardIndex(infohash string) uint32 {
|
func (s *Storage) getShardIndex(infohash string) uint32 {
|
||||||
idx := fnv.New32()
|
idx := fnv.New32()
|
||||||
idx.Write([]byte(infohash))
|
idx.Write([]byte(infohash))
|
||||||
return idx.Sum32() % uint32(len(s.shards))
|
return idx.Sum32() % uint32(len(s.shards))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) GetTorrentShard(infohash string, readonly bool) *Torrents {
|
func (s *Storage) getTorrentShard(infohash string, readonly bool) *Torrents {
|
||||||
shardindex := s.GetShardIndex(infohash)
|
shardindex := s.getShardIndex(infohash)
|
||||||
if readonly {
|
if readonly {
|
||||||
s.shards[shardindex].RLock()
|
s.shards[shardindex].RLock()
|
||||||
} else {
|
} else {
|
||||||
|
@ -65,7 +65,7 @@ func (s *Storage) GetTorrentShard(infohash string, readonly bool) *Torrents {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) TouchTorrent(infohash string) error {
|
func (s *Storage) TouchTorrent(infohash string) error {
|
||||||
shard := s.GetTorrentShard(infohash, false)
|
shard := s.getTorrentShard(infohash, false)
|
||||||
defer shard.Unlock()
|
defer shard.Unlock()
|
||||||
|
|
||||||
torrent, exists := shard.torrents[infohash]
|
torrent, exists := shard.torrents[infohash]
|
||||||
|
@ -79,7 +79,7 @@ func (s *Storage) TouchTorrent(infohash string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) FindTorrent(infohash string) (*models.Torrent, error) {
|
func (s *Storage) FindTorrent(infohash string) (*models.Torrent, error) {
|
||||||
shard := s.GetTorrentShard(infohash, true)
|
shard := s.getTorrentShard(infohash, true)
|
||||||
defer shard.RUnlock()
|
defer shard.RUnlock()
|
||||||
|
|
||||||
torrent, exists := shard.torrents[infohash]
|
torrent, exists := shard.torrents[infohash]
|
||||||
|
@ -91,7 +91,7 @@ func (s *Storage) FindTorrent(infohash string) (*models.Torrent, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) PutTorrent(torrent *models.Torrent) {
|
func (s *Storage) PutTorrent(torrent *models.Torrent) {
|
||||||
shard := s.GetTorrentShard(torrent.Infohash, false)
|
shard := s.getTorrentShard(torrent.Infohash, false)
|
||||||
defer shard.Unlock()
|
defer shard.Unlock()
|
||||||
|
|
||||||
_, exists := shard.torrents[torrent.Infohash]
|
_, exists := shard.torrents[torrent.Infohash]
|
||||||
|
@ -102,7 +102,7 @@ func (s *Storage) PutTorrent(torrent *models.Torrent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) DeleteTorrent(infohash string) {
|
func (s *Storage) DeleteTorrent(infohash string) {
|
||||||
shard := s.GetTorrentShard(infohash, false)
|
shard := s.getTorrentShard(infohash, false)
|
||||||
defer shard.Unlock()
|
defer shard.Unlock()
|
||||||
|
|
||||||
if _, exists := shard.torrents[infohash]; exists {
|
if _, exists := shard.torrents[infohash]; exists {
|
||||||
|
@ -112,7 +112,7 @@ func (s *Storage) DeleteTorrent(infohash string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) IncrementTorrentSnatches(infohash string) error {
|
func (s *Storage) IncrementTorrentSnatches(infohash string) error {
|
||||||
shard := s.GetTorrentShard(infohash, false)
|
shard := s.getTorrentShard(infohash, false)
|
||||||
defer shard.Unlock()
|
defer shard.Unlock()
|
||||||
|
|
||||||
torrent, exists := shard.torrents[infohash]
|
torrent, exists := shard.torrents[infohash]
|
||||||
|
@ -126,7 +126,7 @@ func (s *Storage) IncrementTorrentSnatches(infohash string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) PutLeecher(infohash string, p *models.Peer) error {
|
func (s *Storage) PutLeecher(infohash string, p *models.Peer) error {
|
||||||
shard := s.GetTorrentShard(infohash, false)
|
shard := s.getTorrentShard(infohash, false)
|
||||||
defer shard.Unlock()
|
defer shard.Unlock()
|
||||||
|
|
||||||
torrent, exists := shard.torrents[infohash]
|
torrent, exists := shard.torrents[infohash]
|
||||||
|
@ -140,7 +140,7 @@ func (s *Storage) PutLeecher(infohash string, p *models.Peer) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) DeleteLeecher(infohash string, p *models.Peer) error {
|
func (s *Storage) DeleteLeecher(infohash string, p *models.Peer) error {
|
||||||
shard := s.GetTorrentShard(infohash, false)
|
shard := s.getTorrentShard(infohash, false)
|
||||||
defer shard.Unlock()
|
defer shard.Unlock()
|
||||||
|
|
||||||
torrent, exists := shard.torrents[infohash]
|
torrent, exists := shard.torrents[infohash]
|
||||||
|
@ -154,7 +154,7 @@ func (s *Storage) DeleteLeecher(infohash string, p *models.Peer) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) PutSeeder(infohash string, p *models.Peer) error {
|
func (s *Storage) PutSeeder(infohash string, p *models.Peer) error {
|
||||||
shard := s.GetTorrentShard(infohash, false)
|
shard := s.getTorrentShard(infohash, false)
|
||||||
defer shard.Unlock()
|
defer shard.Unlock()
|
||||||
|
|
||||||
torrent, exists := shard.torrents[infohash]
|
torrent, exists := shard.torrents[infohash]
|
||||||
|
@ -168,7 +168,7 @@ func (s *Storage) PutSeeder(infohash string, p *models.Peer) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) DeleteSeeder(infohash string, p *models.Peer) error {
|
func (s *Storage) DeleteSeeder(infohash string, p *models.Peer) error {
|
||||||
shard := s.GetTorrentShard(infohash, false)
|
shard := s.getTorrentShard(infohash, false)
|
||||||
defer shard.Unlock()
|
defer shard.Unlock()
|
||||||
|
|
||||||
torrent, exists := shard.torrents[infohash]
|
torrent, exists := shard.torrents[infohash]
|
||||||
|
@ -182,7 +182,7 @@ func (s *Storage) DeleteSeeder(infohash string, p *models.Peer) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) PurgeInactiveTorrent(infohash string) error {
|
func (s *Storage) PurgeInactiveTorrent(infohash string) error {
|
||||||
shard := s.GetTorrentShard(infohash, false)
|
shard := s.getTorrentShard(infohash, false)
|
||||||
defer shard.Unlock()
|
defer shard.Unlock()
|
||||||
|
|
||||||
torrent, exists := shard.torrents[infohash]
|
torrent, exists := shard.torrents[infohash]
|
||||||
|
@ -223,7 +223,7 @@ func (s *Storage) PurgeInactivePeers(purgeEmptyTorrents bool, before time.Time)
|
||||||
// Process the keys while allowing other goroutines to run.
|
// Process the keys while allowing other goroutines to run.
|
||||||
for _, infohash := range keys {
|
for _, infohash := range keys {
|
||||||
runtime.Gosched()
|
runtime.Gosched()
|
||||||
shard := s.GetTorrentShard(infohash, false)
|
shard := s.getTorrentShard(infohash, false)
|
||||||
torrent := shard.torrents[infohash]
|
torrent := shard.torrents[infohash]
|
||||||
|
|
||||||
if torrent == nil {
|
if torrent == nil {
|
||||||
|
|
Loading…
Add table
Reference in a new issue