Make peerID a public type
Wanted it applied to Client Status output
This commit is contained in:
parent
c44ee5fec4
commit
e13b0eccbf
|
@ -43,7 +43,7 @@ type Client struct {
|
|||
config Config
|
||||
|
||||
halfOpenLimit int
|
||||
peerID peerID
|
||||
peerID PeerID
|
||||
defaultStorage *storage.Client
|
||||
onClose []func()
|
||||
tcpListener net.Listener
|
||||
|
@ -90,7 +90,7 @@ func (cl *Client) SetIPBlockList(list iplist.Ranger) {
|
|||
}
|
||||
}
|
||||
|
||||
func (cl *Client) PeerID() [20]byte {
|
||||
func (cl *Client) PeerID() PeerID {
|
||||
return cl.peerID
|
||||
}
|
||||
|
||||
|
@ -794,7 +794,7 @@ func (cl *Client) connBTHandshake(c *connection, ih *metainfo.Hash) (ret metainf
|
|||
}
|
||||
ret = res.Hash
|
||||
c.PeerExtensionBytes = res.peerExtensionBytes
|
||||
c.PeerID = res.peerID
|
||||
c.PeerID = res.PeerID
|
||||
c.completedHandshake = time.Now()
|
||||
return
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ type connection struct {
|
|||
sentHaves []bool
|
||||
|
||||
// Stuff controlled by the remote peer.
|
||||
PeerID peerID
|
||||
PeerID PeerID
|
||||
PeerInterested bool
|
||||
PeerChoked bool
|
||||
PeerRequests map[request]struct{}
|
||||
|
|
|
@ -60,7 +60,7 @@ func (pex peerExtensionBytes) GetBit(bit ExtensionBit) bool {
|
|||
|
||||
type handshakeResult struct {
|
||||
peerExtensionBytes
|
||||
peerID
|
||||
PeerID
|
||||
metainfo.Hash
|
||||
}
|
||||
|
||||
|
@ -116,7 +116,7 @@ func handshake(sock io.ReadWriter, ih *metainfo.Hash, peerID [20]byte, extension
|
|||
}
|
||||
missinggo.CopyExact(&res.peerExtensionBytes, b[20:28])
|
||||
missinggo.CopyExact(&res.Hash, b[28:48])
|
||||
missinggo.CopyExact(&res.peerID, b[48:68])
|
||||
missinggo.CopyExact(&res.PeerID, b[48:68])
|
||||
peerExtensions.Add(hex.EncodeToString(res.peerExtensionBytes[:]), 1)
|
||||
|
||||
// TODO: Maybe we can just drop peers here if we're not interested. This
|
||||
|
|
|
@ -4,9 +4,9 @@ import (
|
|||
"encoding/hex"
|
||||
)
|
||||
|
||||
type peerID [20]byte
|
||||
type PeerID [20]byte
|
||||
|
||||
func (me peerID) String() string {
|
||||
func (me PeerID) String() string {
|
||||
if me[0] == '-' && me[7] == '-' {
|
||||
return string(me[:8]) + hex.EncodeToString(me[8:])
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package torrent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/anacrolix/missinggo"
|
||||
|
@ -15,8 +16,9 @@ func TestPeerIdString(t *testing.T) {
|
|||
{"\x1cNJ}\x9c\xc7\xc4o\x94<\x9b\x8c\xc2!I\x1c\a\xec\x98n", "1c4e4a7d9cc7c46f943c9b8cc221491c07ec986e"},
|
||||
{"-FD51W\xe4-LaZMk0N8ZLA7", "-FD51W\xe4-4c615a4d6b304e385a4c4137"},
|
||||
} {
|
||||
var pi peerID
|
||||
var pi PeerID
|
||||
missinggo.CopyExact(&pi, _case.id)
|
||||
assert.EqualValues(t, _case.s, pi.String())
|
||||
assert.EqualValues(t, fmt.Sprintf("%q", _case.s), fmt.Sprintf("%q", pi))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -183,7 +183,7 @@ func TestTorrentMetainfoIncompleteMetadata(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
assert.True(t, ok)
|
||||
assert.True(t, hr.peerExtensionBytes.GetBit(ExtensionBitExtended))
|
||||
assert.EqualValues(t, cl.PeerID(), hr.peerID)
|
||||
assert.EqualValues(t, cl.PeerID(), hr.PeerID)
|
||||
assert.Equal(t, ih, hr.Hash)
|
||||
|
||||
assert.EqualValues(t, 0, tt.metadataSize())
|
||||
|
|
Loading…
Reference in New Issue