Commit 16dffd3c authored by Matt Joiner's avatar Matt Joiner
Browse files

Add debug flag to cmd/dht-announce

parent 5215b74f
package main
import (
"log"
"net"
"os"
"sync"
"github.com/anacrolix/log"
_ "github.com/anacrolix/envpprof"
"github.com/anacrolix/tagflag"
......@@ -12,15 +14,30 @@ import (
)
func main() {
code := mainErr()
if code != 0 {
os.Exit(code)
}
}
func mainErr() int {
var flags = struct {
Port int
Port int
Debug bool
tagflag.StartPos
Infohash [][20]byte
}{}
tagflag.Parse(&flags)
s, err := dht.NewServer(nil)
s, err := dht.NewServer(func() *dht.ServerConfig {
sc := dht.NewDefaultServerConfig()
if flags.Debug {
sc.Logger = log.Default
}
return sc
}())
if err != nil {
log.Fatalf("error creating server: %s", err)
log.Printf("error creating server: %s", err)
return 1
}
defer s.Close()
wg := sync.WaitGroup{}
......@@ -58,4 +75,5 @@ func main() {
}
log.Printf("%x: %d addrs %d distinct ips", ih, len(addrs[ih]), len(ips))
}
return 0
}
......@@ -131,15 +131,19 @@ func (s *Server) Addr() net.Addr {
return s.socket.LocalAddr()
}
func NewDefaultServerConfig() *ServerConfig {
return &ServerConfig{
Conn: mustListen(":0"),
NoSecurity: true,
StartingNodes: GlobalBootstrapAddrs,
ConnectionTracking: conntrack.NewInstance(),
}
}
// NewServer initializes a new DHT node server.
func NewServer(c *ServerConfig) (s *Server, err error) {
if c == nil {
c = &ServerConfig{
Conn: mustListen(":0"),
NoSecurity: true,
StartingNodes: GlobalBootstrapAddrs,
ConnectionTracking: conntrack.NewInstance(),
}
c = NewDefaultServerConfig()
}
if c.Conn == nil {
return nil, errors.New("non-nil Conn required")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment