From ac9392b9e6434ba90d15c6059fea19c035a88717 Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Sun, 23 Jun 2013 15:21:40 +0000
Subject: [PATCH]  * i2psnark: When receiving a metainfo via magnet and saving
 it to disk,    preserve all non-standard fields (such as those created by
 Robert) so the    infohash doesn't change on restart, splitting the swarm.   
 (http://zzz.i2p/topics/1327 thx 'backup')

---
 .../java/src/org/klomp/snark/MetaInfo.java       | 16 ++++++++++++----
 history.txt                                      |  5 +++++
 .../java/src/net/i2p/router/RouterVersion.java   |  2 +-
 3 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/apps/i2psnark/java/src/org/klomp/snark/MetaInfo.java b/apps/i2psnark/java/src/org/klomp/snark/MetaInfo.java
index 810a10db08..138f7d6341 100644
--- a/apps/i2psnark/java/src/org/klomp/snark/MetaInfo.java
+++ b/apps/i2psnark/java/src/org/klomp/snark/MetaInfo.java
@@ -501,12 +501,17 @@ public class MetaInfo
    * Creates a copy of this MetaInfo that shares everything except the
    * announce URL.
    * Drops any announce-list.
+   * Preserves infohash and info map, including any non-standard fields.
+   * @param announce may be null
    */
-  public MetaInfo reannounce(String announce)
+  public MetaInfo reannounce(String announce) throws InvalidBEncodingException
   {
-    return new MetaInfo(announce, name, name_utf8, files,
-                        lengths, piece_length,
-                        piece_hashes, length, privateTorrent, null);
+        Map<String, BEValue> m = new HashMap();
+        if (announce != null)
+            m.put("announce", new BEValue(DataHelper.getUTF8(announce)));
+        Map info = createInfoMap();
+        m.put("info", new BEValue(info));
+        return new MetaInfo(m);
   }
 
   /**
@@ -539,6 +544,9 @@ public class MetaInfo
     // or else we will lose any non-standard keys and corrupt the infohash.
     if (infoMap != null)
         return Collections.unmodifiableMap(infoMap);
+    // we should only get here if serving a magnet on a torrent we created
+    if (_log.shouldLog(Log.WARN))
+        _log.warn("Creating new infomap", new Exception());
     // otherwise we must create it
     Map info = new HashMap();
     info.put("name", name);
diff --git a/history.txt b/history.txt
index c281c07cfa..d9571dabde 100644
--- a/history.txt
+++ b/history.txt
@@ -1,3 +1,8 @@
+2013-06-23 zzz
+ * i2psnark: When receiving a metainfo via magnet and saving it to disk,
+   preserve all non-standard fields (such as those created by Robert) so the
+   infohash doesn't change on restart and split the swarm.
+
 2013-06-22 zzz
  * SSU:
    - Pad messages with random data instead of zeros
diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java
index e36cd3b143..7f4edb9752 100644
--- a/router/java/src/net/i2p/router/RouterVersion.java
+++ b/router/java/src/net/i2p/router/RouterVersion.java
@@ -18,7 +18,7 @@ public class RouterVersion {
     /** deprecated */
     public final static String ID = "Monotone";
     public final static String VERSION = CoreVersion.VERSION;
-    public final static long BUILD = 12;
+    public final static long BUILD = 13;
 
     /** for example "-test" */
     public final static String EXTRA = "";
-- 
GitLab