use of net.i2p.util.I2PAppThread in project i2p.i2p by i2p.
the class FetchAndAdd method startTorrent.
// Snark overrides so all the buttons and stats on the web page work
@Override
public synchronized void startTorrent() {
if (_isRunning)
return;
// reset counters in case starting a second time
_remaining = -1;
// leave the total if we knew it before
// _total = -1;
_transferred = 0;
_failCause = null;
_started = _util.getContext().clock().now();
_isRunning = true;
_active = false;
_thread = new I2PAppThread(this, "Torrent File EepGet", true);
_thread.start();
}
use of net.i2p.util.I2PAppThread in project i2p.i2p by i2p.
the class TrackerClient method start.
public synchronized void start() {
if (!stop) {
if (_log.shouldLog(Log.WARN))
_log.warn("Already started: " + _threadName);
return;
}
stop = false;
consecutiveFails = 0;
runStarted = false;
_fastUnannounce = false;
snark.setTrackerProblems(null);
_thread = new I2PAppThread(this, _threadName + " #" + (++_runCount), true);
_thread.start();
started = true;
}
use of net.i2p.util.I2PAppThread in project i2p.i2p by i2p.
the class PeerCoordinator method addPeer.
/**
* Add peer (inbound or outbound)
* @return true if actual attempt to add peer occurs
*/
public boolean addPeer(final Peer peer) {
if (halted) {
peer.disconnect(false);
return false;
}
boolean need_more;
int peersize = 0;
synchronized (peers) {
peersize = peers.size();
// This isn't a strict limit, as we may have several pending connections;
// thus there is an additional check in connected()
need_more = (!peer.isConnected()) && peersize < getMaxConnections();
// Check if we already have this peer before we build the connection
Peer old = peerIDInList(peer.getPeerID(), peers);
need_more = need_more && ((old == null) || (old.getInactiveTime() > MAX_INACTIVE));
}
if (need_more) {
if (_log.shouldLog(Log.DEBUG)) {
// just for logging
String name;
if (metainfo == null)
name = "Magnet";
else
name = metainfo.getName();
_log.debug("Adding a peer " + peer.getPeerID().toString() + " for " + name, new Exception("add/run"));
}
// Run the peer with us as listener and the current bitfield.
final PeerListener listener = this;
final BitField bitfield;
if (storage != null)
bitfield = storage.getBitField();
else
bitfield = null;
// if we aren't a seed but we don't want any more
final boolean partialComplete = wantedBytes == 0 && bitfield != null && !bitfield.complete();
Runnable r = new Runnable() {
public void run() {
peer.runConnection(_util, listener, bitfield, magnetState, partialComplete);
}
};
String threadName = "Snark peer " + peer.toString();
new I2PAppThread(r, threadName).start();
return true;
}
if (_log.shouldLog(Log.DEBUG)) {
if (peer.isConnected())
_log.info("Add peer already connected: " + peer);
else
_log.info("Connections: " + peersize + "/" + getMaxConnections() + " not accepting extra peer: " + peer);
}
return false;
}
use of net.i2p.util.I2PAppThread in project i2p.i2p by i2p.
the class Reseeder method requestReseed.
/**
* Start a reseed from a single zip or su3 URL only.
* Threaded, nonblocking.
*
* @throws IllegalArgumentException if it doesn't end with zip or su3
* @since 0.9.19
*/
void requestReseed(URI url) throws IllegalArgumentException {
ReseedRunner reseedRunner = new ReseedRunner(url);
// set to daemon so it doesn't hang a shutdown
Thread reseed = new I2PAppThread(reseedRunner, "Reseed", true);
reseed.start();
}
use of net.i2p.util.I2PAppThread in project i2p.i2p by i2p.
the class SAMv2StreamSession method connect.
/**
* Connect the SAM STREAM session to the specified Destination
*
* @param id Unique id for the connection
* @param dest Base64-encoded Destination to connect to
* @param props Options to be used for connection
*
* @throws DataFormatException if the destination is not valid
* @throws SAMInvalidDirectionException if trying to connect through a
* receive-only session
* @return true if the communication with the SAM client is ok
*/
@Override
public boolean connect(int id, String dest, Properties props) throws DataFormatException, SAMInvalidDirectionException {
if (!canCreate) {
if (_log.shouldLog(Log.DEBUG))
_log.debug("Trying to create an outgoing connection using a receive-only session");
throw new SAMInvalidDirectionException("Trying to create connections through a receive-only session");
}
if (checkSocketHandlerId(id)) {
if (_log.shouldLog(Log.DEBUG))
_log.debug("The specified id (" + id + ") is already in use");
return false;
}
Destination d = SAMUtils.getDest(dest);
I2PSocketOptions opts = socketMgr.buildOptions(props);
if (props.getProperty(I2PSocketOptions.PROP_CONNECT_TIMEOUT) == null)
opts.setConnectTimeout(60 * 1000);
if (_log.shouldLog(Log.DEBUG))
_log.debug("Connecting new I2PSocket...");
// non-blocking connection (SAMv2)
StreamConnector connector = new StreamConnector(id, d, opts);
I2PAppThread connectThread = new I2PAppThread(connector, "StreamConnector" + id);
connectThread.start();
return true;
}
Aggregations