mirror of
https://github.com/LBRYFoundation/tracker.git
synced 2025-08-30 17:01:32 +00:00
log->glog; more bencode fixes
This commit is contained in:
parent
834e584f2d
commit
9cb5b82dc7
5 changed files with 36 additions and 33 deletions
|
@ -11,7 +11,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
log "github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Duration wraps a time.Duration and adds JSON marshalling.
|
// Duration wraps a time.Duration and adds JSON marshalling.
|
||||||
|
@ -88,7 +88,7 @@ func New() *Config {
|
||||||
// New.
|
// New.
|
||||||
func Open(path string) (*Config, error) {
|
func Open(path string) (*Config, error) {
|
||||||
if path == "" {
|
if path == "" {
|
||||||
log.V(1).Info("using default config")
|
glog.V(1).Info("using default config")
|
||||||
return New(), nil
|
return New(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ func Open(path string) (*Config, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
log.V(1).Infof("loaded config file: %s", path)
|
glog.V(1).Infof("loaded config file: %s", path)
|
||||||
return conf, nil
|
return conf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
22
main.go
22
main.go
|
@ -11,7 +11,7 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
|
|
||||||
log "github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
|
|
||||||
"github.com/chihaya/chihaya/config"
|
"github.com/chihaya/chihaya/config"
|
||||||
_ "github.com/chihaya/chihaya/drivers/backend/mock"
|
_ "github.com/chihaya/chihaya/drivers/backend/mock"
|
||||||
|
@ -37,29 +37,29 @@ func main() {
|
||||||
if profile {
|
if profile {
|
||||||
f, err := os.Create("chihaya.cpu")
|
f, err := os.Create("chihaya.cpu")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("failed to create profile file: %s\n", err)
|
glog.Fatalf("failed to create profile file: %s\n", err)
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
pprof.StartCPUProfile(f)
|
pprof.StartCPUProfile(f)
|
||||||
log.V(1).Info("started profiling")
|
glog.V(1).Info("started profiling")
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
pprof.StopCPUProfile()
|
pprof.StopCPUProfile()
|
||||||
log.V(1).Info("stopped profiling")
|
glog.V(1).Info("stopped profiling")
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the config file.
|
// Load the config file.
|
||||||
conf, err := config.Open(configPath)
|
conf, err := config.Open(configPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("failed to parse configuration file: %s\n", err)
|
glog.Fatalf("failed to parse configuration file: %s\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new server.
|
// Create a new server.
|
||||||
s, err := server.New(conf)
|
s, err := server.New(conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("failed to create server: %s\n", err)
|
glog.Fatalf("failed to create server: %s\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Spawn a goroutine to handle interrupts and safely shut down.
|
// Spawn a goroutine to handle interrupts and safely shut down.
|
||||||
|
@ -68,24 +68,24 @@ func main() {
|
||||||
signal.Notify(interrupts, os.Interrupt)
|
signal.Notify(interrupts, os.Interrupt)
|
||||||
|
|
||||||
<-interrupts
|
<-interrupts
|
||||||
log.V(1).Info("caught interrupt, shutting down...")
|
glog.V(1).Info("caught interrupt, shutting down...")
|
||||||
|
|
||||||
err := s.Stop()
|
err := s.Stop()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("failed to shutdown cleanly: %s", err)
|
glog.Fatalf("failed to shutdown cleanly: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.V(1).Info("shutdown cleanly")
|
glog.V(1).Info("shutdown cleanly")
|
||||||
|
|
||||||
<-interrupts
|
<-interrupts
|
||||||
|
|
||||||
log.Flush()
|
glog.Flush()
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Start the server listening and handling requests.
|
// Start the server listening and handling requests.
|
||||||
err = s.ListenAndServe()
|
err = s.ListenAndServe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("failed to start server: %s\n", err)
|
glog.Fatalf("failed to start server: %s\n", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
log "github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
|
|
||||||
"github.com/chihaya/chihaya/bencode"
|
"github.com/chihaya/chihaya/bencode"
|
||||||
"github.com/chihaya/chihaya/drivers/tracker"
|
"github.com/chihaya/chihaya/drivers/tracker"
|
||||||
|
@ -74,19 +74,14 @@ func (s Server) serveAnnounce(w http.ResponseWriter, r *http.Request) {
|
||||||
w.(http.Flusher).Flush()
|
w.(http.Flusher).Flush()
|
||||||
|
|
||||||
if s.conf.Private {
|
if s.conf.Private {
|
||||||
|
glog.V(5).Infof(
|
||||||
log.V(5).Infof(
|
|
||||||
"announce: ip: %s user: %s torrent: %s",
|
"announce: ip: %s user: %s torrent: %s",
|
||||||
announce.IP,
|
announce.IP,
|
||||||
user.ID,
|
user.ID,
|
||||||
torrent.ID,
|
torrent.ID,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
log.V(5).Infof(
|
glog.V(5).Infof("announce: ip: %s torrent: %s", announce.IP, torrent.ID)
|
||||||
"announce: ip: %s torrent: %s",
|
|
||||||
announce.IP,
|
|
||||||
torrent.ID,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
log "github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
|
|
||||||
"github.com/chihaya/chihaya/bencode"
|
"github.com/chihaya/chihaya/bencode"
|
||||||
"github.com/chihaya/chihaya/models"
|
"github.com/chihaya/chihaya/models"
|
||||||
|
@ -52,21 +52,29 @@ func (s *Server) serveScrape(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bencoder := bencode.NewEncoder(w)
|
bencoder := bencode.NewEncoder(w)
|
||||||
bencoder.Encode("d")
|
fmt.Fprintf(w, "d")
|
||||||
bencoder.Encode("files")
|
bencoder.Encode("files")
|
||||||
for _, torrent := range torrents {
|
for _, torrent := range torrents {
|
||||||
writeTorrentStatus(w, torrent)
|
writeTorrentStatus(w, torrent)
|
||||||
}
|
}
|
||||||
bencoder.Encode("e")
|
fmt.Fprintf(w, "e")
|
||||||
|
|
||||||
w.(http.Flusher).Flush()
|
w.(http.Flusher).Flush()
|
||||||
|
|
||||||
log.V(5).Infof(
|
if s.conf.Private {
|
||||||
|
glog.V(5).Infof(
|
||||||
"scrape: ip: %s user: %s torrents: %s",
|
"scrape: ip: %s user: %s torrents: %s",
|
||||||
r.RemoteAddr,
|
r.RemoteAddr,
|
||||||
user.ID,
|
user.ID,
|
||||||
strings.Join(torrentIDs, ", "),
|
strings.Join(torrentIDs, ", "),
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
glog.V(5).Infof(
|
||||||
|
"scrape: ip: %s torrents: %s",
|
||||||
|
r.RemoteAddr,
|
||||||
|
strings.Join(torrentIDs, ", "),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeTorrentStatus(w io.Writer, t *models.Torrent) {
|
func writeTorrentStatus(w io.Writer, t *models.Torrent) {
|
||||||
|
|
|
@ -16,7 +16,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/etix/stoppableListener"
|
"github.com/etix/stoppableListener"
|
||||||
log "github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
|
|
||||||
"github.com/chihaya/chihaya/config"
|
"github.com/chihaya/chihaya/config"
|
||||||
"github.com/chihaya/chihaya/drivers/backend"
|
"github.com/chihaya/chihaya/drivers/backend"
|
||||||
|
@ -130,7 +130,7 @@ func fail(err error, w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
w.(http.Flusher).Flush()
|
w.(http.Flusher).Flush()
|
||||||
|
|
||||||
log.V(5).Infof(
|
glog.V(5).Infof(
|
||||||
"failed request: ip: %s failure: %s",
|
"failed request: ip: %s failure: %s",
|
||||||
r.RemoteAddr,
|
r.RemoteAddr,
|
||||||
errmsg,
|
errmsg,
|
||||||
|
|
Loading…
Add table
Reference in a new issue