client.go | 6 +++--- connection.go | 2 +- handshake.go | 4 ++-- peerid.go | 4 ++-- peerid_test.go | 4 +++- torrent_test.go | 2 +- diff --git a/client.go b/client.go index d6da9ed1a4f4f084bb320e753f43893aa24146ae..7fb7d50161a679697efa3b6744a8d42510b93a42 100644 --- a/client.go +++ b/client.go @@ -43,7 +43,7 @@ config Config halfOpenLimit int - peerID peerID + peerID PeerID defaultStorage *storage.Client onClose []func() tcpListener net.Listener @@ -90,7 +90,7 @@ cl.dHT.SetIPBlockList(list) } } -func (cl *Client) PeerID() [20]byte { +func (cl *Client) PeerID() PeerID { return cl.peerID } @@ -794,7 +794,7 @@ return } ret = res.Hash c.PeerExtensionBytes = res.peerExtensionBytes - c.PeerID = res.peerID + c.PeerID = res.PeerID c.completedHandshake = time.Now() return } diff --git a/connection.go b/connection.go index 1c2a24fef680c3b4af76c6648087830adb99ae06..60cadb2006041311954b4c8c36c7019374582c67 100644 --- a/connection.go +++ b/connection.go @@ -73,7 +73,7 @@ metadataRequests []bool sentHaves []bool // Stuff controlled by the remote peer. - PeerID peerID + PeerID PeerID PeerInterested bool PeerChoked bool PeerRequests map[request]struct{} diff --git a/handshake.go b/handshake.go index 7658151731778c60041d2a971abd9e85b770775a..60a546208fdfa58f2b4a63cb76b574f808dbddb2 100644 --- a/handshake.go +++ b/handshake.go @@ -60,7 +60,7 @@ } type handshakeResult struct { peerExtensionBytes - peerID + PeerID metainfo.Hash } @@ -116,7 +116,7 @@ return } 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 diff --git a/peerid.go b/peerid.go index 9d8bf1cc608566de19503bf53cba6d3a2728ac39..c9e3f4cdae94ac8f93ba6f4a283c296f40aff84a 100644 --- 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:]) } diff --git a/peerid_test.go b/peerid_test.go index 3d89ef4b3c0b668c56d60a0c7bcc5e06757dfcfa..965a28abacac3a62b38229a7cf60869685cf87d2 100644 --- a/peerid_test.go +++ b/peerid_test.go @@ -1,6 +1,7 @@ package torrent import ( + "fmt" "testing" "github.com/anacrolix/missinggo" @@ -15,8 +16,9 @@ }{ {"\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)) } } diff --git a/torrent_test.go b/torrent_test.go index 00f5949803bafa8548a5f70addf12c35bc946487..39575dcc1fa0deb0ec52292a47e63fdeadfa345e 100644 --- a/torrent_test.go +++ b/torrent_test.go @@ -183,7 +183,7 @@ hr, ok, err := handshake(nc, &ih, [20]byte{}, pex) 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())