feross/bittorrent-client — pull request #42 by marmolejo (2014-09-11 11:35:50+00:00)
Title: Solve unnecessary state changes upon start

When a torrent receives metadata, _onMetadata() is called. Then for each wire in the torrent, _onWireWithMetadata() sends the message "interested" to the peer, as it always starts like that. Later on the function calls _updateSelections(). As there is no selection yet, it now sends "not interested". After the function returns, _onMetadata() calls _onStorage() which selects the entire torrent, thus sending another "interested" message to the peer.

I'm not sure but probably it's not necessary to _updateSelections() in _onWireWithMetadata() as later on it will be called. However, _onWire() also calls it when a new wire in the torrent is being created with metadata.