Skip to content
This repository has been archived by the owner on Jul 13, 2019. It is now read-only.

Commit

Permalink
Turn off logging noise from anacrolix/torrent
Browse files Browse the repository at this point in the history
For now, set os.Stdout = nil and log to file instead

Reference: anacrolix/torrent#271
  • Loading branch information
koffeeboi committed Jun 6, 2019
1 parent 461c9e4 commit baa18f4
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 6 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ bin

# I don't know why github.com/anacrolix/torrent is using these for storage
.torrent.bolt.db
.torrent.bolt.db.lock
.torrent.bolt.db.lock

*.log
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,14 @@ $ bin/kabedon-nyaa
```

# Notes
github.com/anacrolix/torrent uses github.com/anacrolix/go-libutp which is a go wrapper for github.com/bittorrent/libutp and it requires gcc to compile bittorrent's transport protocol library.
github.com/anacrolix/torrent uses github.com/anacrolix/go-libutp which is a go wrapper for github.com/bittorrent/libutp and it requires gcc to compile bittorrent's transport protocol library.

github.com/anacrolix/torrent client doesn't expose the logger. Unfortunately, it's outputting a lot of noise.
```bash
$ ./kabedon-nyaa
go-libutp: 2019/06/06 03:53:10 socket.go:172: ignoring socket read error: read udp4 0.0.0.0:58865: wsarecvfrom: The connection has been broken due to keep-alive activity detecting a failure while the operation was in progress.
go-libutp: 2019/06/06 03:53:11 socket.go:172: ignoring socket read error: read udp4 0.0.0.0:58865: wsarecvfrom: The connection has been broken due to keep-alive activity detecting a failure while the operation was in progress.
go-libutp: 2019/06/06 03:53:11 socket.go:172: ignoring socket read error: read udp4 0.0.0.0:58865: wsarecvfrom: The connection has been broken due to keep-alive activity detecting a failure while the operation was in progress.
2019-06-06 03:53:12 portfwd.go:31: discovered 0 upnp devices
```
Turn it off by setting os.Stdout = nil and just log to a file instead, though this can be disadvantageous...
22 changes: 19 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"os"
"fmt"
"log"
"github.com/greenmochi/kabedon-nyaa/torrent"
)

Expand All @@ -13,12 +14,27 @@ const (
func main() {
// Run gRPC service, uncomment/comment when you don't want it running
//grpc.RunGRPC(port)

// anacrolix/torrent is outputting crazy noise, turn it off and log to file instead
os.Stdout = nil

f, err := os.Create("kabedon-nyaa.log")
if err != nil {
log.Println("unable to create log file")
}
defer f.Close()

client, err := torrent.NewClient()
if err != nil {
fmt.Println(err)
fmt.Fprintf(f, "%+v\n", err)
os.Exit(1)
}
if client != nil {
fmt.Println("client no nil")
defer client.Close()

fmt.Fprintf(f, "Adding magnet")
magnet := "magnet:?xt=urn:btih:464aa94a230061049a1017c7550e6cf724aa9767&dn=%5BHorribleSubs%5D%20Sewayaki%20Kitsune%20no%20Senko-san%20-%2009%20%5B360p%5D.mkv&tr=http%3A%2F%2Fnyaa.tracker.wf%3A7777%2Fannounce&tr=udp%3A%2F%2Fopen.stealth.si%3A80%2Fannounce&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969%2Fannounce&tr=udp%3A%2F%2Fexodus.desync.com%3A6969%2Fannounce"
if ok := client.AddMagnet(magnet); !ok {
fmt.Fprintf(f, "unable to add magnet")
}
fmt.Fprintf(f, "done")
}
23 changes: 22 additions & 1 deletion torrent/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,36 @@ import "github.com/anacrolix/torrent"
// Client wraps the torrent client
type Client struct {
client *torrent.Client
torrents []*torrent.Torrent
}

// NewClient wraps anacrolix torrent new client
// NewClient wraps NewClient
func NewClient() (*Client, error) {
client, err := torrent.NewClient(nil)
if err != nil {
return nil, err
}

return &Client{
client: client,
}, nil
}

// Close wraps Close
func (c *Client) Close() {
c.Close()
}

// AddMagnet wraps AddMagnet
func (c *Client) AddMagnet(uri string) bool {
torrent, err := c.client.AddMagnet(uri)
if err != nil {
return false
}

<- torrent.GotInfo()
torrent.DownloadAll()
c.client.WaitAll()
c.torrents = append(c.torrents, torrent)
return true
}

0 comments on commit baa18f4

Please sign in to comment.