Skip to content

Commit

Permalink
Changes for dht-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
anacrolix committed Jul 20, 2017
1 parent 99b3f98 commit 2624281
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
12 changes: 9 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,15 @@ func NewClient(cfg *Config) (cl *Client, err error) {
if dhtCfg.IPBlocklist == nil {
dhtCfg.IPBlocklist = cl.ipBlockList
}
dhtCfg.Addr = firstNonEmptyString(dhtCfg.Addr, cl.listenAddr, cl.config.ListenAddr)
if dhtCfg.Conn == nil && cl.utpSock != nil {
dhtCfg.Conn = cl.utpSock
if dhtCfg.Conn == nil {
if cl.utpSock != nil {
dhtCfg.Conn = cl.utpSock
} else {
dhtCfg.Conn, err = net.ListenPacket("udp", firstNonEmptyString(cl.listenAddr, cl.config.ListenAddr))
if err != nil {
return
}
}
}
if dhtCfg.OnAnnouncePeer == nil {
dhtCfg.OnAnnouncePeer = cl.onDHTAnnouncePeer
Expand Down
11 changes: 5 additions & 6 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"testing"
"time"

"github.com/anacrolix/dht"
_ "github.com/anacrolix/envpprof"
"github.com/anacrolix/missinggo"
"github.com/anacrolix/missinggo/filecache"
Expand Down Expand Up @@ -49,9 +48,6 @@ func TestingConfig() *Config {
}
return ret
}(),
DHTConfig: dht.ServerConfig{
NoDefaultBootstrap: true,
},
Debug: true,
}
}
Expand Down Expand Up @@ -831,11 +827,14 @@ func TestAddMetainfoWithNodes(t *testing.T) {
cl, err := NewClient(cfg)
require.NoError(t, err)
defer cl.Close()
assert.EqualValues(t, cl.DHT().NumNodes(), 0)
assert.EqualValues(t, 0, cl.DHT().NumNodes()+cl.DHT().Stats().OutstandingTransactions)
tt, err := cl.AddTorrentFromFile("metainfo/testdata/issue_65a.torrent")
require.NoError(t, err)
// Nodes are not added or exposed in Torrent's metainfo. We just randomly
// check if the announce-list is here instead. TODO: Add nodes.
assert.Len(t, tt.metainfo.AnnounceList, 5)
assert.EqualValues(t, 6, cl.DHT().NumNodes())
// There are 6 nodes in the torrent file.
assert.EqualValues(t, 6, cl.DHT().NumNodes()+cl.DHT().Stats().OutstandingTransactions)
}

type testDownloadCancelParams struct {
Expand Down
2 changes: 1 addition & 1 deletion connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ func (c *connection) mainReadLoop() error {
if msg.Port != 0 {
pingAddr.Port = int(msg.Port)
}
go cl.dHT.Ping(pingAddr)
go cl.dHT.Ping(pingAddr, nil)
default:
err = fmt.Errorf("received unknown message type: %#v", msg.Type)
}
Expand Down

0 comments on commit 2624281

Please sign in to comment.