From ef4aa0d3f9a0ad4152a5a80eaa83d47556932ec9 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Fri, 21 Mar 2014 00:13:32 +1100 Subject: [PATCH] Add -listenAddr and actually listen in ./cmd/torrent --- cmd/torrent/main.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cmd/torrent/main.go b/cmd/torrent/main.go index cbc9512b..3bcde987 100644 --- a/cmd/torrent/main.go +++ b/cmd/torrent/main.go @@ -18,6 +18,8 @@ var ( downloadDir = flag.String("downloadDir", "", "directory to store download torrent data") testPeer = flag.String("testPeer", "", "bootstrap peer address") profAddr = flag.String("profAddr", "", "http serve address") + // TODO: Check the default torrent listen port. + listenAddr = flag.String("listenAddr", ":6882", "incoming connection address") ) func init() { @@ -25,12 +27,21 @@ func init() { flag.Parse() } +func makeListener() net.Listener { + l, err := net.Listen("tcp", *listenAddr) + if err != nil { + log.Fatal(err) + } + return l +} + func main() { if *profAddr != "" { go http.ListenAndServe(*profAddr, nil) } client := torrent.Client{ - DataDir: *downloadDir, + DataDir: *downloadDir, + Listener: makeListener(), } client.Start() defer client.Stop() -- 2.48.1