Skip to content

Commit

Permalink
Allow limiting the maximum number of connections
Browse files Browse the repository at this point in the history
Fixes #11.
  • Loading branch information
Sioro-Neoku committed Jul 7, 2016
1 parent 14daf24 commit 8d441bb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type Client struct {

// NewClient creates a new torrent client based on a magnet or a torrent file.
// If the torrent file is on http, we try downloading it.
func NewClient(torrentPath string, port int, seed bool, tcp bool) (client Client, err error) {
func NewClient(torrentPath string, port int, seed bool, tcp bool, maxConnections int) (client Client, err error) {
var t *torrent.Torrent
var c *torrent.Client

Expand Down Expand Up @@ -94,6 +94,7 @@ func NewClient(torrentPath string, port int, seed bool, tcp bool) (client Client
}

client.Torrent = t
client.Torrent.SetMaxEstablishedConns(maxConnections)

go func() {
<-t.GotInfo()
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ func main() {
var port int
var seed, tcp *bool
var player *string
var maxConnections int

player = flag.String("player", "", "Open the stream with a video player ("+joinPlayerNames()+")")
flag.IntVar(&port, "port", 8080, "Port to stream the video on")
seed = flag.Bool("seed", false, "Seed after finished downloading")
flag.IntVar(&maxConnections, "conn", 200, "Maximum number of connections")
tcp = flag.Bool("tcp", true, "Allow connections via TCP")
flag.Parse()
if len(flag.Args()) == 0 {
Expand All @@ -35,7 +37,7 @@ func main() {
}

// Start up the torrent client.
client, err := NewClient(flag.Arg(0), port, *seed, *tcp)
client, err := NewClient(flag.Arg(0), port, *seed, *tcp, maxConnections)
if err != nil {
log.Fatalf(err.Error())
os.Exit(exitErrorInClient)
Expand Down

0 comments on commit 8d441bb

Please sign in to comment.