use of net.i2p.data.Destination in project i2p.i2p-bote by i2p.
the class SeedlessAnnounce method doSeedlessAnnounce.
private synchronized void doSeedlessAnnounce() {
List<String> seedlessServers = seedlessScrapeServers.getSeedlessServers();
if (seedlessServers.isEmpty()) {
// try again in a minute.
log.error("SeedlessServers.isEmpty, will retry shortly.");
lastSeedlessAnnounce = System.currentTimeMillis() - (interval - TimeUnit.MINUTES.toMillis(1));
return;
}
// Announce to 10 servers.
// We do this over the i2pSocket.
int successful = Math.min(10, seedlessServers.size());
log.debug("Try to announce to " + successful + " Seedless Servers");
Collections.shuffle(seedlessServers, new Random());
Iterator<String> it = seedlessServers.iterator();
String line;
I2PSocket I2P;
InputStream Iin;
OutputStream Iout;
BufferedReader data;
Boolean didsomething = false;
BufferedWriter output;
while (successful > 0 && it.hasNext()) {
lastSeedlessAnnounce = System.currentTimeMillis();
String b32 = it.next();
Destination dest = null;
I2P = null;
try {
lastSeedlessAnnounce = System.currentTimeMillis();
// deprecated dest = I2PTunnel.destFromName(b32);
dest = I2PAppContext.getGlobalContext().namingService().lookup(b32);
lastSeedlessAnnounce = System.currentTimeMillis();
if (dest == null) {
log.debug("Could not find the destination: <" + b32 + ">");
continue;
}
line = dest.toBase64();
dest = new Destination();
dest.fromBase64(line);
I2P = socketManager.connect(dest);
// I2P.setReadTimeout(0); // temp bugfix, this *SHOULD* be the default
// make readers/writers
Iin = I2P.getInputStream();
Iout = I2P.getOutputStream();
output = new BufferedWriter(new OutputStreamWriter(Iout));
output.write(announceString);
output.flush();
data = new BufferedReader(new InputStreamReader(Iin));
// Check for success.
line = data.readLine();
if (line != null) {
if (line.contains(" 200 ")) {
log.debug("Announced to " + b32);
successful--;
didsomething = true;
} else {
log.debug("Announce to " + b32 + " Failed with Error " + line);
log.debug("We sent " + announceString);
}
}
while ((line = data.readLine()) != null) {
}
} catch (DataFormatException ex) {
log.debug("Not base64!", ex);
} catch (ConnectException ex) {
log.debug("ConnectException", ex);
} catch (NoRouteToHostException ex) {
log.debug("NoRouteToHostException", ex);
} catch (InterruptedIOException ex) {
log.debug("InterruptedIOException", ex);
} catch (IOException ex) {
log.debug("IOException", ex);
ex.printStackTrace();
} catch (I2PException ex) {
log.debug("I2PException", ex);
}
if (I2P != null) {
try {
I2P.close();
} catch (IOException ex) {
// don't care.
}
}
}
if (!didsomething) {
// try again in 1 minute.
lastSeedlessAnnounce = System.currentTimeMillis() - (interval - TimeUnit.MINUTES.toMillis(1));
return;
}
lastSeedlessAnnounce = System.currentTimeMillis();
}
use of net.i2p.data.Destination in project i2p.i2p-bote by i2p.
the class SeedlessScrapePeers method doSeedlessScrapePeers.
private synchronized void doSeedlessScrapePeers() {
HttpURLConnection h;
int i;
String foo;
List<String> metadatas = new ArrayList<String>();
List<String> ip32s = new ArrayList<String>();
InputStream in;
BufferedReader data;
String line;
String ip32;
log.debug("doSeedlessScrapePeers");
try {
ProxyRequest proxy = new ProxyRequest();
h = proxy.doURLRequest(seedlessParameters.getSeedlessUrl(), seedlessParameters.getPeersLocateHeader(), null, -1, "admin", seedlessParameters.getConsolePassword());
if (h != null) {
i = h.getResponseCode();
if (i == 200) {
in = h.getInputStream();
data = new BufferedReader(new InputStreamReader(in));
while ((line = data.readLine()) != null) {
metadatas.add(line);
}
Iterator<String> it = metadatas.iterator();
while (it.hasNext()) {
foo = it.next();
ip32 = Base64.decodeToString(foo).split(" ")[0].trim();
if (!ip32s.contains(ip32)) {
ip32s.add(ip32);
}
}
}
}
} catch (IOException ex) {
}
for (String b32Peer : ip32s) {
Destination peer = lookup(b32Peer);
if (peer != null)
synchronized (this) {
peers.add(peer);
}
}
log.debug("doSeedlessScrapePeers Done.");
lastSeedlessScrapePeers = System.currentTimeMillis();
}
use of net.i2p.data.Destination in project i2p.i2p-bote by i2p.
the class ElGamal2048_DSA1024 method createPublicKeyPair.
@Override
public PublicKeyPair createPublicKeyPair(String base64) throws GeneralSecurityException {
Destination i2pDestination;
// add a null certificate
base64 += "AAAA";
try {
i2pDestination = new Destination(base64);
} catch (DataFormatException e) {
throw new KeyException("Can't create I2P destination from Base64: <" + base64 + ">", e);
}
PublicKeyPair keyPair = new PublicKeyPair();
keyPair.encryptionKey = new ElGamalPublicKey(i2pDestination.getPublicKey());
keyPair.signingKey = new DSAPublicKey(i2pDestination.getSigningPublicKey());
return keyPair;
}
use of net.i2p.data.Destination in project i2p.i2p by i2p.
the class I2PSocketManagerFactoryTest method testCreateDiscMgr_customDest.
@Test
public void testCreateDiscMgr_customDest() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Destination dest = I2PClientFactory.createClient().createDestination(baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
I2PSocketManagerFull mgr = (I2PSocketManagerFull) I2PSocketManagerFactory.createDisconnectedManager(bais, null, 0, null);
assertThat(mgr, is(not(nullValue())));
assertThat(mgr.getName(), is("manager"));
assertThat(mgr.getSession().getMyDestination(), is(equalTo(dest)));
}
use of net.i2p.data.Destination in project i2p.i2p by i2p.
the class I2PSocketAddressTest method testConstruct_Dest.
@Test
public void testConstruct_Dest() {
Destination dest = new Destination();
I2PSocketAddress addr = new I2PSocketAddress(dest, 1234);
assertThat(addr.getPort(), is(1234));
assertThat(addr.getAddress(), is(dest));
assertThat(addr.getHostName(), is(nullValue()));
assertFalse(addr.isUnresolved());
}
Aggregations