]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Make peerID a public type
authorMatt Joiner <anacrolix@gmail.com>
Sat, 6 Jan 2018 04:50:45 +0000 (15:50 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Sat, 6 Jan 2018 04:50:45 +0000 (15:50 +1100)
Wanted it applied to Client Status output

client.go
connection.go
handshake.go
peerid.go
peerid_test.go
torrent_test.go

index d6da9ed1a4f4f084bb320e753f43893aa24146ae..7fb7d50161a679697efa3b6744a8d42510b93a42 100644 (file)
--- a/client.go
+++ b/client.go
@@ -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
 }
index 1c2a24fef680c3b4af76c6648087830adb99ae06..60cadb2006041311954b4c8c36c7019374582c67 100644 (file)
@@ -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{}
index 7658151731778c60041d2a971abd9e85b770775a..60a546208fdfa58f2b4a63cb76b574f808dbddb2 100644 (file)
@@ -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
index 9d8bf1cc608566de19503bf53cba6d3a2728ac39..c9e3f4cdae94ac8f93ba6f4a283c296f40aff84a 100644 (file)
--- a/peerid.go
+++ b/peerid.go
@@ -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:])
        }
index 3d89ef4b3c0b668c56d60a0c7bcc5e06757dfcfa..965a28abacac3a62b38229a7cf60869685cf87d2 100644 (file)
@@ -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))
        }
 }
index 00f5949803bafa8548a5f70addf12c35bc946487..39575dcc1fa0deb0ec52292a47e63fdeadfa345e 100644 (file)
@@ -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())