resolve merge conflict

This commit is contained in:
idk
2022-09-02 19:27:47 -04:00
5 changed files with 12 additions and 11 deletions

View File

@ -120,8 +120,8 @@ func TestDecode(t *testing.T) {
{`d1:X3:foo1:Yi10e1:h3:bare`, new(dT), dT{"foo", 10, ""}, false, false},
{`d3:fooli0ei1ee3:barli2ei3eee`, new(map[string][]int), map[string][]int{
"foo": []int{0, 1},
"bar": []int{2, 3},
"foo": {0, 1},
"bar": {2, 3},
}, false, false},
{`de`, new(map[string]string), map[string]string{}, false, false},

View File

@ -112,8 +112,8 @@ func TestEncode(t *testing.T) {
{"c": 2, "d": 3},
}, `ld1:ai0e1:bi1eed1:ci2e1:di3eee`, false},
{[][]byte{
[]byte{'0', '2', '4', '6', '8'},
[]byte{'a', 'c', 'e'},
{'0', '2', '4', '6', '8'},
{'a', 'c', 'e'},
}, `l5:024683:acee`, false},
{(*[]interface{})(nil), ``, false},

View File

@ -153,7 +153,7 @@ func (bl *blacklist) Add(ip string, port int) {
wp.Enable = false
wp.Ports = nil
} else if wp.Ports == nil {
wp.Ports = map[int]struct{}{port: struct{}{}}
wp.Ports = map[int]struct{}{port: {}}
} else {
wp.Ports[port] = struct{}{}
}

View File

@ -469,6 +469,7 @@ func (s *Server) handleQuery(raddr net.Addr, m krpc.Message) {
switch m.Q {
case queryMethodPing:
s.reply(raddr, m.T, krpc.ResponseResult{})
case queryMethodFindNode: // See BEP 32
var r krpc.ResponseResult
n4 := m.A.ContainsWant(krpc.WantNodes)
@ -488,6 +489,7 @@ func (s *Server) handleQuery(raddr net.Addr, m krpc.Message) {
}
}
s.reply(raddr, m.T, r)
case queryMethodGetPeers: // See BEP 32
n4 := m.A.ContainsWant(krpc.WantNodes)
n6 := m.A.ContainsWant(krpc.WantNodes6)
@ -753,7 +755,6 @@ func (s *Server) GetPeers(infohash metainfo.Hash, cb ...func(Result)) {
for _, node := range nodes {
s.getPeers(infohash, node.Addr, s.conf.SearchDepth, ids, cb...)
}
}
// AnnouncePeer announces the torrent infohash to the K closest nodes,

View File

@ -136,7 +136,7 @@ func ExampleServer() {
server1.GetPeers(infohash, func(r Result) {
if len(r.Peers) == 0 {
fmt.Printf("no peers for %s\n", infohash)
fmt.Printf("%s: no peers for %s\n", r.Addr.String(), infohash)
} else {
for _, peer := range r.Peers {
fmt.Printf("%s: %s\n", infohash, peer.String())
@ -154,7 +154,7 @@ func ExampleServer() {
// which will search the DHT server1 recursively.
server2.GetPeers(infohash, func(r Result) {
if len(r.Peers) == 0 {
fmt.Printf("no peers for %s\n", infohash)
fmt.Printf("%s: no peers for %s\n", r.Addr.String(), infohash)
} else {
for _, peer := range r.Peers {
fmt.Printf("%s: %s\n", infohash, peer.String())
@ -171,11 +171,11 @@ func ExampleServer() {
// Server3: 2
// 127.0.0.1:9001 is searching 0102030405060708090a0b0c0d0e0f1011121314
// 127.0.0.1:9001 is searching 0102030405060708090a0b0c0d0e0f1011121314
// no peers for 0102030405060708090a0b0c0d0e0f1011121314
// no peers for 0102030405060708090a0b0c0d0e0f1011121314
// 127.0.0.1:9002: no peers for 0102030405060708090a0b0c0d0e0f1011121314
// 127.0.0.1:9003: no peers for 0102030405060708090a0b0c0d0e0f1011121314
// 127.0.0.1:9002 is searching 0102030405060708090a0b0c0d0e0f1011121314
// 127.0.0.1:9002 is searching 0102030405060708090a0b0c0d0e0f1011121314
// no peers for 0102030405060708090a0b0c0d0e0f1011121314
// 127.0.0.1:9003: no peers for 0102030405060708090a0b0c0d0e0f1011121314
// 0102030405060708090a0b0c0d0e0f1011121314: 127.0.0.1:9001
// 127.0.0.1 has downloaded 0102030405060708090a0b0c0d0e0f1011121314
}