Misc tidying
This commit is contained in:
parent
4b1b009049
commit
a1010d7404
2
TODO
2
TODO
@ -2,4 +2,4 @@
|
|||||||
* Emulate a UDP server in the UDP tracker tests.
|
* Emulate a UDP server in the UDP tracker tests.
|
||||||
* Make use of sparse file regions in download data for faster hashing.
|
* 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?
|
* 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.
|
* Don't announce torrents that don't need active peers. It spams UDP, fills memory, and publicizes what we have loaded.
|
@ -759,6 +759,10 @@ type handshakeResult struct {
|
|||||||
InfoHash
|
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) {
|
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.
|
// Bytes to be sent to the peer. Should never block the sender.
|
||||||
postCh := make(chan []byte, 4)
|
postCh := make(chan []byte, 4)
|
||||||
@ -1839,7 +1843,7 @@ func (me *Client) addOrMergeTorrent(ih InfoHash, announceList [][]string) (T Tor
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds the torrent to the client.
|
// Adds a torrent to the client.
|
||||||
func (me *Client) AddTorrent(metaInfo *metainfo.MetaInfo) (t Torrent, err error) {
|
func (me *Client) AddTorrent(metaInfo *metainfo.MetaInfo) (t Torrent, err error) {
|
||||||
var ih InfoHash
|
var ih InfoHash
|
||||||
CopyExact(&ih, metaInfo.Info.Hash)
|
CopyExact(&ih, metaInfo.Info.Hash)
|
||||||
|
@ -20,10 +20,11 @@ const GreetingFileContents = "hello, world\n"
|
|||||||
func CreateDummyTorrentData(dirName string) string {
|
func CreateDummyTorrentData(dirName string) string {
|
||||||
f, _ := os.Create(filepath.Join(dirName, "greeting"))
|
f, _ := os.Create(filepath.Join(dirName, "greeting"))
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
f.WriteString("hello, world\n")
|
f.WriteString(GreetingFileContents)
|
||||||
return f.Name()
|
return f.Name()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Writes to w, a metainfo containing the file at name.
|
||||||
func CreateMetaInfo(name string, w io.Writer) {
|
func CreateMetaInfo(name string, w io.Writer) {
|
||||||
builder := metainfo.Builder{}
|
builder := metainfo.Builder{}
|
||||||
builder.AddFile(name)
|
builder.AddFile(name)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user