]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Clone the AnnounceList out of Torrent.Metainfo
authorMatt Joiner <anacrolix@gmail.com>
Wed, 15 Apr 2020 03:07:17 +0000 (13:07 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Wed, 15 Apr 2020 07:26:02 +0000 (17:26 +1000)
Should fix a race with Torrent.AddTrackers

metainfo/announcelist.go
torrent.go

index 3a5c09d48349f896134b4ba7e0cb7429d3553853..b371f70d4e31d7fd23882fff3e2bd047d5db0f01 100644 (file)
@@ -2,6 +2,13 @@ package metainfo
 
 type AnnounceList [][]string
 
+func (al AnnounceList) Clone() (ret AnnounceList) {
+       for _, tier := range al {
+               ret = append(ret, append([]string(nil), tier...))
+       }
+       return
+}
+
 // Whether the AnnounceList should be preferred over a single URL announce.
 func (al AnnounceList) OverridesAnnounce(announce string) bool {
        for _, tier := range al {
index db0126bfac1ccd8b3f03d23b463924dca41dca20..d29c9a923525eff29ac18a0d15f699fcc8550a07 100644 (file)
@@ -633,7 +633,7 @@ func (t *Torrent) newMetaInfo() metainfo.MetaInfo {
                CreationDate: time.Now().Unix(),
                Comment:      "dynamic metainfo from client",
                CreatedBy:    "go.torrent",
-               AnnounceList: t.metainfo.UpvertedAnnounceList(),
+               AnnounceList: t.metainfo.UpvertedAnnounceList().Clone(),
                InfoBytes: func() []byte {
                        if t.haveInfo() {
                                return t.metadataBytes