Skip to content

Commit

Permalink
IPv6 support, windows build fix (#77)
Browse files Browse the repository at this point in the history
* add ipv6 support, update readme

* add .exe to windows binaries

* update readme

* delete showing absDir

* add  (default all, ipv4 and ipv6) to the addr flag
  • Loading branch information
tadev authored and fanpei91 committed Jan 11, 2020
1 parent 01e210b commit e81c707
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Usage:
torsniff [flags]
Flags:
-a, --addr string listen on given address (default "0.0.0.0")
-a, --addr string listen on given address (default all, ipv4 and ipv6)
-d, --dir string the directory to store the torrents (default "$HOME/torrents")
-h, --help help for torsniff
-f, --friends int max fiends to make with per second (default 500)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Usage:
torsniff [flags]
Flags:
-a, --addr string listen on given address (default "0.0.0.0")
-a, --addr string listen on given address (default all, ipv4 and ipv6)
-d, --dir string the directory to store the torrents (default "$HOME/torrents")
-h, --help help for torsniff
-f, --friends int max fiends to make with per second (default 500)
Expand Down
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
GOARCH=amd64 GOOS=linux go build -o releases/torsniff-${VERSION}-linux-amd64
GOARCH=386 GOOS=linux go build -o releases/torsniff-${VERSION}-linux-386

GOARCH=amd64 GOOS=windows go build -o releases/torsniff-${VERSION}-windows-amd64
GOARCH=386 GOOS=windows go build -o releases/torsniff-${VERSION}-windows-386
GOARCH=amd64 GOOS=windows go build -o releases/torsniff-${VERSION}-windows-amd64.exe
GOARCH=386 GOOS=windows go build -o releases/torsniff-${VERSION}-windows-386.exe

GOARCH=amd64 GOOS=darwin go build -o releases/torsniff-${VERSION}-darwin-amd64
4 changes: 2 additions & 2 deletions dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ type dht struct {
}

func newDHT(laddr string, maxFriendsPerSec int) (*dht, error) {
conn, err := net.ListenPacket("udp4", laddr)
conn, err := net.ListenPacket("udp", laddr)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -277,7 +277,7 @@ func (d *dht) findNode(to string, target nodeID) {
"target": string(randBytes(20)),
})

addr, err := net.ResolveUDPAddr("udp4", to)
addr, err := net.ResolveUDPAddr("udp", to)
if err != nil {
return
}
Expand Down
9 changes: 5 additions & 4 deletions torsniff.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import (
"fmt"
"io/ioutil"
"log"
"net"
"os"
"path"
"path/filepath"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -143,7 +145,6 @@ func (t *torsniff) run() error {
}
}

return nil
}

func (t *torsniff) work(ac *announcement, tokens chan struct{}) {
Expand Down Expand Up @@ -258,7 +259,7 @@ func main() {
}

p := &torsniff{
laddr: fmt.Sprintf("%s:%d", addr, port),
laddr: net.JoinHostPort(addr, strconv.Itoa(int(port))),
timeout: timeout,
maxFriends: friends,
maxPeers: peers,
Expand All @@ -269,7 +270,7 @@ func main() {
return p.run()
}

root.Flags().StringVarP(&addr, "addr", "a", "0.0.0.0", "listen on given address")
root.Flags().StringVarP(&addr, "addr", "a", "", "listen on given address (default all, ipv4 and ipv6)")
root.Flags().Uint16VarP(&port, "port", "p", 6881, "listen on given port")
root.Flags().IntVarP(&friends, "friends", "f", 500, "max fiends to make with per second")
root.Flags().IntVarP(&peers, "peers", "e", 400, "max peers to connect to download torrents")
Expand All @@ -278,6 +279,6 @@ func main() {
root.Flags().BoolVarP(&verbose, "verbose", "v", true, "run in verbose mode")

if err := root.Execute(); err != nil {
fmt.Errorf("could not start: %s\n", err)
fmt.Println(fmt.Errorf("could not start: %s", err))
}
}

0 comments on commit e81c707

Please sign in to comment.