Search in sources :

Example 71 with Destination

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();
}
Also used : I2PException(net.i2p.I2PException) Destination(net.i2p.data.Destination) InterruptedIOException(java.io.InterruptedIOException) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) I2PSocket(net.i2p.client.streaming.I2PSocket) OutputStream(java.io.OutputStream) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) NoRouteToHostException(java.net.NoRouteToHostException) BufferedWriter(java.io.BufferedWriter) DataFormatException(net.i2p.data.DataFormatException) Random(java.util.Random) BufferedReader(java.io.BufferedReader) OutputStreamWriter(java.io.OutputStreamWriter) ConnectException(java.net.ConnectException)

Example 72 with Destination

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();
}
Also used : Destination(net.i2p.data.Destination) HttpURLConnection(java.net.HttpURLConnection) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 73 with Destination

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;
}
Also used : Destination(net.i2p.data.Destination) DataFormatException(net.i2p.data.DataFormatException) KeyException(java.security.KeyException)

Example 74 with Destination

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)));
}
Also used : Destination(net.i2p.data.Destination) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) I2PSocketManagerFull(net.i2p.client.streaming.impl.I2PSocketManagerFull) Test(org.junit.Test)

Example 75 with Destination

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());
}
Also used : Destination(net.i2p.data.Destination) Test(org.junit.Test)

Aggregations

Destination (net.i2p.data.Destination)149 IOException (java.io.IOException)46 DataFormatException (net.i2p.data.DataFormatException)33 Properties (java.util.Properties)29 I2PException (net.i2p.I2PException)26 Hash (net.i2p.data.Hash)18 ArrayList (java.util.ArrayList)13 File (java.io.File)12 I2PSessionException (net.i2p.client.I2PSessionException)12 SigType (net.i2p.crypto.SigType)12 ByteArrayInputStream (java.io.ByteArrayInputStream)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 I2PSession (net.i2p.client.I2PSession)10 I2PSocket (net.i2p.client.streaming.I2PSocket)10 FileInputStream (java.io.FileInputStream)7 InputStream (java.io.InputStream)7 OutputStream (java.io.OutputStream)7 I2PClient (net.i2p.client.I2PClient)7 I2PSocketOptions (net.i2p.client.streaming.I2PSocketOptions)7 Test (org.junit.Test)6