From: James Lawrence Date: Sun, 12 Jan 2020 19:26:29 +0000 (-0500) Subject: fixes various vet errors X-Git-Tag: v1.12.0~22 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=ad73cf861155c560d9b410e775d0762c745e56c1;p=btrtrc.git fixes various vet errors --- 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{