forked from I2P_Developers/i2p.i2p
* I2CP, HostsTxtNamingService, I2PTunnel:
Implement Base32 Hash hostnames, via the naming service. Names are of the form [52-characters].i2p, where the 52 characters are the Base32 representation of our 256-byte hash. The client requests a lookup of the hash via a brief I2CP session using new I2CP request/reply messages. The router looks up the leaseset for the hash to convert the hash to a dest. Convert the I2PTunnel 'preview' links to use Base32 hostnames as a demonstration.
This commit is contained in:
@@ -11,6 +11,7 @@ package net.i2p.router.client;
|
||||
import net.i2p.data.Payload;
|
||||
import net.i2p.data.i2cp.CreateLeaseSetMessage;
|
||||
import net.i2p.data.i2cp.CreateSessionMessage;
|
||||
import net.i2p.data.i2cp.DestLookupMessage;
|
||||
import net.i2p.data.i2cp.DestroySessionMessage;
|
||||
import net.i2p.data.i2cp.GetDateMessage;
|
||||
import net.i2p.data.i2cp.I2CPMessage;
|
||||
@@ -78,6 +79,9 @@ class ClientMessageEventListener implements I2CPMessageReader.I2CPMessageEventLi
|
||||
case DestroySessionMessage.MESSAGE_TYPE:
|
||||
handleDestroySession(reader, (DestroySessionMessage)message);
|
||||
break;
|
||||
case DestLookupMessage.MESSAGE_TYPE:
|
||||
handleDestLookup(reader, (DestLookupMessage)message);
|
||||
break;
|
||||
default:
|
||||
if (_log.shouldLog(Log.ERROR))
|
||||
_log.error("Unhandled I2CP type received: " + message.getType());
|
||||
@@ -85,13 +89,14 @@ class ClientMessageEventListener implements I2CPMessageReader.I2CPMessageEventLi
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle notifiation that there was an error
|
||||
* Handle notification that there was an error
|
||||
*
|
||||
*/
|
||||
public void readError(I2CPMessageReader reader, Exception error) {
|
||||
if (_runner.isDead()) return;
|
||||
if (_log.shouldLog(Log.ERROR))
|
||||
_log.error("Error occurred", error);
|
||||
// Is this is a little drastic for an unknown message type?
|
||||
_runner.stopRunning();
|
||||
}
|
||||
|
||||
@@ -228,6 +233,10 @@ class ClientMessageEventListener implements I2CPMessageReader.I2CPMessageEventLi
|
||||
_runner.leaseSetCreated(message.getLeaseSet());
|
||||
}
|
||||
|
||||
private void handleDestLookup(I2CPMessageReader reader, DestLookupMessage message) {
|
||||
_context.jobQueue().addJob(new LookupDestJob(_context, _runner, message.getHash()));
|
||||
}
|
||||
|
||||
// this *should* be mod 65536, but UnsignedInteger is still b0rked. FIXME
|
||||
private final static int MAX_SESSION_ID = 32767;
|
||||
|
||||
|
54
router/java/src/net/i2p/router/client/LookupDestJob.java
Normal file
54
router/java/src/net/i2p/router/client/LookupDestJob.java
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Released into the public domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
*/
|
||||
package net.i2p.router.client;
|
||||
|
||||
import net.i2p.data.Destination;
|
||||
import net.i2p.data.Hash;
|
||||
import net.i2p.data.LeaseSet;
|
||||
import net.i2p.data.i2cp.DestReplyMessage;
|
||||
import net.i2p.data.i2cp.I2CPMessageException;
|
||||
import net.i2p.router.JobImpl;
|
||||
import net.i2p.router.RouterContext;
|
||||
|
||||
/**
|
||||
* Look up the lease of a hash, to convert it to a Destination for the client
|
||||
*/
|
||||
class LookupDestJob extends JobImpl {
|
||||
private ClientConnectionRunner _runner;
|
||||
private Hash _hash;
|
||||
|
||||
public LookupDestJob(RouterContext context, ClientConnectionRunner runner, Hash h) {
|
||||
super(context);
|
||||
_runner = runner;
|
||||
_hash = h;
|
||||
}
|
||||
|
||||
public String getName() { return "LeaseSet Lookup for Client"; }
|
||||
public void runJob() {
|
||||
DoneJob done = new DoneJob(getContext());
|
||||
getContext().netDb().lookupLeaseSet(_hash, done, done, 10*1000);
|
||||
}
|
||||
|
||||
private class DoneJob extends JobImpl {
|
||||
public DoneJob(RouterContext enclosingContext) {
|
||||
super(enclosingContext);
|
||||
}
|
||||
public String getName() { return "LeaseSet Lookup Reply to Client"; }
|
||||
public void runJob() {
|
||||
LeaseSet ls = getContext().netDb().lookupLeaseSetLocally(_hash);
|
||||
if (ls != null)
|
||||
returnDest(ls.getDestination());
|
||||
else
|
||||
returnDest(null);
|
||||
}
|
||||
}
|
||||
|
||||
private void returnDest(Destination d) {
|
||||
DestReplyMessage msg = new DestReplyMessage(d);
|
||||
try {
|
||||
_runner.doSend(msg);
|
||||
} catch (I2CPMessageException ime) {}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user