Package org.klomp.snark
Class I2PSnarkUtil
- java.lang.Object
-
- org.klomp.snark.I2PSnarkUtil
-
- All Implemented Interfaces:
I2PSocketManager.DisconnectListener
public class I2PSnarkUtil extends Object implements I2PSocketManager.DisconnectListener
I2P specific helpers for I2PSnark We use this class as a sort of context for i2psnark so we can run multiple instances of single Snarks (but not multiple SnarkManagers, it is still static)
-
-
Field Summary
Fields Modifier and Type Field Description static booleanDEFAULT_COLLAPSE_PANELSstatic intDEFAULT_STARTUP_DELAYstatic booleanDEFAULT_USE_DHTstatic booleanDEFAULT_USE_OPENTRACKERSstatic StringEEPGET_USER_AGENTstatic intMAX_CONNECTIONSstatic StringPROP_MAX_BW
-
Constructor Summary
Constructors Constructor Description I2PSnarkUtil(I2PAppContext ctx)I2PSnarkUtil(I2PAppContext ctx, String baseName, I2PSocketManager.DisconnectListener discon)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancollapsePanels()booleancommentsEnabled()booleanconnect()Connect to the router, if we aren't already(package private) I2PSocketconnect(PeerID peer)connect to the given destinationbooleanconnected()voiddisconnect()Destroy the destination itselfFileget(String url)Fetch the given URL, returning the file it is stored in, or null on error.Fileget(String url, boolean rewrite)Fileget(String url, boolean rewrite, int retries)byte[]get(String url, boolean rewrite, int retries, int initialSize, int maxSize)Fetch to memoryFileget(String url, int retries)List<String>getBackupTrackers()List of open tracker announce URLs to use as backups even if disabledStringgetCommentsName()I2PAppContextgetContext()(package private) DestinationgetDestination(String ip)Base64 Hash or Hash.i2p or name.i2p using naming service(package private) static DestinationgetDestinationFromBase64(String ip)Base64 only - static (no naming service)DHTgetDHT()StringgetEepProxyHost()intgetEepProxyPort()booleangetEepProxySet()booleangetFilesPublic()StringgetI2CPHost()Map<String,String>getI2CPOptions()intgetI2CPPort()intgetMaxConnections()intgetMaxFilesPerTorrent()intgetMaxUpBW()intgetMaxUploaders()(package private) DestinationgetMyDestination()List<String>getOpenTrackers()List of open tracker announce URLs to use as backupsStringgetOurIPString()Full Base64 of DestinationI2PServerSocketgetServerSocket()I2PSocketManagergetSocketManager()For FetchAndAddlonggetStartedTime()When did we connect to the network? For RPCintgetStartupDelay()StringgetString(int n, String s, String p)ngettext @since 0.7.14StringgetString(String key)lang in routerconsole.lang property, else current localeStringgetString(String s, Object o)translate a string with a parameter This is a lot more expensive than getString(s, ctx), so use sparingly.StringgetString(String s, Object o, Object o2){0} and {1}FilegetTempDir()booleanisConnecting()booleanisKnownOpenTracker(String url)Is this announce URL probably for an open tracker?(package private) static voidloadProps(Properties props, File f)Same as DataHelper.loadProps() but allows '#' in values, so we can have filenames with '#' in them in torrent config files.Stringlookup(String name)booleanratingsEnabled()(package private) StringrewriteAnnounce(String origAnnounce)Given http://KEY.i2p/foo/announce turn it into http://i2p/KEY/foo/announce Given http://tracker.blah.i2p/foo/announce leave it alonevoidsessionDisconnected()DisconnectListener interfacevoidsetCollapsePanels(boolean yes)voidsetCommentsEnabled(boolean yes)voidsetCommentsName(String name)voidsetFilesPublic(boolean yes)voidsetI2CPConfig(String i2cpHost, int i2cpPort, Map opts)voidsetMaxConnections(int limit)voidsetMaxFilesPerTorrent(int max)voidsetMaxUpBW(int limit)This updates ALL the session options (not just the bw) and tells the routervoidsetMaxUploaders(int limit)voidsetOpenTrackers(List<String> ot)voidsetRatingsEnabled(boolean yes)voidsetStartupDelay(int minutes)voidsetUseDHT(boolean yes)voidsetUseOpenTrackers(boolean yes)booleanshouldUseDHT()booleanshouldUseOpenTrackers()(package private) static voidstoreProps(Properties props, File file)Same as DataHelper.loadProps() but allows '#' in values, so we can have filenames with '#' in them in torrent config files.static StringtoHex(byte[] b)Like DataHelper.toHexString but ensures no loss of leading zero bytesbooleanutCommentsEnabled()
-
-
-
Field Detail
-
DEFAULT_STARTUP_DELAY
public static final int DEFAULT_STARTUP_DELAY
- See Also:
- Constant Field Values
-
DEFAULT_COLLAPSE_PANELS
public static final boolean DEFAULT_COLLAPSE_PANELS
- See Also:
- Constant Field Values
-
DEFAULT_USE_OPENTRACKERS
public static final boolean DEFAULT_USE_OPENTRACKERS
- See Also:
- Constant Field Values
-
MAX_CONNECTIONS
public static final int MAX_CONNECTIONS
- See Also:
- Constant Field Values
-
PROP_MAX_BW
public static final String PROP_MAX_BW
- See Also:
- Constant Field Values
-
DEFAULT_USE_DHT
public static final boolean DEFAULT_USE_DHT
- See Also:
- Constant Field Values
-
EEPGET_USER_AGENT
public static final String EEPGET_USER_AGENT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
I2PSnarkUtil
public I2PSnarkUtil(I2PAppContext ctx)
-
I2PSnarkUtil
public I2PSnarkUtil(I2PAppContext ctx, String baseName, I2PSocketManager.DisconnectListener discon)
- Parameters:
baseName- generally "i2psnark"- Since:
- Jetty 7
-
-
Method Detail
-
getContext
public I2PAppContext getContext()
- Since:
- 0.9.1
-
setI2CPConfig
public void setI2CPConfig(String i2cpHost, int i2cpPort, Map opts)
- Parameters:
i2cpHost- may be null for no changei2cpPort- may be 0 for no changeopts- may be null for no change
-
setMaxUploaders
public void setMaxUploaders(int limit)
-
setMaxUpBW
public void setMaxUpBW(int limit)
This updates ALL the session options (not just the bw) and tells the router- Parameters:
limit- KBps
-
setMaxConnections
public void setMaxConnections(int limit)
-
setStartupDelay
public void setStartupDelay(int minutes)
-
getI2CPHost
public String getI2CPHost()
-
getI2CPPort
public int getI2CPPort()
-
getEepProxyHost
public String getEepProxyHost()
-
getEepProxyPort
public int getEepProxyPort()
-
getEepProxySet
public boolean getEepProxySet()
-
getMaxUploaders
public int getMaxUploaders()
-
getMaxUpBW
public int getMaxUpBW()
- Returns:
- KBps
-
getMaxConnections
public int getMaxConnections()
-
getStartupDelay
public int getStartupDelay()
-
getFilesPublic
public boolean getFilesPublic()
- Since:
- 0.8.9
-
setFilesPublic
public void setFilesPublic(boolean yes)
- Since:
- 0.8.9
-
getTempDir
public File getTempDir()
- Since:
- 0.9.1
-
getMaxFilesPerTorrent
public int getMaxFilesPerTorrent()
- Since:
- 0.9.58
-
setMaxFilesPerTorrent
public void setMaxFilesPerTorrent(int max)
- Since:
- 0.9.58
-
connect
public boolean connect()
Connect to the router, if we aren't already
-
sessionDisconnected
public void sessionDisconnected()
DisconnectListener interface- Specified by:
sessionDisconnectedin interfaceI2PSocketManager.DisconnectListener- Since:
- 0.9.53
-
getDHT
public DHT getDHT()
- Returns:
- null if disabled or not started
- Since:
- 0.8.4
-
connected
public boolean connected()
-
isConnecting
public boolean isConnecting()
- Since:
- 0.9.1
-
getSocketManager
public I2PSocketManager getSocketManager()
For FetchAndAdd- Returns:
- null if not connected
- Since:
- 0.9.1
-
disconnect
public void disconnect()
Destroy the destination itself
-
getStartedTime
public long getStartedTime()
When did we connect to the network? For RPC- Returns:
- 0 if not connected
- Since:
- 0.9.30
-
connect
I2PSocket connect(PeerID peer) throws IOException
connect to the given destination- Throws:
IOException
-
get
public File get(String url)
Fetch the given URL, returning the file it is stored in, or null on error. No retries.
-
get
public File get(String url, boolean rewrite)
- Parameters:
rewrite- if true, convert http://KEY.i2p/foo/announce to http://i2p/KEY/foo/announce
-
get
public File get(String url, int retries)
- Parameters:
retries- if < 0, set timeout to a few seconds
-
get
public File get(String url, boolean rewrite, int retries)
- Parameters:
retries- if < 0, set timeout to a few seconds
-
get
public byte[] get(String url, boolean rewrite, int retries, int initialSize, int maxSize)
Fetch to memory- Parameters:
retries- if < 0, set timeout to a few secondsinitialSize- buffer sizemaxSize- fails if greater- Returns:
- null on error
- Since:
- 0.9.4
-
getServerSocket
public I2PServerSocket getServerSocket()
-
getOurIPString
public String getOurIPString()
Full Base64 of Destination
-
getMyDestination
Destination getMyDestination()
- Returns:
- dest or null
- Since:
- 0.8.4
-
getDestinationFromBase64
static Destination getDestinationFromBase64(String ip)
Base64 only - static (no naming service)
-
getDestination
Destination getDestination(String ip)
Base64 Hash or Hash.i2p or name.i2p using naming service
-
rewriteAnnounce
String rewriteAnnounce(String origAnnounce)
Given http://KEY.i2p/foo/announce turn it into http://i2p/KEY/foo/announce Given http://tracker.blah.i2p/foo/announce leave it alone
-
setOpenTrackers
public void setOpenTrackers(List<String> ot)
- Parameters:
ot- non-null list of announce URLs
-
getOpenTrackers
public List<String> getOpenTrackers()
List of open tracker announce URLs to use as backups- Returns:
- non-null, possibly unmodifiable, empty if disabled
-
isKnownOpenTracker
public boolean isKnownOpenTracker(String url)
Is this announce URL probably for an open tracker?- Since:
- 0.9.17
-
getBackupTrackers
public List<String> getBackupTrackers()
List of open tracker announce URLs to use as backups even if disabled- Returns:
- non-null
- Since:
- 0.9.4
-
setUseOpenTrackers
public void setUseOpenTrackers(boolean yes)
-
shouldUseOpenTrackers
public boolean shouldUseOpenTrackers()
-
setUseDHT
public void setUseDHT(boolean yes)
- Since:
- DHT
-
shouldUseDHT
public boolean shouldUseDHT()
- Since:
- DHT
-
setRatingsEnabled
public void setRatingsEnabled(boolean yes)
- Since:
- 0.9.31
-
ratingsEnabled
public boolean ratingsEnabled()
- Since:
- 0.9.31
-
setCommentsEnabled
public void setCommentsEnabled(boolean yes)
- Since:
- 0.9.31
-
commentsEnabled
public boolean commentsEnabled()
- Since:
- 0.9.31
-
setCommentsName
public void setCommentsName(String name)
- Since:
- 0.9.31
-
getCommentsName
public String getCommentsName()
- Returns:
- non-null, "" if none
- Since:
- 0.9.31
-
utCommentsEnabled
public boolean utCommentsEnabled()
- Since:
- 0.9.31
-
collapsePanels
public boolean collapsePanels()
- Since:
- 0.9.32
-
setCollapsePanels
public void setCollapsePanels(boolean yes)
- Since:
- 0.9.32
-
toHex
public static String toHex(byte[] b)
Like DataHelper.toHexString but ensures no loss of leading zero bytes- Since:
- 0.8.4
-
getString
public String getString(String key)
lang in routerconsole.lang property, else current locale
-
getString
public String getString(String s, Object o)
translate a string with a parameter This is a lot more expensive than getString(s, ctx), so use sparingly.- Parameters:
s- string to be translated containing {0} The {0} will be replaced by the parameter. Single quotes must be doubled, i.e. ' -> '' in the string.o- parameter, not translated. To translate parameter also, use _t("foo {0} bar", _t("baz")) Do not double the single quotes in the parameter. Use autoboxing to call with ints, longs, floats, etc.
-
loadProps
static void loadProps(Properties props, File f) throws IOException
Same as DataHelper.loadProps() but allows '#' in values, so we can have filenames with '#' in them in torrent config files. '#' must be in column 1 for a comment.- Throws:
IOException- Since:
- 0.9.58
-
storeProps
static void storeProps(Properties props, File file) throws IOException
Same as DataHelper.loadProps() but allows '#' in values, so we can have filenames with '#' in them in torrent config files. '#' must be in column 1 for a comment.- Throws:
IOException- Since:
- 0.9.58
-
-