]> Sergey Matveev's repositories - btrtrc.git/commitdiff
fixes various vet errors
authorJames Lawrence <jljatone@gmail.com>
Sun, 12 Jan 2020 19:26:29 +0000 (14:26 -0500)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 13 Jan 2020 23:09:09 +0000 (09:09 +1000)
Peer.go
bep40_test.go
client.go
connection_test.go

diff --git a/Peer.go b/Peer.go
index 080fad4db1b066bf0c9209ed805f56ddef40e4e4..02b2c31aec76ef98af52bc8aa4cc6aa095d2b4d2 100644 (file)
--- a/Peer.go
+++ b/Peer.go
@@ -21,6 +21,7 @@ type Peer struct {
        Trusted bool
 }
 
+// FromPex generate Peer from peer exchange
 func (me *Peer) FromPex(na krpc.NodeAddr, fs peer_protocol.PexPeerFlags) {
        me.IP = append([]byte(nil), na.IP...)
        me.Port = na.Port
@@ -33,5 +34,5 @@ func (me *Peer) FromPex(na krpc.NodeAddr, fs peer_protocol.PexPeerFlags) {
 }
 
 func (me Peer) addr() IpPort {
-       return IpPort{me.IP, uint16(me.Port)}
+       return IpPort{IP: me.IP, Port: uint16(me.Port)}
 }
index 63d59eed4fb78fd7a33f14606d68034598003649..78b3ac21547dd918f1b09d64313cc8acdcb9eec8 100644 (file)
@@ -9,21 +9,21 @@ import (
 
 func TestBep40Priority(t *testing.T) {
        assert.EqualValues(t, peerPriority(0xec2d7224), bep40PriorityIgnoreError(
-               IpPort{net.ParseIP("123.213.32.10"), 0},
-               IpPort{net.ParseIP("98.76.54.32"), 0},
+               IpPort{IP: net.ParseIP("123.213.32.10"), Port: 0},
+               IpPort{IP: net.ParseIP("98.76.54.32"), Port: 0},
        ))
        assert.EqualValues(t, peerPriority(0xec2d7224), bep40PriorityIgnoreError(
-               IpPort{net.ParseIP("98.76.54.32"), 0},
-               IpPort{net.ParseIP("123.213.32.10"), 0},
+               IpPort{IP: net.ParseIP("98.76.54.32"), Port: 0},
+               IpPort{IP: net.ParseIP("123.213.32.10"), Port: 0},
        ))
        assert.Equal(t, peerPriority(0x99568189), bep40PriorityIgnoreError(
-               IpPort{net.ParseIP("123.213.32.10"), 0},
-               IpPort{net.ParseIP("123.213.32.234"), 0},
+               IpPort{IP: net.ParseIP("123.213.32.10"), Port: 0},
+               IpPort{IP: net.ParseIP("123.213.32.234"), Port: 0},
        ))
        assert.EqualValues(t, "\x00\x00\x00\x00", func() []byte {
                b, _ := bep40PriorityBytes(
-                       IpPort{net.ParseIP("123.213.32.234"), 0},
-                       IpPort{net.ParseIP("123.213.32.234"), 0},
+                       IpPort{IP: net.ParseIP("123.213.32.234"), Port: 0},
+                       IpPort{IP: net.ParseIP("123.213.32.234"), Port: 0},
                )
                return b
        }())
index 2de19a1e928eead57a9fd2eafbeae595df46241d..260219cb4e14df6f277c32f5e14d394352238cf9 100644 (file)
--- a/client.go
+++ b/client.go
@@ -1298,12 +1298,12 @@ func (cl *Client) publicIp(peer net.IP) net.IP {
                        cl.config.PublicIp4,
                        cl.findListenerIp(func(ip net.IP) bool { return ip.To4() != nil }),
                )
-       } else {
-               return firstNotNil(
-                       cl.config.PublicIp6,
-                       cl.findListenerIp(func(ip net.IP) bool { return ip.To4() == nil }),
-               )
        }
+
+       return firstNotNil(
+               cl.config.PublicIp6,
+               cl.findListenerIp(func(ip net.IP) bool { return ip.To4() == nil }),
+       )
 }
 
 func (cl *Client) findListenerIp(f func(net.IP) bool) net.IP {
@@ -1314,9 +1314,10 @@ func (cl *Client) findListenerIp(f func(net.IP) bool) net.IP {
 
 // Our IP as a peer should see it.
 func (cl *Client) publicAddr(peer net.IP) IpPort {
-       return IpPort{cl.publicIp(peer), uint16(cl.incomingPeerPort())}
+       return IpPort{IP: cl.publicIp(peer), Port: uint16(cl.incomingPeerPort())}
 }
 
+// ListenAddrs addresses currently being listened to.
 func (cl *Client) ListenAddrs() (ret []net.Addr) {
        cl.lock()
        defer cl.unlock()
index 69e3c9d8bcda6d5774e6c726476af9c982cb30ff..d9924d181edc4d76edbf8020376412084a7db6ce 100644 (file)
@@ -96,7 +96,7 @@ func BenchmarkConnectionMainReadLoop(b *testing.B) {
        ts := &torrentStorage{}
        t := &Torrent{
                cl:                cl,
-               storage:           &storage.Torrent{ts},
+               storage:           &storage.Torrent{TorrentImpl: ts},
                pieceStateChanges: pubsub.NewPubSub(),
        }
        require.NoError(b, t.setInfo(&metainfo.Info{