TODO | 2 +- client.go | 6 +++++- testutil/testutil.go | 3 ++- diff --git a/TODO b/TODO index e99c5b6a5a1504b7d65355f2437da4961ffd0674..23c1d0a3c95f04487a35b7516bd03736a5914203 100644 --- a/TODO +++ b/TODO @@ -2,4 +2,4 @@ * Track upload and download data. * Emulate a UDP server in the UDP tracker tests. * Make use of sparse file regions in download data for faster hashing. * If we're choked and interested, we never send not-interested if there's nothing we want? - * Perform announce as part of GetPeers, to reduce closest node calculation overhead, and wasting discarded nodes during the search. \ No newline at end of file + * Don't announce torrents that don't need active peers. It spams UDP, fills memory, and publicizes what we have loaded. \ No newline at end of file diff --git a/client.go b/client.go index 7e5f2b4588865780d376a8d108b70f6c42b2f4ae..4cc6025173441cfcd581816bb78575345dd3fea2 100644 --- a/client.go +++ b/client.go @@ -759,6 +759,10 @@ peerID InfoHash } +// ih is nil if we expect the peer to declare the InfoHash, such as when the +// peer initiated the connection. Returns ok if the handshake was successful, +// and err if there was an unexpected condition other than the peer simply +// abandoning the handshake. func handshake(sock io.ReadWriteCloser, ih *InfoHash, peerID [20]byte) (res handshakeResult, ok bool, err error) { // Bytes to be sent to the peer. Should never block the sender. postCh := make(chan []byte, 4) @@ -1839,7 +1843,7 @@ } return } -// Adds the torrent to the client. +// Adds a torrent to the client. func (me *Client) AddTorrent(metaInfo *metainfo.MetaInfo) (t Torrent, err error) { var ih InfoHash CopyExact(&ih, metaInfo.Info.Hash) diff --git a/testutil/testutil.go b/testutil/testutil.go index e4b606080853d91be9e4d8e4e86112a57f5f93e0..db0462530723bd12c667941c4245136a768595ca 100644 --- a/testutil/testutil.go +++ b/testutil/testutil.go @@ -20,10 +20,11 @@ func CreateDummyTorrentData(dirName string) string { f, _ := os.Create(filepath.Join(dirName, "greeting")) defer f.Close() - f.WriteString("hello, world\n") + f.WriteString(GreetingFileContents) return f.Name() } +// Writes to w, a metainfo containing the file at name. func CreateMetaInfo(name string, w io.Writer) { builder := metainfo.Builder{} builder.AddFile(name)