beginning of branch i2p.i2p.i2p

This commit is contained in:
cvs_import
2004-04-08 04:41:54 +00:00
committed by zzz
commit 77bd69c5e5
292 changed files with 41035 additions and 0 deletions
+86
View File
@@ -0,0 +1,86 @@
/*
* $Id $
* Copyright (c) 2003 mihi
* Licensed under the GNU Public License (GPL) as published by the
* Free Software Foundation, using version 2 or later of the GPL. You
* should have recieved the GPL with this source code, otherwise see
* http://www.fsf.org/copyleft/
*/
import java.io.*;
import java.net.*;
public class FetchSeeds {
/**
* Fetch seednodes.
*
* @param destination the dir to store the seednodes to
* @param sourceURL the URL to fetch the seednode from - must end
* with a slash
* @return whether new seed nodes could be fetched
*/
public static boolean fetchSeeds(File destination, String sourceURL) {
InputStream in = null;
try {
URL source = new URL(sourceURL);
URLConnection con = source.openConnection();
in = con.getInputStream();
BufferedReader br = new BufferedReader
(new InputStreamReader(in));
String line;
while ((line = br.readLine())!= null) {
int pos = line.indexOf(" <a href=\"routerInfo-");
if (pos == -1) continue;
line=line.substring(pos+10);
pos=line.indexOf("\"");
if (pos == -1) continue;
line=line.substring(0,pos);
fetchFile(new File(destination, line), sourceURL+line);
System.out.println(line);
}
br.close();
return true;
} catch (IOException ex) {
System.err.println("Unable to fetch seeds from " + sourceURL + ": " + ex.getMessage());
//ex.printStackTrace();
return false;
} finally {
if (in != null) try { in.close(); } catch (IOException ioe) {}
}
}
public static void fetchFile(File destFile, String fileURL)
throws IOException {
URL url = new URL(fileURL);
InputStream in = url.openStream();
OutputStream out = new FileOutputStream(destFile);
byte[] buf = new byte[1024];
int len;
while ((len=in.read(buf)) != -1) {
out.write(buf,0,len);
}
in.close();
out.flush();
out.close();
}
/**
* test main method.
*/
public static void main(String[] args) {
switch (args.length) {
case 1:
fetchSeeds(new File(args[0]), "http://i2p.dnsalias.net/i2pdb/");
return;
case 2:
fetchSeeds(new File(args[0]), args[1]);
return;
default:
System.out.println("Usage: FetchSeeds <outDir>");
System.out.println(" or FetchSeeds <outDir> <seedURL>");
System.out.println("The default seedURL is http://i2p.dnsalias.net/i2pdb/");
return;
}
}
}