Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPv6 support, windows build fix #77

Merged
merged 5 commits into from
Apr 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -24,7 +24,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))
}
}