FileDocCategorySizeDatePackage
PlatformTorrentUtils.javaAPI DocAzureus 3.0.3.422255Tue Sep 25 17:25:10 BST 2007com.aelitis.azureus.core.torrent

PlatformTorrentUtils

public class PlatformTorrentUtils extends Object
author
TuxPaper
created
Sep 27, 2006

Fields Summary
private static final long
RETRY_METADATA
private static final long
MIN_SPEED_DEFAULT
private static final long
MIN_MD_REFRESH_MS
private static final long
MAX_MD_REFRESH_MS
public static final boolean
DEBUG_CACHING
private static final String
TOR_AZ_PROP_MAP
private static final String
TOR_AZ_PROP_HASH
private static final String
TOR_AZ_PROP_TITLE
private static final String
TOR_AZ_PROP_DESCRIPTION
private static final String
TOR_AZ_PROP_AUTHOR
private static final String
TOR_AZ_PROP_PUBLISHER
private static final String
TOR_AZ_PROP_URL
private static final String
TOR_AZ_PROP_THUMBNAIL
private static final String
TOR_AZ_PROP_QUALITY
private static final String
TOR_AZ_PROP_USER_RATING
private static final String
TOR_AZ_PROP_LASTUPDATED
private static final String
TOR_AZ_PROP_CREATIONDATE
private static final String
TOR_AZ_PROP_METADATA_REFRESHON
private static final String
TOR_AZ_PROP_PROGRESSIVE
private static final String
TOR_AZ_PROP_SPEED
private static final String
TOR_AZ_PROP_MIN_SPEED
private static final String
TOR_AZ_PROP_DRM
private static final String
TOR_AZ_PROP_QOS_CLASS
private static final String
TOR_AZ_PROP_AD_ID
private static final String
TOR_AZ_PROP_AD_ENABLED
private static final String
TOR_AZ_PROP_EXPIRESON
private static final String
TOR_AZ_PROP_PRIMARY_FILE
private static final ArrayList
metaDataListeners
private static final String
TOR_AZ_PROP_USE_EMP
private static final String
TOR_AZ_PROP_FILE_METADATA
private static ArrayList
listPlatformHosts
private static final Map
mapPlatformTrackerTorrents
private static boolean
embeddedPlayerAvail
Constructors Summary
Methods Summary
public static voidaddListener(MetaDataUpdateListener l)

		if (metaDataListeners.indexOf(l) < 0) {
			metaDataListeners.add(l);
		}
	
public static voidaddPlatformHost(java.lang.String host)

		List platformHosts = getPlatformHosts();
		host = host.toLowerCase();

		if (!platformHosts.contains(host)) {
			platformHosts.add(platformHosts);
			mapPlatformTrackerTorrents.clear();
		}
	
public static booleanembeddedPlayerAvail()

		// cache true, always recheck false in case plugin installs.
		if (embeddedPlayerAvail) {
			return true;
		}

		try {
			PluginInterface pi = AzureusCoreFactory.getSingleton().getPluginManager().getPluginInterfaceByID(
					"azemp");
			if (pi != null && pi.isOperational() && !pi.isDisabled()) {
				embeddedPlayerAvail = true;
			}
		} catch (Throwable e1) {
		}

		return embeddedPlayerAvail;
	
public static java.lang.StringgetAdId(org.gudy.azureus2.core3.torrent.TOTorrent torrent)

		return getContentMapString(torrent, TOR_AZ_PROP_AD_ID);
	
public static java.lang.StringgetContentAuthor(org.gudy.azureus2.core3.torrent.TOTorrent torrent)

		return getContentMapString(torrent, TOR_AZ_PROP_AUTHOR);
	
public static java.lang.StringgetContentDescription(org.gudy.azureus2.core3.torrent.TOTorrent torrent)

		return getContentMapString(torrent, TOR_AZ_PROP_DESCRIPTION);
	
public static java.lang.StringgetContentHash(org.gudy.azureus2.core3.torrent.TOTorrent torrent)

		return getContentMapString(torrent, TOR_AZ_PROP_HASH);
	
public static longgetContentLastUpdated(org.gudy.azureus2.core3.torrent.TOTorrent torrent)

		return getContentMapLong(torrent, TOR_AZ_PROP_LASTUPDATED, 0);
	
public static java.util.MapgetContentMap(org.gudy.azureus2.core3.torrent.TOTorrent torrent)


	     
		if (torrent == null) {
			return new HashMap();
		}

		Map mapAZProps = torrent.getAdditionalMapProperty(TOTorrent.AZUREUS_PROPERTIES);

		if (mapAZProps == null) {
			mapAZProps = new HashMap();
			torrent.setAdditionalMapProperty(TOTorrent.AZUREUS_PROPERTIES, mapAZProps);
		}

		Object objExistingContentMap = mapAZProps.get(TOR_AZ_PROP_MAP);

		Map mapContent;
		if (objExistingContentMap instanceof Map) {
			mapContent = (Map) objExistingContentMap;
		} else {
			mapContent = new HashMap();
			mapAZProps.put(TOR_AZ_PROP_MAP, mapContent);
		}

		return mapContent;
	
private static longgetContentMapLong(org.gudy.azureus2.core3.torrent.TOTorrent torrent, java.lang.String key, long def)

		if (torrent == null) {
			return def;
		}

		Map mapContent = getContentMap(torrent);
		Object obj = mapContent.get(key);

		try {
			if (obj instanceof Long) {
				return ((Long) obj).longValue();
			} else if (obj instanceof Integer) {
				return ((Integer) obj).longValue();
			} else if (obj instanceof String) {
				return Long.parseLong((String) obj);
			} else if (obj instanceof byte[]) {
				return Long.parseLong(new String((byte[]) obj));
			}
		} catch (Exception e) {
		}

		return def;
	
public static java.util.MapgetContentMapMap(org.gudy.azureus2.core3.torrent.TOTorrent torrent, java.lang.String key)

		if ( torrent == null ){
			return( null );
		}
		
		Map mapContent = getContentMap(torrent);
		Object obj = mapContent.get(key);
		
		if ( obj instanceof Map ){
			return((Map)obj);
		}
		
		return( null );
	
private static java.lang.StringgetContentMapString(org.gudy.azureus2.core3.torrent.TOTorrent torrent, java.lang.String key)

		if (torrent == null) {
			return null;
		}

		Map mapContent = getContentMap(torrent);
		Object obj = mapContent.get(key);

		if (obj instanceof String) {
			return (String) obj;
		} else if (obj instanceof byte[]) {
			try {
				return new String((byte[]) obj, Constants.DEFAULT_ENCODING);
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		return null;
	
public static longgetContentMinimumSpeedBps(org.gudy.azureus2.core3.torrent.TOTorrent torrent)

		return getContentMapLong(torrent, TOR_AZ_PROP_MIN_SPEED, MIN_SPEED_DEFAULT);
	
public static intgetContentPrimaryFileIndex(org.gudy.azureus2.core3.torrent.TOTorrent torrent)

		return (int)getContentMapLong(torrent, TOR_AZ_PROP_PRIMARY_FILE, -1 );

	
public static java.lang.StringgetContentPublisher(org.gudy.azureus2.core3.torrent.TOTorrent torrent)

		return getContentMapString(torrent, TOR_AZ_PROP_PUBLISHER);
	
public static java.lang.StringgetContentQuality(org.gudy.azureus2.core3.torrent.TOTorrent torrent)

		return getContentMapString(torrent, TOR_AZ_PROP_QUALITY);
	
public static longgetContentStreamSpeedBps(org.gudy.azureus2.core3.torrent.TOTorrent torrent)

		return getContentMapLong(torrent, TOR_AZ_PROP_SPEED, 0);
	
public static byte[]getContentThumbnail(org.gudy.azureus2.core3.torrent.TOTorrent torrent)

		Map mapContent = getContentMap(torrent);
		Object obj = mapContent.get(TOR_AZ_PROP_THUMBNAIL);

		if (obj instanceof byte[]) {
			return (byte[]) obj;
		}

		return null;
	
public static java.lang.StringgetContentTitle(org.gudy.azureus2.core3.torrent.TOTorrent torrent)

		return getContentMapString(torrent, TOR_AZ_PROP_TITLE);
	
public static java.lang.StringgetContentURL(org.gudy.azureus2.core3.torrent.TOTorrent torrent)

		return getContentMapString(torrent, TOR_AZ_PROP_URL);
	
public static longgetExpiresOn(org.gudy.azureus2.core3.torrent.TOTorrent torrent)

		Map mapContent = getContentMap(torrent);
		Long l = (Long) mapContent.get(TOR_AZ_PROP_EXPIRESON);
		if (l == null) {
			return 0;
		}
		return l.longValue();
	
public static java.util.MapgetFileMetaData(org.gudy.azureus2.core3.torrent.TOTorrent torrent)

		return getContentMapMap( torrent, TOR_AZ_PROP_FILE_METADATA );
	
public static longgetMetaDataRefreshOn(org.gudy.azureus2.core3.torrent.TOTorrent torrent)

		Map mapContent = getTempContentMap(torrent);
		Long l = (Long) mapContent.get(TOR_AZ_PROP_METADATA_REFRESHON);
		if (l == null) {
			return 0;
		}
		return l.longValue();
	
public static java.util.ListgetPlatformHosts()

		if (listPlatformHosts == null) {
			listPlatformHosts = new ArrayList();
			for (int i = 0; i < Constants.AZUREUS_DOMAINS.length; i++) {
				listPlatformHosts.add(Constants.AZUREUS_DOMAINS[i].toLowerCase());
			}
		}
		return listPlatformHosts;
	
public static longgetQOSClass(org.gudy.azureus2.core3.torrent.TOTorrent torrent)

		return getContentMapLong(torrent, TOR_AZ_PROP_QOS_CLASS, 0);
	
static java.util.MapgetTempContentMap(org.gudy.azureus2.core3.torrent.TOTorrent torrent)

		if (torrent == null) {
			return new HashMap();
		}

		Map mapAZProps = torrent.getAdditionalMapProperty("attributes");

		if (mapAZProps == null) {
			mapAZProps = new HashMap();
			torrent.setAdditionalMapProperty("attributes", mapAZProps);
		}

		Object objExistingContentMap = mapAZProps.get(TOR_AZ_PROP_MAP);

		Map mapContent;
		if (objExistingContentMap instanceof Map) {
			mapContent = (Map) objExistingContentMap;
		} else {
			mapContent = new HashMap();
			mapAZProps.put(TOR_AZ_PROP_MAP, mapContent);
		}

		return mapContent;
	
public static intgetUserRating(org.gudy.azureus2.core3.torrent.TOTorrent torrent)

param
torrent
return
-1: No rating

		Map mapContent = getTempContentMap(torrent);
		Long l = (Long) mapContent.get(TOR_AZ_PROP_USER_RATING);
		if (l == null) {
			return -1;
		}
		return l.intValue();
	
public static booleanisContent(org.gudy.azureus2.core3.torrent.TOTorrent torrent, boolean requirePlatformTracker)

		if (torrent == null) {
			return false;
		}
		boolean bContent = PlatformTorrentUtils.getContentHash(torrent) != null;
		if (!bContent || (bContent && !requirePlatformTracker)) {
			return bContent;
		}

		return isPlatformTracker(torrent);
	
public static booleanisContent(org.gudy.azureus2.plugins.torrent.Torrent torrent, boolean requirePlatformTracker)

		if (torrent instanceof TorrentImpl) {
			return isContent(((TorrentImpl) torrent).getTorrent(),
					requirePlatformTracker);
		}
		return false;
	
public static booleanisContentAdEnabled(org.gudy.azureus2.core3.torrent.TOTorrent torrent)

		return getContentMapLong(torrent, TOR_AZ_PROP_AD_ENABLED, 0) == 1;
	
public static booleanisContentDRM(org.gudy.azureus2.core3.torrent.TOTorrent torrent)

		return getContentMapLong(torrent, TOR_AZ_PROP_DRM, -1) >= 0;
	
public static booleanisContentProgressive(org.gudy.azureus2.core3.torrent.TOTorrent torrent)

		return getContentMapLong(torrent, TOR_AZ_PROP_PROGRESSIVE, 0) == 1;
	
public static booleanisPlatformHost(java.lang.String host)

		Object[] domains = getPlatformHosts().toArray();

		host = host.toLowerCase();

		for (int i = 0; i < domains.length; i++) {

			String domain = (String) domains[i];

			if (domain.equals(host)) {

				return (true);
			}

			if (host.endsWith("." + domain)) {

				return (true);
			}
		}

		if ( Constants.isCVSVersion()){
		
				// allow local addresses for testing
			
			try{
				InetAddress ia = InetAddress.getByName( host );
			
				return( ia.isLoopbackAddress() || ia.isLinkLocalAddress() || ia.isSiteLocalAddress());
				
			}catch( Throwable e ){
			}
		}
		
		return (false);
	
public static booleanisPlatformTracker(org.gudy.azureus2.core3.torrent.TOTorrent torrent)

		try {
			if (torrent == null) {

				return false;
			}

			Object oCache = mapPlatformTrackerTorrents.get(torrent);
			if (oCache instanceof Boolean) {
				return ((Boolean) oCache).booleanValue();
			}

			// check them all incase someone includes one of our trackers in a multi-tracker
			// torrent

			URL announceURL = torrent.getAnnounceURL();

			if (announceURL != null) {

				if (!isPlatformHost(announceURL.getHost())) {

					mapPlatformTrackerTorrents.put(torrent, new Boolean(false));
					return (false);
				}
			}

			TOTorrentAnnounceURLSet[] sets = torrent.getAnnounceURLGroup().getAnnounceURLSets();

			for (int i = 0; i < sets.length; i++) {

				URL[] urls = sets[i].getAnnounceURLs();

				for (int j = 0; j < urls.length; j++) {

					if (!isPlatformHost(urls[j].getHost())) {

						mapPlatformTrackerTorrents.put(torrent, new Boolean(false));
						return (false);
					}
				}
			}

			boolean b = announceURL != null;
			mapPlatformTrackerTorrents.put(torrent, new Boolean(b));
			return b;

		} catch (Throwable e) {

			Debug.printStackTrace(e);

			mapPlatformTrackerTorrents.put(torrent, new Boolean(false));
			return (false);
		}
	
public static booleanisPlatformTracker(org.gudy.azureus2.plugins.torrent.Torrent torrent)

		if (torrent instanceof TorrentImpl) {
			return isPlatformTracker(((TorrentImpl) torrent).getTorrent());
		}
		return false;
	
public static voidlog(java.lang.String str)

		AEDiagnosticsLogger diag_logger = AEDiagnostics.getLogger("v3.MD");
		diag_logger.log(str);
		if (DEBUG_CACHING) {
			System.out.println(Thread.currentThread().getName() + "|"
					+ System.currentTimeMillis() + "] " + str);
		}
	
public static voidlog(org.gudy.azureus2.core3.torrent.TOTorrent torrent, java.lang.String string)

param
torrent
param
string
since
3.0.1.5

		String hash = "";
		try {
			hash = torrent.getHashWrapper().toBase32String();
		} catch (TOTorrentException e) {
		}
		log(hash + "] " + string);
	
private static voidputOrRemove(java.util.Map map, java.lang.String key, java.lang.Object obj)

		if (obj == null || obj.equals(null)) {
			map.remove(key);
		} else {
			map.put(key, obj);
		}
	
public static voidremoveListener(MetaDataUpdateListener l)

		metaDataListeners.remove(l);
	
public static voidremoveUserRating(org.gudy.azureus2.core3.torrent.TOTorrent torrent)

		Map mapContent = getTempContentMap(torrent);
		if (mapContent.remove(TOR_AZ_PROP_USER_RATING) != null) {
			writeTorrentIfExists(torrent);
		}
	
public static voidsetAdId(org.gudy.azureus2.core3.torrent.TOTorrent torrent, java.lang.String sID)

		Map mapContent = getContentMap(torrent);
		putOrRemove(mapContent, TOR_AZ_PROP_AD_ID, sID);

		writeTorrentIfExists(torrent);
	
public static voidsetContentLastUpdated(org.gudy.azureus2.core3.torrent.TOTorrent torrent, long lastUpdate)

		setContentMapLong(torrent, TOR_AZ_PROP_LASTUPDATED, lastUpdate);
	
private static voidsetContentMapLong(org.gudy.azureus2.core3.torrent.TOTorrent torrent, java.lang.String key, long value)

		if (torrent == null) {
			return;
		}

		Map mapContent = getContentMap(torrent);
		mapContent.put(key, new Long(value));
	
private static voidsetContentMapMap(org.gudy.azureus2.core3.torrent.TOTorrent torrent, java.lang.String key, java.util.Map value)

		if (torrent == null) {
			return;
		}

		Map mapContent = getContentMap(torrent);
		mapContent.put(key, value);
	
private static voidsetContentMapString(org.gudy.azureus2.core3.torrent.TOTorrent torrent, java.lang.String key, java.lang.String value)

		if (torrent == null) {
			return;
		}

		Map mapContent = getContentMap(torrent);
		mapContent.put(key, value);
	
public static voidsetContentQuality(org.gudy.azureus2.core3.torrent.TOTorrent torrent, java.lang.String sQualityID)

		Map mapContent = getContentMap(torrent);
		putOrRemove(mapContent, TOR_AZ_PROP_QUALITY, sQualityID);

		writeTorrentIfExists(torrent);
	
public static voidsetContentThumbnail(org.gudy.azureus2.core3.torrent.TOTorrent torrent, byte[] thumbnail)

		Map mapContent = getContentMap(torrent);
		putOrRemove(mapContent, TOR_AZ_PROP_THUMBNAIL, thumbnail);

		writeTorrentIfExists(torrent);
	
public static voidsetContentTitle(org.gudy.azureus2.core3.torrent.TOTorrent torrent, java.lang.String title)

		setContentMapString(torrent, TOR_AZ_PROP_TITLE, title);
	
public static voidsetExpiresOn(org.gudy.azureus2.core3.torrent.TOTorrent torrent, long expiresOn)

		Map mapContent = getContentMap(torrent);
		mapContent.put(TOR_AZ_PROP_EXPIRESON, new Long(expiresOn));
		writeTorrentIfExists(torrent);
	
public static voidsetFileMetaData(org.gudy.azureus2.core3.torrent.TOTorrent torrent, java.util.Map map)

		setContentMapMap(torrent, TOR_AZ_PROP_FILE_METADATA, map );
	
public static voidsetMetaDataRefreshOn(org.gudy.azureus2.core3.torrent.TOTorrent torrent, long refreshOn)

		Map mapContent = getTempContentMap(torrent);
		mapContent.put(TOR_AZ_PROP_METADATA_REFRESHON, new Long(refreshOn));
		writeTorrentIfExists(torrent);
	
public static voidsetQOSClass(org.gudy.azureus2.core3.torrent.TOTorrent torrent, long cla)

		setContentMapLong(torrent, TOR_AZ_PROP_QOS_CLASS, cla);
	
public static voidsetUseEMP(org.gudy.azureus2.core3.torrent.TOTorrent torrent, boolean useEMP)

		setContentMapLong(torrent, TOR_AZ_PROP_USE_EMP, useEMP ? 1 : 0);
	
public static voidsetUserRating(org.gudy.azureus2.core3.torrent.TOTorrent torrent, int rating)

		Map mapContent = getTempContentMap(torrent);
		mapContent.put(TOR_AZ_PROP_USER_RATING, new Long(rating));
		writeTorrentIfExists(torrent);
	
public static voidtriggerMetaDataUpdateListeners(org.gudy.azureus2.core3.torrent.TOTorrent torrent)

		MetaDataUpdateListener[] listeners = (MetaDataUpdateListener[]) metaDataListeners.toArray(new MetaDataUpdateListener[0]);
		for (int i = 0; i < listeners.length; i++) {
			MetaDataUpdateListener listener = listeners[i];
			try {
				listener.metaDataUpdated(torrent);
			} catch (Exception e) {
				Debug.out(e);
			}
		}
	
public static voidupdateMetaData(org.gudy.azureus2.core3.torrent.TOTorrent torrent, long maxDelayMS)

param
torrent
param
maxDelayMS TODO

		if (!isContent(torrent, true)) {
			log(torrent, "torrent " + new String(torrent.getName())
					+ " not az content");
			return;
		}

		log(torrent, "updateMD");

		PlatformTorrentMessenger.getMetaData(new TOTorrent[] {
			torrent
		}, maxDelayMS, new PlatformTorrentMessenger.GetMetaDataReplyListener() {

			public void messageSent() {
			}

			public void replyReceived(String replyType, Map mapHashes) {
				updateMetaData_handleReply(torrent, null, replyType, mapHashes);
			}
		});
	
private static voidupdateMetaData_handleReply(org.gudy.azureus2.core3.torrent.TOTorrent torrent, java.lang.String hash, java.lang.String replyType, java.util.Map mapHashes)

		Map contentMap = PlatformTorrentUtils.getContentMap(torrent);

		if (replyType.equals(PlatformMessenger.REPLY_EXCEPTION)) {
			// try again in a bit
			log(torrent, "Exception, retrying later");
			SimpleTimer.addEvent("Update MD Retry", SystemTime.getCurrentTime()
					+ RETRY_METADATA, new TimerEventPerformer() {
				public void perform(TimerEvent event) {
					log(torrent, "retry time");
					PlatformTorrentUtils.updateMetaData(torrent, 15000);
				}
			});
		} else {
			if (hash == null) {
				try {
					hash = torrent.getHashWrapper().toBase32String();
				} catch (TOTorrentException e) {
				}
			}
			Map jsonMapMetaData = hash == null ? null : (Map) mapHashes.get(hash);
			if (jsonMapMetaData != null) {
				long oldLastUpdated = getContentLastUpdated(torrent);
				long expireyMins = 0;

				for (Iterator iter = jsonMapMetaData.keySet().iterator(); iter.hasNext();) {
					String key = (String) iter.next();
					Object value = jsonMapMetaData.get(key);

					if (value == null || value.equals(null)) {
						contentMap.remove(key);
					} else if ((key.equals("Thumbnail") || key.endsWith(".B64"))
							&& value instanceof String) {
						contentMap.put(key, Base64.decode((String) value));
					} else if (key.equals("expires-in-mins") && value instanceof Long) {
						expireyMins = ((Long) value).longValue();
					} else {
						contentMap.put(key, value);
					}
					writeTorrentIfExists(torrent);
				}

				// crappy way of updating the display name
				try {
					GlobalManager gm = AzureusCoreFactory.getSingleton().getGlobalManager();
					DownloadManager dm = gm.getDownloadManager(torrent);
					String title = PlatformTorrentUtils.getContentTitle(torrent);
					if (title != null && title.length() > 0
							&& dm.getDownloadState().getDisplayName() == null) {
						dm.getDownloadState().setDisplayName(title);
					}
				} catch (Exception e) {

				}
				triggerMetaDataUpdateListeners(torrent);

				long refreshOn;
				if (expireyMins > 0) {
					refreshOn = SystemTime.getCurrentTime() + (expireyMins * 60 * 1000L);
				} else {
					long newLastUpdated = getContentLastUpdated(torrent);

					long diff = newLastUpdated - oldLastUpdated;
					log(torrent, "Last Updated: new " + new Date(newLastUpdated)
							+ ";old " + new Date(oldLastUpdated) + ";diff=" + diff);
					if (diff > 0 && oldLastUpdated != 0) {
						diff *= 2;
						if (diff < MIN_MD_REFRESH_MS) {
							diff = MIN_MD_REFRESH_MS;
						} else if (diff > MAX_MD_REFRESH_MS) {
							diff = MAX_MD_REFRESH_MS;
						}
						refreshOn = SystemTime.getOffsetTime(diff);
					} else {
						refreshOn = SystemTime.getCurrentTime()
								+ (7 * 24 * 60 * 60 * 1000L);
					}
				}

				log(torrent, "got MD. Next refresh in "
						+ (refreshOn - SystemTime.getCurrentTime()));
				setMetaDataRefreshOn(torrent, refreshOn);
				SimpleTimer.addEvent("Update MD", refreshOn, new TimerEventPerformer() {
					public void perform(TimerEvent event) {
						PlatformTorrentUtils.updateMetaData(torrent, 15000);
					}
				});
			} else {
				long refreshOn = SystemTime.getCurrentTime()
						+ (30 * 24 * 60 * 60 * 1000L);
				setMetaDataRefreshOn(torrent, refreshOn);
				log(torrent, "no hash in reply. Next refresh on " + new Date(refreshOn));
			}
		}
	
public static booleanuseEMP(org.gudy.azureus2.core3.torrent.TOTorrent torrent)

		return getContentMapLong(torrent, TOR_AZ_PROP_USE_EMP, 0) == 1;
	
private static voidwriteTorrentIfExists(org.gudy.azureus2.core3.torrent.TOTorrent torrent)

		AzureusCore core = AzureusCoreFactory.getSingleton();
		if (core == null || !core.isStarted()) {
			return;
		}

		GlobalManager gm = core.getGlobalManager();
		if (gm == null || gm.getDownloadManager(torrent) == null) {
			return;
		}

		try {
			TorrentUtils.writeToFile(torrent);
		} catch (TOTorrentException e) {
			Debug.out(e);
		}