use of net.i2p.data.Destination in project i2p.i2p by i2p.
the class Snark method x_startTorrent.
private void x_startTorrent() {
boolean ok = _util.connect();
if (!ok)
fatal("Unable to connect to I2P");
if (coordinator == null) {
I2PServerSocket serversocket = _util.getServerSocket();
if (serversocket == null)
fatal("Unable to listen for I2P connections");
else {
Destination d = serversocket.getManager().getSession().getMyDestination();
if (_log.shouldLog(Log.INFO))
_log.info("Listening on I2P destination " + d.toBase64() + " / " + d.calculateHash().toBase64());
}
if (_log.shouldLog(Log.INFO))
_log.info("Starting PeerCoordinator, ConnectionAcceptor, and TrackerClient");
activity = "Collecting pieces";
coordinator = new PeerCoordinator(_util, id, infoHash, meta, storage, this, this);
coordinator.setUploaded(savedUploaded);
if (_peerCoordinatorSet != null) {
// multitorrent
_peerCoordinatorSet.add(coordinator);
} else {
// single torrent
acceptor = new ConnectionAcceptor(_util, new PeerAcceptor(coordinator));
}
// TODO pass saved closest DHT nodes to the tracker? or direct to the coordinator?
trackerclient = new TrackerClient(_util, meta, additionalTrackerURL, coordinator, this);
}
// ensure acceptor is running when in multitorrent
if (_peerCoordinatorSet != null && acceptor != null) {
acceptor.startAccepting();
}
stopped = false;
if (coordinator.halted()) {
coordinator.restart();
if (_peerCoordinatorSet != null)
_peerCoordinatorSet.add(coordinator);
}
if (!trackerclient.started()) {
trackerclient.start();
} else if (trackerclient.halted()) {
if (storage != null) {
try {
storage.reopen();
} catch (IOException ioe) {
try {
storage.close();
} catch (IOException ioee) {
ioee.printStackTrace();
}
fatal("Could not reopen storage", ioe);
}
}
trackerclient.start();
} else {
if (_log.shouldLog(Log.INFO))
_log.info("NOT starting TrackerClient???");
}
}
use of net.i2p.data.Destination in project i2p.i2p by i2p.
the class KRPC method receivePong.
/**
* If node info was previously created with the dummy NID,
* replace it with the received NID.
*/
private void receivePong(NodeInfo nInfo, byte[] nid) {
if (nInfo.getNID().equals(FAKE_NID)) {
NodeInfo newInfo = new NodeInfo(new NID(nid), nInfo.getHash(), nInfo.getPort());
Destination dest = nInfo.getDestination();
if (dest != null)
newInfo.setDestination(dest);
heardFrom(newInfo);
}
if (_log.shouldLog(Log.INFO))
_log.info("Rcvd pong from: " + nInfo);
}
use of net.i2p.data.Destination 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;
}
use of net.i2p.data.Destination in project i2p.i2p by i2p.
the class ConfigTunnelsHelper method getForm.
public String getForm() {
StringBuilder buf = new StringBuilder(1024);
// HTML: <input> cannot be inside a <table>
buf.append("<input type=\"hidden\" name=\"pool.0\" value=\"exploratory\" >\n");
int cur = 1;
Set<Destination> clients = _context.clientManager().listClients();
for (Destination dest : clients) {
buf.append("<input type=\"hidden\" name=\"pool.").append(cur).append("\" value=\"");
buf.append(dest.calculateHash().toBase64()).append("\" >\n");
cur++;
}
buf.append("<table id=\"tunnelconfig\">\n");
TunnelPoolSettings exploratoryIn = _context.tunnelManager().getInboundSettings();
TunnelPoolSettings exploratoryOut = _context.tunnelManager().getOutboundSettings();
renderForm(buf, 0, "exploratory", _t("Exploratory tunnels"), exploratoryIn, exploratoryOut);
cur = 1;
for (Destination dest : clients) {
TunnelPoolSettings in = _context.tunnelManager().getInboundSettings(dest.calculateHash());
TunnelPoolSettings out = _context.tunnelManager().getOutboundSettings(dest.calculateHash());
if (in == null || in.getAliasOf() != null || out == null || out.getAliasOf() != null)
continue;
String name = in.getDestinationNickname();
if (name == null)
name = out.getDestinationNickname();
if (name == null)
name = dest.calculateHash().toBase64().substring(0, 6);
String prefix = dest.calculateHash().toBase64().substring(0, 4);
renderForm(buf, cur, prefix, _t("Client tunnels for {0}", DataHelper.escapeHTML(_t(name))), in, out);
cur++;
}
buf.append("</table>\n");
return buf.toString();
}
use of net.i2p.data.Destination in project i2p.i2p by i2p.
the class ConfigKeyringHelper method render.
/**
* @since 0.9.33 moved from PersistentKeyRing
*/
private void render(StringBuilder buf, boolean local) {
buf.append("\n<table class=\"configtable\"><tr><th align=\"left\">").append(_t("Destination")).append("<th align=\"left\">").append(_t("Name")).append("<th align=\"left\">").append(_t("Encryption Key")).append("</tr>");
for (Map.Entry<Hash, SessionKey> e : _context.keyRing().entrySet()) {
Hash h = e.getKey();
if (local != _context.clientManager().isLocal(h))
continue;
buf.append("\n<tr><td>");
buf.append(h.toBase32());
buf.append("</td><td>");
Destination dest = _context.netDb().lookupDestinationLocally(h);
if (dest != null && local) {
TunnelPoolSettings in = _context.tunnelManager().getInboundSettings(h);
if (in != null && in.getDestinationNickname() != null)
buf.append(in.getDestinationNickname());
} else {
String host = _context.namingService().reverseLookup(h);
if (host != null)
buf.append(host);
}
buf.append("</td><td>");
SessionKey sk = e.getValue();
buf.append(sk.toBase64());
buf.append("</td>\n");
}
buf.append("</table>\n");
}
Aggregations