From ad73cf861155c560d9b410e775d0762c745e56c1 Mon Sep 17 00:00:00 2001
From: James Lawrence <jljatone@gmail.com>
Date: Sun, 12 Jan 2020 14:26:29 -0500
Subject: [PATCH] fixes various vet errors

---
 Peer.go            |  3 ++-
 bep40_test.go      | 16 ++++++++--------
 client.go          | 13 +++++++------
 connection_test.go |  2 +-
 4 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/Peer.go b/Peer.go
index 080fad4d..02b2c31a 100644
--- 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)}
 }
diff --git a/bep40_test.go b/bep40_test.go
index 63d59eed..78b3ac21 100644
--- a/bep40_test.go
+++ b/bep40_test.go
@@ -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
 	}())
diff --git a/client.go b/client.go
index 2de19a1e..260219cb 100644
--- 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()
diff --git a/connection_test.go b/connection_test.go
index 69e3c9d8..d9924d18 100644
--- a/connection_test.go
+++ b/connection_test.go
@@ -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{
-- 
2.51.0