2004-04-08 04:41:54 +00:00
|
|
|
package net.i2p.data.i2np;
|
|
|
|
/*
|
|
|
|
* free (adj.): unencumbered; not under the control of others
|
big ol' update to strip out the singletons, replacing them with
a rooted app context. The core itself has its own I2PAppContext
(see its javadoc for, uh, docs), and the router extends that to
expose the router's singletons. The main point of this is to
make it so that we can run multiple routers in the same JVM, even
to allow different apps in the same JVM to switch singleton
implementations (e.g. run some routers with one set of profile
calculators, and other routers with a different one).
There is still some work to be done regarding the actual boot up
of multiple routers in a JVM, as well as their configuration,
though the plan is to have the RouterContext override the
I2PAppContext's getProperty/getPropertyNames methods to read from
a config file (seperate ones per context) instead of using the
System.getProperty that the base I2PAppContext uses.
Once the multi-router is working, i'll shim in a VMCommSystem
that doesn't depend upon sockets or threads to read/write (and
that uses configurable message send delays / disconnects / etc,
perhaps using data from the routerContext.getProperty to drive it).
I could hold off until the sim is all working, but there's a
truckload of changes in here and I hate dealing with conflicts ;)
Everything works - I've been running 'er for a while and kicked
the tires a bit, but if you see something amiss, please let me
know.
2004-04-24 11:54:35 +00:00
|
|
|
* Written by jrandom in 2003 and released into the public domain
|
|
|
|
* with no warranty of any kind, either expressed or implied.
|
|
|
|
* It probably won't make your computer catch on fire, or eat
|
2004-04-08 04:41:54 +00:00
|
|
|
* your children, but it might. Use at your own risk.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
2004-05-17 03:38:53 +00:00
|
|
|
import net.i2p.I2PAppContext;
|
2004-04-08 04:41:54 +00:00
|
|
|
import net.i2p.data.DataFormatException;
|
|
|
|
import net.i2p.data.DataHelper;
|
|
|
|
import net.i2p.data.Hash;
|
|
|
|
import net.i2p.data.TunnelId;
|
|
|
|
import net.i2p.util.Log;
|
|
|
|
|
|
|
|
/**
|
big ol' update to strip out the singletons, replacing them with
a rooted app context. The core itself has its own I2PAppContext
(see its javadoc for, uh, docs), and the router extends that to
expose the router's singletons. The main point of this is to
make it so that we can run multiple routers in the same JVM, even
to allow different apps in the same JVM to switch singleton
implementations (e.g. run some routers with one set of profile
calculators, and other routers with a different one).
There is still some work to be done regarding the actual boot up
of multiple routers in a JVM, as well as their configuration,
though the plan is to have the RouterContext override the
I2PAppContext's getProperty/getPropertyNames methods to read from
a config file (seperate ones per context) instead of using the
System.getProperty that the base I2PAppContext uses.
Once the multi-router is working, i'll shim in a VMCommSystem
that doesn't depend upon sockets or threads to read/write (and
that uses configurable message send delays / disconnects / etc,
perhaps using data from the routerContext.getProperty to drive it).
I could hold off until the sim is all working, but there's a
truckload of changes in here and I hate dealing with conflicts ;)
Everything works - I've been running 'er for a while and kicked
the tires a bit, but if you see something amiss, please let me
know.
2004-04-24 11:54:35 +00:00
|
|
|
* Defines the message a router sends to another router in reply to a
|
2004-04-08 04:41:54 +00:00
|
|
|
* TunnelCreateMessage
|
|
|
|
*
|
|
|
|
* @author jrandom
|
|
|
|
*/
|
|
|
|
public class TunnelCreateStatusMessage extends I2NPMessageImpl {
|
|
|
|
private final static Log _log = new Log(TunnelCreateStatusMessage.class);
|
|
|
|
public final static int MESSAGE_TYPE = 7;
|
|
|
|
private TunnelId _tunnelId;
|
|
|
|
private int _status;
|
|
|
|
private Hash _from;
|
|
|
|
|
|
|
|
public final static int STATUS_SUCCESS = 0;
|
|
|
|
public final static int STATUS_FAILED_DUPLICATE_ID = 1;
|
|
|
|
public final static int STATUS_FAILED_OVERLOADED = 2;
|
|
|
|
public final static int STATUS_FAILED_CERTIFICATE = 3;
|
|
|
|
public final static int STATUS_FAILED_DELETED = 100;
|
|
|
|
|
big ol' update to strip out the singletons, replacing them with
a rooted app context. The core itself has its own I2PAppContext
(see its javadoc for, uh, docs), and the router extends that to
expose the router's singletons. The main point of this is to
make it so that we can run multiple routers in the same JVM, even
to allow different apps in the same JVM to switch singleton
implementations (e.g. run some routers with one set of profile
calculators, and other routers with a different one).
There is still some work to be done regarding the actual boot up
of multiple routers in a JVM, as well as their configuration,
though the plan is to have the RouterContext override the
I2PAppContext's getProperty/getPropertyNames methods to read from
a config file (seperate ones per context) instead of using the
System.getProperty that the base I2PAppContext uses.
Once the multi-router is working, i'll shim in a VMCommSystem
that doesn't depend upon sockets or threads to read/write (and
that uses configurable message send delays / disconnects / etc,
perhaps using data from the routerContext.getProperty to drive it).
I could hold off until the sim is all working, but there's a
truckload of changes in here and I hate dealing with conflicts ;)
Everything works - I've been running 'er for a while and kicked
the tires a bit, but if you see something amiss, please let me
know.
2004-04-24 11:54:35 +00:00
|
|
|
public TunnelCreateStatusMessage(I2PAppContext context) {
|
|
|
|
super(context);
|
|
|
|
setTunnelId(null);
|
|
|
|
setStatus(-1);
|
|
|
|
setFromHash(null);
|
2004-04-08 04:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public TunnelId getTunnelId() { return _tunnelId; }
|
2004-10-08 02:08:10 +00:00
|
|
|
public void setTunnelId(TunnelId id) {
|
|
|
|
_tunnelId = id;
|
|
|
|
if ( (id != null) && (id.getTunnelId() <= 0) )
|
|
|
|
throw new IllegalArgumentException("wtf, tunnelId " + id);
|
|
|
|
}
|
2004-04-08 04:41:54 +00:00
|
|
|
|
|
|
|
public int getStatus() { return _status; }
|
|
|
|
public void setStatus(int status) { _status = status; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Contains the SHA256 Hash of the RouterIdentity sending the message
|
|
|
|
*/
|
|
|
|
public Hash getFromHash() { return _from; }
|
|
|
|
public void setFromHash(Hash from) { _from = from; }
|
|
|
|
|
2004-10-08 02:08:10 +00:00
|
|
|
public void readMessage(byte data[], int offset, int dataSize, int type) throws I2NPMessageException, IOException {
|
big ol' update to strip out the singletons, replacing them with
a rooted app context. The core itself has its own I2PAppContext
(see its javadoc for, uh, docs), and the router extends that to
expose the router's singletons. The main point of this is to
make it so that we can run multiple routers in the same JVM, even
to allow different apps in the same JVM to switch singleton
implementations (e.g. run some routers with one set of profile
calculators, and other routers with a different one).
There is still some work to be done regarding the actual boot up
of multiple routers in a JVM, as well as their configuration,
though the plan is to have the RouterContext override the
I2PAppContext's getProperty/getPropertyNames methods to read from
a config file (seperate ones per context) instead of using the
System.getProperty that the base I2PAppContext uses.
Once the multi-router is working, i'll shim in a VMCommSystem
that doesn't depend upon sockets or threads to read/write (and
that uses configurable message send delays / disconnects / etc,
perhaps using data from the routerContext.getProperty to drive it).
I could hold off until the sim is all working, but there's a
truckload of changes in here and I hate dealing with conflicts ;)
Everything works - I've been running 'er for a while and kicked
the tires a bit, but if you see something amiss, please let me
know.
2004-04-24 11:54:35 +00:00
|
|
|
if (type != MESSAGE_TYPE) throw new I2NPMessageException("Message type is incorrect for this message");
|
2004-10-08 02:08:10 +00:00
|
|
|
int curIndex = offset;
|
|
|
|
|
|
|
|
_tunnelId = new TunnelId(DataHelper.fromLong(data, curIndex, 4));
|
|
|
|
curIndex += 4;
|
|
|
|
|
|
|
|
if (_tunnelId.getTunnelId() <= 0)
|
|
|
|
throw new I2NPMessageException("wtf, negative tunnelId? " + _tunnelId);
|
|
|
|
|
|
|
|
_status = (int)DataHelper.fromLong(data, curIndex, 1);
|
|
|
|
curIndex++;
|
|
|
|
byte peer[] = new byte[Hash.HASH_LENGTH];
|
|
|
|
System.arraycopy(data, curIndex, peer, 0, Hash.HASH_LENGTH);
|
|
|
|
curIndex += Hash.HASH_LENGTH;
|
|
|
|
_from = new Hash(peer);
|
2004-04-08 04:41:54 +00:00
|
|
|
}
|
|
|
|
|
2004-10-08 02:08:10 +00:00
|
|
|
|
2004-10-07 19:19:51 +00:00
|
|
|
/** calculate the message body's length (not including the header and footer */
|
|
|
|
protected int calculateWrittenLength() {
|
|
|
|
return 4 + 1 + Hash.HASH_LENGTH; // id + status + from
|
|
|
|
}
|
|
|
|
/** write the message body to the output array, starting at the given index */
|
|
|
|
protected int writeMessageBody(byte out[], int curIndex) throws I2NPMessageException {
|
big ol' update to strip out the singletons, replacing them with
a rooted app context. The core itself has its own I2PAppContext
(see its javadoc for, uh, docs), and the router extends that to
expose the router's singletons. The main point of this is to
make it so that we can run multiple routers in the same JVM, even
to allow different apps in the same JVM to switch singleton
implementations (e.g. run some routers with one set of profile
calculators, and other routers with a different one).
There is still some work to be done regarding the actual boot up
of multiple routers in a JVM, as well as their configuration,
though the plan is to have the RouterContext override the
I2PAppContext's getProperty/getPropertyNames methods to read from
a config file (seperate ones per context) instead of using the
System.getProperty that the base I2PAppContext uses.
Once the multi-router is working, i'll shim in a VMCommSystem
that doesn't depend upon sockets or threads to read/write (and
that uses configurable message send delays / disconnects / etc,
perhaps using data from the routerContext.getProperty to drive it).
I could hold off until the sim is all working, but there's a
truckload of changes in here and I hate dealing with conflicts ;)
Everything works - I've been running 'er for a while and kicked
the tires a bit, but if you see something amiss, please let me
know.
2004-04-24 11:54:35 +00:00
|
|
|
if ( (_tunnelId == null) || (_from == null) ) throw new I2NPMessageException("Not enough data to write out");
|
2004-10-08 02:08:10 +00:00
|
|
|
if (_tunnelId.getTunnelId() < 0) throw new I2NPMessageException("Negative tunnelId!? " + _tunnelId);
|
big ol' update to strip out the singletons, replacing them with
a rooted app context. The core itself has its own I2PAppContext
(see its javadoc for, uh, docs), and the router extends that to
expose the router's singletons. The main point of this is to
make it so that we can run multiple routers in the same JVM, even
to allow different apps in the same JVM to switch singleton
implementations (e.g. run some routers with one set of profile
calculators, and other routers with a different one).
There is still some work to be done regarding the actual boot up
of multiple routers in a JVM, as well as their configuration,
though the plan is to have the RouterContext override the
I2PAppContext's getProperty/getPropertyNames methods to read from
a config file (seperate ones per context) instead of using the
System.getProperty that the base I2PAppContext uses.
Once the multi-router is working, i'll shim in a VMCommSystem
that doesn't depend upon sockets or threads to read/write (and
that uses configurable message send delays / disconnects / etc,
perhaps using data from the routerContext.getProperty to drive it).
I could hold off until the sim is all working, but there's a
truckload of changes in here and I hate dealing with conflicts ;)
Everything works - I've been running 'er for a while and kicked
the tires a bit, but if you see something amiss, please let me
know.
2004-04-24 11:54:35 +00:00
|
|
|
|
2004-10-07 19:19:51 +00:00
|
|
|
byte id[] = DataHelper.toLong(4, _tunnelId.getTunnelId());
|
|
|
|
System.arraycopy(id, 0, out, curIndex, 4);
|
|
|
|
curIndex += 4;
|
|
|
|
byte status[] = DataHelper.toLong(1, _status);
|
|
|
|
out[curIndex++] = status[0];
|
|
|
|
System.arraycopy(_from.getData(), 0, out, curIndex, Hash.HASH_LENGTH);
|
|
|
|
curIndex += Hash.HASH_LENGTH;
|
|
|
|
return curIndex;
|
2004-04-08 04:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getType() { return MESSAGE_TYPE; }
|
|
|
|
|
|
|
|
public int hashCode() {
|
big ol' update to strip out the singletons, replacing them with
a rooted app context. The core itself has its own I2PAppContext
(see its javadoc for, uh, docs), and the router extends that to
expose the router's singletons. The main point of this is to
make it so that we can run multiple routers in the same JVM, even
to allow different apps in the same JVM to switch singleton
implementations (e.g. run some routers with one set of profile
calculators, and other routers with a different one).
There is still some work to be done regarding the actual boot up
of multiple routers in a JVM, as well as their configuration,
though the plan is to have the RouterContext override the
I2PAppContext's getProperty/getPropertyNames methods to read from
a config file (seperate ones per context) instead of using the
System.getProperty that the base I2PAppContext uses.
Once the multi-router is working, i'll shim in a VMCommSystem
that doesn't depend upon sockets or threads to read/write (and
that uses configurable message send delays / disconnects / etc,
perhaps using data from the routerContext.getProperty to drive it).
I could hold off until the sim is all working, but there's a
truckload of changes in here and I hate dealing with conflicts ;)
Everything works - I've been running 'er for a while and kicked
the tires a bit, but if you see something amiss, please let me
know.
2004-04-24 11:54:35 +00:00
|
|
|
return DataHelper.hashCode(getTunnelId()) +
|
|
|
|
getStatus() +
|
|
|
|
DataHelper.hashCode(getFromHash());
|
2004-04-08 04:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean equals(Object object) {
|
|
|
|
if ( (object != null) && (object instanceof TunnelCreateStatusMessage) ) {
|
|
|
|
TunnelCreateStatusMessage msg = (TunnelCreateStatusMessage)object;
|
|
|
|
return DataHelper.eq(getTunnelId(),msg.getTunnelId()) &&
|
big ol' update to strip out the singletons, replacing them with
a rooted app context. The core itself has its own I2PAppContext
(see its javadoc for, uh, docs), and the router extends that to
expose the router's singletons. The main point of this is to
make it so that we can run multiple routers in the same JVM, even
to allow different apps in the same JVM to switch singleton
implementations (e.g. run some routers with one set of profile
calculators, and other routers with a different one).
There is still some work to be done regarding the actual boot up
of multiple routers in a JVM, as well as their configuration,
though the plan is to have the RouterContext override the
I2PAppContext's getProperty/getPropertyNames methods to read from
a config file (seperate ones per context) instead of using the
System.getProperty that the base I2PAppContext uses.
Once the multi-router is working, i'll shim in a VMCommSystem
that doesn't depend upon sockets or threads to read/write (and
that uses configurable message send delays / disconnects / etc,
perhaps using data from the routerContext.getProperty to drive it).
I could hold off until the sim is all working, but there's a
truckload of changes in here and I hate dealing with conflicts ;)
Everything works - I've been running 'er for a while and kicked
the tires a bit, but if you see something amiss, please let me
know.
2004-04-24 11:54:35 +00:00
|
|
|
DataHelper.eq(getFromHash(),msg.getFromHash()) &&
|
|
|
|
(getStatus() == msg.getStatus());
|
2004-04-08 04:41:54 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
big ol' update to strip out the singletons, replacing them with
a rooted app context. The core itself has its own I2PAppContext
(see its javadoc for, uh, docs), and the router extends that to
expose the router's singletons. The main point of this is to
make it so that we can run multiple routers in the same JVM, even
to allow different apps in the same JVM to switch singleton
implementations (e.g. run some routers with one set of profile
calculators, and other routers with a different one).
There is still some work to be done regarding the actual boot up
of multiple routers in a JVM, as well as their configuration,
though the plan is to have the RouterContext override the
I2PAppContext's getProperty/getPropertyNames methods to read from
a config file (seperate ones per context) instead of using the
System.getProperty that the base I2PAppContext uses.
Once the multi-router is working, i'll shim in a VMCommSystem
that doesn't depend upon sockets or threads to read/write (and
that uses configurable message send delays / disconnects / etc,
perhaps using data from the routerContext.getProperty to drive it).
I could hold off until the sim is all working, but there's a
truckload of changes in here and I hate dealing with conflicts ;)
Everything works - I've been running 'er for a while and kicked
the tires a bit, but if you see something amiss, please let me
know.
2004-04-24 11:54:35 +00:00
|
|
|
public String toString() {
|
2004-04-08 04:41:54 +00:00
|
|
|
StringBuffer buf = new StringBuffer();
|
|
|
|
buf.append("[TunnelCreateStatusMessage: ");
|
|
|
|
buf.append("\n\tTunnel ID: ").append(getTunnelId());
|
|
|
|
buf.append("\n\tStatus: ").append(getStatus());
|
|
|
|
buf.append("\n\tFrom: ").append(getFromHash());
|
|
|
|
buf.append("]");
|
|
|
|
return buf.toString();
|
|
|
|
}
|
|
|
|
}
|