From: Matt Joiner <anacrolix@gmail.com>
Date: Thu, 20 Mar 2014 13:13:32 +0000 (+1100)
Subject: Add -listenAddr and actually listen in ./cmd/torrent
X-Git-Tag: v1.0.0~1765
X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=ef4aa0d3f9a0ad4152a5a80eaa83d47556932ec9;p=btrtrc.git
Add -listenAddr and actually listen in ./cmd/torrent
---
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()