* Moved PetName and PetNameDB to core.
* Implement PetNameNamingService.
This commit is contained in:
@ -4,6 +4,8 @@ import java.io.*;
|
|||||||
import java.text.*;
|
import java.text.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import net.i2p.I2PAppContext;
|
import net.i2p.I2PAppContext;
|
||||||
|
import net.i2p.client.naming.PetName;
|
||||||
|
import net.i2p.client.naming.PetNameDB;
|
||||||
import net.i2p.data.*;
|
import net.i2p.data.*;
|
||||||
import net.i2p.syndie.data.*;
|
import net.i2p.syndie.data.*;
|
||||||
import net.i2p.syndie.sml.*;
|
import net.i2p.syndie.sml.*;
|
||||||
|
@ -4,6 +4,7 @@ import java.io.UnsupportedEncodingException;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import net.i2p.I2PAppContext;
|
import net.i2p.I2PAppContext;
|
||||||
|
import net.i2p.client.naming.PetNameDB;
|
||||||
import net.i2p.data.*;
|
import net.i2p.data.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,6 +4,7 @@ import java.io.*;
|
|||||||
import java.text.*;
|
import java.text.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import net.i2p.I2PAppContext;
|
import net.i2p.I2PAppContext;
|
||||||
|
import net.i2p.client.naming.PetName;
|
||||||
import net.i2p.data.*;
|
import net.i2p.data.*;
|
||||||
import net.i2p.syndie.*;
|
import net.i2p.syndie.*;
|
||||||
import net.i2p.syndie.data.*;
|
import net.i2p.syndie.data.*;
|
||||||
|
@ -4,6 +4,8 @@ import java.io.*;
|
|||||||
import java.text.*;
|
import java.text.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import net.i2p.I2PAppContext;
|
import net.i2p.I2PAppContext;
|
||||||
|
import net.i2p.client.naming.PetName;
|
||||||
|
import net.i2p.client.naming.PetNameDB;
|
||||||
import net.i2p.data.*;
|
import net.i2p.data.*;
|
||||||
import net.i2p.syndie.*;
|
import net.i2p.syndie.*;
|
||||||
import net.i2p.syndie.data.*;
|
import net.i2p.syndie.data.*;
|
||||||
|
@ -3,6 +3,7 @@ package net.i2p.syndie.web;
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import net.i2p.I2PAppContext;
|
import net.i2p.I2PAppContext;
|
||||||
|
import net.i2p.client.naming.PetName;
|
||||||
import net.i2p.syndie.*;
|
import net.i2p.syndie.*;
|
||||||
import net.i2p.syndie.data.BlogURI;
|
import net.i2p.syndie.data.BlogURI;
|
||||||
import net.i2p.syndie.sml.HTMLPreviewRenderer;
|
import net.i2p.syndie.sml.HTMLPreviewRenderer;
|
||||||
|
@ -5,6 +5,7 @@ import java.text.*;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.zip.*;
|
import java.util.zip.*;
|
||||||
import net.i2p.I2PAppContext;
|
import net.i2p.I2PAppContext;
|
||||||
|
import net.i2p.client.naming.PetNameDB;
|
||||||
import net.i2p.data.*;
|
import net.i2p.data.*;
|
||||||
import net.i2p.util.EepGet;
|
import net.i2p.util.EepGet;
|
||||||
import net.i2p.util.EepGetScheduler;
|
import net.i2p.util.EepGetScheduler;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<%@page contentType="text/html; charset=UTF-8" import="net.i2p.syndie.web.ArchiveViewerBean, net.i2p.syndie.*" %>
|
<%@page contentType="text/html; charset=UTF-8" import="net.i2p.syndie.web.ArchiveViewerBean, net.i2p.syndie.*, net.i2p.client.naming.PetName" %>
|
||||||
<% request.setCharacterEncoding("UTF-8"); %>
|
<% request.setCharacterEncoding("UTF-8"); %>
|
||||||
<jsp:useBean scope="session" class="net.i2p.syndie.User" id="user" /><%
|
<jsp:useBean scope="session" class="net.i2p.syndie.User" id="user" /><%
|
||||||
if (user.getAuthenticated() && (null != request.getParameter("action")) ) {
|
if (user.getAuthenticated() && (null != request.getParameter("action")) ) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="net.i2p.data.Base64, net.i2p.syndie.web.*, net.i2p.syndie.sml.*, net.i2p.syndie.data.*, net.i2p.syndie.*, org.mortbay.servlet.MultiPartRequest, java.util.*, java.io.*" %><%
|
<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="net.i2p.data.Base64, net.i2p.syndie.web.*, net.i2p.syndie.sml.*, net.i2p.syndie.data.*, net.i2p.syndie.*, net.i2p.client.naming.PetName, net.i2p.client.naming.PetNameDB, org.mortbay.servlet.MultiPartRequest, java.util.*, java.io.*" %><%
|
||||||
request.setCharacterEncoding("UTF-8"); %><jsp:useBean scope="session" class="net.i2p.syndie.User" id="user"
|
request.setCharacterEncoding("UTF-8"); %><jsp:useBean scope="session" class="net.i2p.syndie.User" id="user"
|
||||||
/><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
|
/><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
|
||||||
<html>
|
<html>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="net.i2p.data.Base64, net.i2p.syndie.web.*, net.i2p.syndie.sml.*, net.i2p.syndie.data.*, net.i2p.syndie.*, org.mortbay.servlet.MultiPartRequest, java.util.*" %><%
|
<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="net.i2p.data.Base64, net.i2p.client.naming.PetName, net.i2p.client.naming.PetNameDB, net.i2p.syndie.web.*, net.i2p.syndie.sml.*, net.i2p.syndie.data.*, net.i2p.syndie.*, org.mortbay.servlet.MultiPartRequest, java.util.*" %><%
|
||||||
request.setCharacterEncoding("UTF-8");
|
request.setCharacterEncoding("UTF-8");
|
||||||
%><jsp:useBean scope="session" class="net.i2p.syndie.User" id="user"
|
%><jsp:useBean scope="session" class="net.i2p.syndie.User" id="user"
|
||||||
/><jsp:useBean scope="session" class="net.i2p.syndie.web.PostBean" id="post"
|
/><jsp:useBean scope="session" class="net.i2p.syndie.web.PostBean" id="post"
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="net.i2p.syndie.web.*, net.i2p.syndie.*, net.i2p.syndie.sml.*, java.util.*" %><%
|
<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="net.i2p.client.naming.PetName, net.i2p.syndie.web.*, net.i2p.syndie.*, net.i2p.syndie.sml.*, java.util.*" %><%
|
||||||
request.setCharacterEncoding("UTF-8");
|
request.setCharacterEncoding("UTF-8");
|
||||||
%><jsp:useBean scope="session" class="net.i2p.syndie.web.RemoteArchiveBean" id="remote"
|
%><jsp:useBean scope="session" class="net.i2p.syndie.web.RemoteArchiveBean" id="remote"
|
||||||
/><jsp:useBean scope="session" class="net.i2p.syndie.User" id="user"
|
/><jsp:useBean scope="session" class="net.i2p.syndie.User" id="user"
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package net.i2p.syndie;
|
package net.i2p.client.naming;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import net.i2p.data.DataHelper;
|
import net.i2p.data.DataHelper;
|
@ -1,8 +1,9 @@
|
|||||||
package net.i2p.syndie;
|
package net.i2p.client.naming;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
@ -0,0 +1,65 @@
|
|||||||
|
package net.i2p.client.naming;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import net.i2p.I2PAppContext;
|
||||||
|
import net.i2p.data.DataHelper;
|
||||||
|
import net.i2p.data.Destination;
|
||||||
|
|
||||||
|
public class PetNameNamingService extends NamingService {
|
||||||
|
|
||||||
|
private PetNameDB _petnameDb;
|
||||||
|
public final static String PROP_PETNAME_FILE = "i2p.petnamefile";
|
||||||
|
public final static String DEFAULT_PETNAME_FILE = "petnames.txt";
|
||||||
|
|
||||||
|
public PetNameNamingService(I2PAppContext context) {
|
||||||
|
super(context);
|
||||||
|
_petnameDb = new PetNameDB();
|
||||||
|
String file = _context.getProperty(PROP_PETNAME_FILE, DEFAULT_PETNAME_FILE);
|
||||||
|
|
||||||
|
//If the petnamedb file doesn't exist, create it, using the
|
||||||
|
//contents of hosts.txt.
|
||||||
|
File nameFile = new File(file);
|
||||||
|
if (!nameFile.exists()) {
|
||||||
|
Properties hosts = new Properties();
|
||||||
|
File hostsFile = new File("hosts.txt");
|
||||||
|
if (hostsFile.exists() && hostsFile.canRead()) {
|
||||||
|
try {
|
||||||
|
DataHelper.loadProps(hosts, hostsFile);
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Iterator iter = hosts.keySet().iterator();
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
String hostname = (String)iter.next();
|
||||||
|
PetName pn = new PetName(hostname, "i2p", "http", hosts.getProperty(hostname));
|
||||||
|
_petnameDb.set(hostname, pn);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
_petnameDb.store(file);
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
_petnameDb.load(file);
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Destination lookup(String hostname) {
|
||||||
|
PetName name = _petnameDb.get(hostname);
|
||||||
|
if (name != null && name.getNetwork().equals("i2p")) {
|
||||||
|
return lookupBase64(name.getLocation());
|
||||||
|
} else {
|
||||||
|
return lookupBase64(hostname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String reverseLookup(Destination dest) {
|
||||||
|
return _petnameDb.getNameByLocation(dest.toBase64());
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user