forked from I2P_Developers/i2p.i2p
- Handle case where we already have torrent
- New Storage.main() for use in the release process - Make torrent files in release process - Stop tunnel after fatal if no snarks are running
This commit is contained in:
@ -748,6 +748,14 @@ public class SnarkManager implements CompleteListener {
|
|||||||
*/
|
*/
|
||||||
public Snark getTorrent(String filename) { synchronized (_snarks) { return _snarks.get(filename); } }
|
public Snark getTorrent(String filename) { synchronized (_snarks) { return _snarks.get(filename); } }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unmodifiable
|
||||||
|
* @since 0.9.4
|
||||||
|
*/
|
||||||
|
public Collection<Snark> getTorrents() {
|
||||||
|
return Collections.unmodifiableCollection(_snarks.values());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Grab the torrent given the base name of the storage
|
* Grab the torrent given the base name of the storage
|
||||||
* @return Snark or null
|
* @return Snark or null
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
package org.klomp.snark;
|
package org.klomp.snark;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.RandomAccessFile;
|
import java.io.RandomAccessFile;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
@ -34,8 +35,10 @@ import java.util.StringTokenizer;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
import net.i2p.I2PAppContext;
|
||||||
import net.i2p.crypto.SHA1;
|
import net.i2p.crypto.SHA1;
|
||||||
import net.i2p.data.ByteArray;
|
import net.i2p.data.ByteArray;
|
||||||
|
import net.i2p.data.DataHelper;
|
||||||
import net.i2p.util.ByteCache;
|
import net.i2p.util.ByteCache;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
import net.i2p.util.SecureFile;
|
import net.i2p.util.SecureFile;
|
||||||
@ -1200,4 +1203,41 @@ public class Storage
|
|||||||
rafs[i] = null;
|
rafs[i] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a metainfo.
|
||||||
|
* Used in the installer build process; do not comment out.
|
||||||
|
* @since 0.9.4
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) {
|
||||||
|
if (args.length < 1 || args.length > 2) {
|
||||||
|
System.err.println("Usage: Storage file-or-dir [announceURL]");
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
File base = new File(args[0]);
|
||||||
|
String announce = args.length == 2 ? args[1] : null;
|
||||||
|
I2PAppContext ctx = I2PAppContext.getGlobalContext();
|
||||||
|
I2PSnarkUtil util = new I2PSnarkUtil(ctx);
|
||||||
|
File file = null;
|
||||||
|
FileOutputStream out = null;
|
||||||
|
try {
|
||||||
|
Storage storage = new Storage(util, base, announce, false, null);
|
||||||
|
MetaInfo meta = storage.getMetaInfo();
|
||||||
|
file = new File(storage.getBaseName() + ".torrent");
|
||||||
|
out = new FileOutputStream(file);
|
||||||
|
out.write(meta.getTorrentData());
|
||||||
|
String hex = DataHelper.toString(meta.getInfoHash());
|
||||||
|
System.out.println("Created: " + file);
|
||||||
|
System.out.println("InfoHash: " + hex);
|
||||||
|
String magnet = MagnetURI.MAGNET_FULL + hex;
|
||||||
|
if (announce != null)
|
||||||
|
magnet += "&tr=" + announce;
|
||||||
|
System.out.println("Magnet: " + magnet);
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
if (file != null)
|
||||||
|
file.delete();
|
||||||
|
ioe.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
try { if (out != null) out.close(); } catch (IOException ioe) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,8 +82,19 @@ class UpdateRunner implements UpdateTask, CompleteListener {
|
|||||||
String updateURL = uri.toString();
|
String updateURL = uri.toString();
|
||||||
try {
|
try {
|
||||||
MagnetURI magnet = new MagnetURI(_smgr.util(), updateURL);
|
MagnetURI magnet = new MagnetURI(_smgr.util(), updateURL);
|
||||||
String name = magnet.getName();
|
|
||||||
byte[] ih = magnet.getInfoHash();
|
byte[] ih = magnet.getInfoHash();
|
||||||
|
// do we already have it?
|
||||||
|
_snark = _smgr.getTorrentByInfoHash(ih);
|
||||||
|
if (_snark != null) {
|
||||||
|
if (_snark.getMetaInfo() != null) {
|
||||||
|
_hasMetaInfo = true;
|
||||||
|
Storage storage = _snark.getStorage();
|
||||||
|
if (storage != null && storage.complete())
|
||||||
|
processComplete(_snark);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
String name = magnet.getName();
|
||||||
String trackerURL = magnet.getTrackerURL();
|
String trackerURL = magnet.getTrackerURL();
|
||||||
if (trackerURL == null && !_smgr.util().shouldUseDHT() &&
|
if (trackerURL == null && !_smgr.util().shouldUseDHT() &&
|
||||||
!_smgr.util().shouldUseOpenTrackers()) {
|
!_smgr.util().shouldUseOpenTrackers()) {
|
||||||
@ -151,21 +162,33 @@ class UpdateRunner implements UpdateTask, CompleteListener {
|
|||||||
_umgr.notifyTaskFailed(this, error, null);
|
_umgr.notifyTaskFailed(this, error, null);
|
||||||
_log.error(error);
|
_log.error(error);
|
||||||
_isRunning = false;
|
_isRunning = false;
|
||||||
|
// stop the tunnel if we were the only one running
|
||||||
|
if (_smgr.util().connected() && !_smgr.util().isConnecting()) {
|
||||||
|
for (Snark s : _smgr.getTorrents()) {
|
||||||
|
if (!s.isStopped())
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_smgr.util().disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processComplete(Snark snark) {
|
||||||
|
String dataFile = snark.getBaseName();
|
||||||
|
File f = new File(_smgr.getDataDir(), dataFile);
|
||||||
|
String sudVersion = TrustedUpdate.getVersionString(f);
|
||||||
|
if (_newVersion.equals(sudVersion))
|
||||||
|
_umgr.notifyComplete(this, _newVersion, f);
|
||||||
|
else
|
||||||
|
fatal("version mismatch");
|
||||||
|
_isComplete = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//////// begin CompleteListener methods
|
//////// begin CompleteListener methods
|
||||||
//////// all pass through to SnarkManager
|
//////// all pass through to SnarkManager
|
||||||
|
|
||||||
public void torrentComplete(Snark snark) {
|
public void torrentComplete(Snark snark) {
|
||||||
String dataFile = snark.getBaseName();
|
processComplete(snark);
|
||||||
File f = new File(_smgr.getDataDir(), dataFile);
|
|
||||||
String sudVersion = TrustedUpdate.getVersionString(f);
|
|
||||||
if (!_newVersion.equals(sudVersion)) {
|
|
||||||
fatal("version mismatch");
|
|
||||||
}
|
|
||||||
_umgr.notifyComplete(this, _newVersion, f);
|
|
||||||
_smgr.torrentComplete(snark);
|
_smgr.torrentComplete(snark);
|
||||||
_isComplete = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
17
build.xml
17
build.xml
@ -1553,6 +1553,23 @@
|
|||||||
<arg value="i2pupdate.su2" />
|
<arg value="i2pupdate.su2" />
|
||||||
<arg value="i2pupdate.sud" />
|
<arg value="i2pupdate.sud" />
|
||||||
</exec>
|
</exec>
|
||||||
|
<!-- make torrent files -->
|
||||||
|
<copy file="i2pupdate.sud" tofile="i2pupdate_${release.number}.sud" />
|
||||||
|
<java classname="org.klomp.snark.Storage" fork="true" failonerror="true">
|
||||||
|
<classpath>
|
||||||
|
<pathelement location="build/i2p.jar" />
|
||||||
|
<pathelement location="build/i2psnark.jar" />
|
||||||
|
</classpath>
|
||||||
|
<arg value="i2pupdate_${release.number}.sud" />
|
||||||
|
</java>
|
||||||
|
<copy file="i2pupdate.su2" tofile="i2pupdate_${release.number}.su2" />
|
||||||
|
<java classname="org.klomp.snark.Storage" fork="true" failonerror="true">
|
||||||
|
<classpath>
|
||||||
|
<pathelement location="build/i2p.jar" />
|
||||||
|
<pathelement location="build/i2psnark.jar" />
|
||||||
|
</classpath>
|
||||||
|
<arg value="i2pupdate_${release.number}.su2" />
|
||||||
|
</java>
|
||||||
<echo message="Don't forget to mtn tag w: i2p-${release.number}" />
|
<echo message="Don't forget to mtn tag w: i2p-${release.number}" />
|
||||||
<echo message="... and mtn cert t:i2p-${release.number} branch i2p.i2p.release" />
|
<echo message="... and mtn cert t:i2p-${release.number} branch i2p.i2p.release" />
|
||||||
</target>
|
</target>
|
||||||
|
Reference in New Issue
Block a user