client.go | 7 +++++-- diff --git a/client.go b/client.go index 86f908818c1fe354900964d6faae75997a1c429f..1f8cf72427647af41c4a91dc739054bb529ebd63 100644 --- a/client.go +++ b/client.go @@ -31,6 +31,8 @@ "sync" "syscall" "time" + "bitbucket.org/anacrolix/go.torrent/util/levelmu" + "bitbucket.org/anacrolix/go.torrent/dht" . "bitbucket.org/anacrolix/go.torrent/util" @@ -98,7 +100,7 @@ disableTrackers bool downloadStrategy DownloadStrategy dHT *dht.Server - mu sync.Mutex + mu levelmu.LevelMutex event sync.Cond quit chan struct{} @@ -143,7 +145,7 @@ // Read torrent data at the given offset. Returns ErrDataNotReady if the data // isn't available. func (cl *Client) TorrentReadAt(ih InfoHash, off int64, p []byte) (n int, err error) { - cl.mu.Lock() + cl.mu.LevelLock(1) defer cl.mu.Unlock() t := cl.torrent(ih) if t == nil { @@ -206,6 +208,7 @@ quit: make(chan struct{}), torrents: make(map[InfoHash]*torrent), } cl.event.L = &cl.mu + cl.mu.Init(2) o := copy(cl.peerID[:], BEP20) _, err = rand.Read(cl.peerID[o:])