aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Hanley <felix@userspace.com.au>2017-06-17 13:23:22 +0000
committerFelix Hanley <felix@userspace.com.au>2017-06-17 13:23:22 +0000
commitae07c61044d45e54652ce45dd75bf33ec48aa150 (patch)
treee3fd7e04f5086061efc576db9bdaccb8fcc996c2
parent38f4db10adce0dd5e93f9835e1bad49ed4f4276b (diff)
downloaddhtsearch-ae07c61044d45e54652ce45dd75bf33ec48aa150.tar.gz
dhtsearch-ae07c61044d45e54652ce45dd75bf33ec48aa150.tar.bz2
Reduce some logging with the 'quiet' flag
-rw-r--r--db.go1
-rwxr-xr-xdht.go3
-rwxr-xr-xmain.go16
3 files changed, 14 insertions, 6 deletions
diff --git a/db.go b/db.go
index 1bfc257..9e513dd 100644
--- a/db.go
+++ b/db.go
@@ -22,7 +22,6 @@ func newDB(dsn string) (*database, error) {
if err != nil {
return nil, err
}
- fmt.Printf("Found %d existing torrents\n", count)
torrentsTotal.Set(int64(count))
return &database{d, false}, nil
}
diff --git a/dht.go b/dht.go
index f78a2bf..d92c697 100755
--- a/dht.go
+++ b/dht.go
@@ -103,9 +103,10 @@ func (d *DHTNode) run(done <-chan struct{}) error {
if d.debug {
fmt.Printf("Error writing packet %s\n", err)
}
+ } else {
+ dhtPacketsOut.Add(1)
}
dhtBytesOut.Add(int64(b))
- dhtPacketsOut.Add(1)
}
}
}()
diff --git a/main.go b/main.go
index 270ae4b..ac2cb1b 100755
--- a/main.go
+++ b/main.go
@@ -41,11 +41,13 @@ func main() {
var basePort, numNodes int
var debug bool
+ var quiet bool
var noHttp bool
var dsn, httpAddress string
flag.IntVar(&basePort, "port", 6881, "listen port (and first of multiple ports)")
flag.IntVar(&numNodes, "nodes", 1, "number of nodes to start")
flag.BoolVar(&debug, "debug", false, "provide debug output")
+ flag.BoolVar(&quiet, "quiet", false, "log only errors")
flag.StringVar(&dsn, "dsn", "postgres://dht:dht@localhost/dht?sslmode=disable", "DB DSN")
flag.BoolVar(&noHttp, "no-http", false, "no HTTP service")
flag.StringVar(&httpAddress, "http", "localhost:6880", "HTTP listen address:port")
@@ -113,7 +115,9 @@ func main() {
http.HandleFunc("/search", searchHandler)
sock, _ := net.Listen("tcp", httpAddress)
go func() {
- fmt.Printf("HTTP now available at %s\n", httpAddress)
+ if !quiet {
+ fmt.Printf("HTTP now available at %s\n", httpAddress)
+ }
http.Serve(sock, nil)
}()
}
@@ -151,7 +155,9 @@ func main() {
var notWanted = false
for _, tag := range t.Tags {
if tag == "adult" {
- fmt.Printf("Skipping %s\n", t.Name)
+ if !quiet {
+ fmt.Printf("Skipping torrent: %q\n", t.Name)
+ }
notWanted = true
}
}
@@ -160,11 +166,13 @@ func main() {
continue
}
- fmt.Printf("Torrrent length: %d, name: %s, tags: %s, url: magnet:?xt=urn:btih:%s\n", length, t.Name, t.Tags, t.InfoHash)
-
err := t.save()
if err != nil {
fmt.Printf("Error saving torrent: %q\n", err)
+ continue
+ }
+ if !quiet {
+ fmt.Printf("Torrrent added, length: %d, name: %q, tags: %s, url: magnet:?xt=urn:btih:%s\n", length, t.Name, t.Tags, t.InfoHash)
}
torrentsSaved.Add(1)
torrentsTotal.Add(1)