Changeset f679ef2


Ignore:
Timestamp:
Jan 14, 2011 5:12:44 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
394dd3c
Parents:
c92a885
Message:

stub out flags support in I2CP SMES

Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/client/I2CPMessageProducer.java

    rc92a885 rf679ef2  
    131131    public void sendMessage(I2PSessionImpl session, Destination dest, long nonce, byte[] payload, SessionTag tag,
    132132                            SessionKey key, Set tags, SessionKey newKey, long expires) throws I2PSessionException {
     133        sendMessage(session, dest, nonce, payload, expires, 0);
     134    }
     135
     136    /**
     137     * Package up and send the payload to the router for delivery
     138     * @since 0.8.4
     139     */
     140    public void sendMessage(I2PSessionImpl session, Destination dest, long nonce, byte[] payload,
     141                            long expires, int flags) throws I2PSessionException {
     142
    133143        if (!updateBps(payload.length, expires))
    134144            // drop the message... send fail notification?
    135145            return;
    136146        SendMessageMessage msg;
    137         if (expires > 0) {
    138             msg = new SendMessageExpiresMessage();
    139             ((SendMessageExpiresMessage)msg).setExpiration(new Date(expires));
     147        if (expires > 0 || flags > 0) {
     148            SendMessageExpiresMessage smsg = new SendMessageExpiresMessage();
     149            smsg.setExpiration(expires);
     150            smsg.setFlags(flags);
     151            msg = smsg;
    140152        } else
    141153            msg = new SendMessageMessage();
     
    143155        msg.setSessionId(session.getSessionId());
    144156        msg.setNonce(nonce);
    145         Payload data = createPayload(dest, payload, tag, key, tags, newKey);
     157        Payload data = createPayload(dest, payload, null, null, null, null);
    146158        msg.setPayload(data);
    147159        session.sendMessage(msg);
  • core/java/src/net/i2p/client/I2PSession.java

    rc92a885 rf679ef2  
    2222 * <p>Define the standard means of sending and receiving messages on the
    2323 * I2P network by using the I2CP (the client protocol).  This is done over a
    24  * bidirectional TCP socket and never sends any private keys - all end to end
    25  * encryption is done transparently within the client's I2PSession
    26  * itself.  Periodically the router will ask the client to authorize a new set of
     24 * bidirectional TCP socket and never sends any private keys.
     25 *
     26 * End to end encryption in I2PSession was disabled in release 0.6.
     27 *
     28 * Periodically the router will ask the client to authorize a new set of
    2729 * tunnels to be allocated to the client, which the client can accept by sending a
    2830 * {@link net.i2p.data.LeaseSet} signed by the {@link net.i2p.data.Destination}. 
    29  * In addition, the router may on occation provide the client with an updated
     31 * In addition, the router may on occasion provide the client with an updated
    3032 * clock offset so that the client can stay in sync with the network (even if
    3133 * the host computer's clock is off).</p>
     
    3335 */
    3436public interface I2PSession {
     37
    3538    /** Send a new message to the given destination, containing the specified
    3639     * payload, returning true if the router feels confident that the message
     
    4144     */
    4245    public boolean sendMessage(Destination dest, byte[] payload) throws I2PSessionException;
     46
    4347    public boolean sendMessage(Destination dest, byte[] payload, int offset, int size) throws I2PSessionException;
    44     /** See I2PSessionMuxedImpl for details */
     48
     49    /**
     50     * See I2PSessionMuxedImpl for proto/port details.
     51     * @since 0.7.1
     52     */
    4553    public boolean sendMessage(Destination dest, byte[] payload, int proto, int fromport, int toport) throws I2PSessionException;
    4654
    4755    /**
     56     * End-to-End Crypto is disabled, tags and keys are ignored!
     57     *
    4858     * Like sendMessage above, except the key used and the tags sent are exposed to the
    4959     * application.  <p />
     
    6373     * @param dest location to send the message
    6474     * @param payload body of the message to be sent (unencrypted)
    65      * @param keyUsed session key delivered to the destination for association with the tags sent.  This is essentially
     75     * @param keyUsed UNUSED, IGNORED. Session key delivered to the destination for association with the tags sent.  This is essentially
    6676     *                an output parameter - keyUsed.getData() is ignored during this call, but after the call completes,
    6777     *                it will be filled with the bytes of the session key delivered.  Typically the key delivered is the
    6878     *                same one as the key encrypted with, but not always.  If this is null then the key data will not be
    6979     *                exposed.
    70      * @param tagsSent set of tags delivered to the peer and associated with the keyUsed.  This is also an output parameter -
     80     * @param tagsSent UNUSED, IGNORED. Set of tags delivered to the peer and associated with the keyUsed.  This is also an output parameter -
    7181     *                 the contents of the set is ignored during the call, but afterwards it contains a set of SessionTag
    7282     *                 objects that were sent along side the given keyUsed.
    7383     */
    7484    public boolean sendMessage(Destination dest, byte[] payload, SessionKey keyUsed, Set tagsSent) throws I2PSessionException;
     85
     86    /**
     87     * End-to-End Crypto is disabled, tags and keys are ignored.
     88     * @param keyUsed UNUSED, IGNORED.
     89     * @param tagsSent UNUSED, IGNORED.
     90     */
    7591    public boolean sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set tagsSent) throws I2PSessionException;
     92
     93    /**
     94     * End-to-End Crypto is disabled, tags and keys are ignored.
     95     * @param keyUsed UNUSED, IGNORED.
     96     * @param tagsSent UNUSED, IGNORED.
     97     * @since 0.7.1
     98     */
    7699    public boolean sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set tagsSent, long expire) throws I2PSessionException;
    77     /** See I2PSessionMuxedImpl for details */
     100
     101    /**
     102     * See I2PSessionMuxedImpl for proto/port details.
     103     * End-to-End Crypto is disabled, tags and keys are ignored.
     104     * @param keyUsed UNUSED, IGNORED.
     105     * @param tagsSent UNUSED, IGNORED.
     106     * @since 0.7.1
     107     */
    78108    public boolean sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set tagsSent,
    79109                               int proto, int fromport, int toport) throws I2PSessionException;
    80     /** See I2PSessionMuxedImpl for details */
     110
     111    /**
     112     * See I2PSessionMuxedImpl for proto/port details.
     113     * End-to-End Crypto is disabled, tags and keys are ignored.
     114     * @param keyUsed UNUSED, IGNORED.
     115     * @param tagsSent UNUSED, IGNORED.
     116     * @since 0.7.1
     117     */
    81118    public boolean sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set tagsSent, long expire,
    82119                               int proto, int fromport, int toport) throws I2PSessionException;
     120
     121    /**
     122     * See I2PSessionMuxedImpl for proto/port details.
     123     * End-to-End Crypto is disabled, tags and keys are ignored.
     124     * @param keyUsed UNUSED, IGNORED.
     125     * @param tagsSent UNUSED, IGNORED.
     126     * @since 0.8.4
     127     */
     128    public boolean sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set tagsSent, long expire,
     129                               int proto, int fromport, int toport, int flags) throws I2PSessionException;
    83130
    84131    /** Receive a message that the router has notified the client about, returning
     
    162209    /**
    163210     * Get the current bandwidth limits. Blocking.
     211     * @since 0.8.3
    164212     */
    165213    public int[] bandwidthLimits() throws I2PSessionException;
  • core/java/src/net/i2p/client/I2PSessionImpl.java

    rc92a885 rf679ef2  
    439439    }
    440440
    441     /**
    442      * Send the data to the destination. 
    443      * TODO: this currently always returns true, regardless of whether the message was
    444      * delivered successfully.  make this wait for at least ACCEPTED
    445      *
    446      */
    447     public abstract boolean sendMessage(Destination dest, byte[] payload) throws I2PSessionException;
    448    
    449     /**
    450      * @param keyUsed unused - no end-to-end crypto
    451      * @param tagsSent unused - no end-to-end crypto
    452      */
    453     public abstract boolean sendMessage(Destination dest, byte[] payload, SessionKey keyUsed,
    454                                         Set tagsSent) throws I2PSessionException;
    455 
    456441    public abstract void receiveStatus(int msgId, long nonce, int status);
    457442
  • core/java/src/net/i2p/client/I2PSessionImpl2.java

    rc92a885 rf679ef2  
    131131        throw new IllegalArgumentException("Use MuxedImpl");
    132132    }
     133    public boolean sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set tagsSent, long expire,
     134                               int proto, int fromport, int toport, int flags) throws I2PSessionException {
     135        throw new IllegalArgumentException("Use MuxedImpl");
     136    }
    133137
    134138    @Override
     
    223227
    224228    /**
     229     * @param keyUsed unused - no end-to-end crypto
     230     * @param tagsSent unused - no end-to-end crypto
     231     */
     232    protected boolean sendBestEffort(Destination dest, byte payload[], SessionKey keyUsed, Set tagsSent, long expires)
     233                    throws I2PSessionException {
     234        return sendBestEffort(dest, payload, expires, 0);
     235    }
     236
     237    /**
    225238     * TODO - Don't need to save MessageState since actuallyWait is false...
    226239     * But for now just use sendNoEffort() instead.
    227240     *
    228      * @param keyUsed unused - no end-to-end crypto
    229      * @param tagsSent unused - no end-to-end crypto
    230      */
    231     protected boolean sendBestEffort(Destination dest, byte payload[], SessionKey keyUsed, Set tagsSent, long expires)
     241     * @param flags to be passed to the router
     242     * @since 0.8.4
     243     */
     244    protected boolean sendBestEffort(Destination dest, byte payload[], long expires, int flags)
    232245                    throws I2PSessionException {
    233246        //SessionKey key = null;
     
    325338                       + " add took " + (afterSendingSync-inSendingSync));
    326339        //_producer.sendMessage(this, dest, nonce, payload, tag, key, sentTags, newKey, expires);
    327         _producer.sendMessage(this, dest, nonce, payload, null, null, null, null, expires);
     340        _producer.sendMessage(this, dest, nonce, payload, expires, flags);
    328341       
    329342        // since this is 'best effort', all we're waiting for is a status update
  • core/java/src/net/i2p/client/I2PSessionMuxedImpl.java

    rc92a885 rf679ef2  
    163163     *  @param fromPort 1-65535 or 0 for unset
    164164     *  @param toPort 1-65535 or 0 for unset
     165     *  @since 0.7.1
    165166     */
    166167    @Override
     
    168169                               SessionKey keyUsed, Set tagsSent, long expires,
    169170                               int proto, int fromPort, int toPort)
     171                   throws I2PSessionException {
     172        return sendMessage(dest, payload, offset, size, keyUsed, tagsSent, 0, proto, fromPort, toPort, 0);
     173    }
     174
     175    /**
     176     *  @param keyUsed unused - no end-to-end crypto
     177     *  @param tagsSent unused - no end-to-end crypto
     178     *  @param proto 1-254 or 0 for unset; recommended:
     179     *         I2PSession.PROTO_UNSPECIFIED
     180     *         I2PSession.PROTO_STREAMING
     181     *         I2PSession.PROTO_DATAGRAM
     182     *         255 disallowed
     183     *  @param fromPort 1-65535 or 0 for unset
     184     *  @param toPort 1-65535 or 0 for unset
     185     *  @param flags to be passed to the router
     186     *  @since 0.8.4
     187     */
     188    @Override
     189    public boolean sendMessage(Destination dest, byte[] payload, int offset, int size,
     190                               SessionKey keyUsed, Set tagsSent, long expires,
     191                               int proto, int fromPort, int toPort, int flags)
    170192                   throws I2PSessionException {
    171193        if (isClosed()) throw new I2PSessionException("Already closed");
     
    184206        _context.statManager().addRateData("i2cp.tx.msgCompressed", payload.length, 0);
    185207        _context.statManager().addRateData("i2cp.tx.msgExpanded", size, 0);
    186         return sendBestEffort(dest, payload, keyUsed, tagsSent, expires);
     208        return sendBestEffort(dest, payload, expires, flags);
    187209    }
    188210
  • core/java/src/net/i2p/data/i2cp/SendMessageExpiresMessage.java

    rc92a885 rf679ef2  
    1717import net.i2p.data.DataFormatException;
    1818import net.i2p.data.DataHelper;
     19import net.i2p.data.DateAndFlags;
    1920import net.i2p.data.Destination;
    2021import net.i2p.data.Payload;
     
    2324 * Same as SendMessageMessage, but with an expiration to be passed to the router
    2425 *
     26 * As of 0.8.4, retrofitted to use DateAndFlags. Backwards compatible.
     27 *
    2528 * @author zzz
    2629 */
     
    2831    /* FIXME hides another field FIXME */
    2932    public final static int MESSAGE_TYPE = 36;
    30     private SessionId _sessionId;
    31     private Destination _destination;
    32     private Payload _payload;
    33     private Date _expiration;
     33    private final DateAndFlags _daf;
    3434
    3535    public SendMessageExpiresMessage() {
    3636        super();
     37        _daf = new DateAndFlags();
    3738    }
    3839
     40    /**
     41     *  The Date object is created here, it is not cached.
     42     *  Use getExpirationTime() if you only need the long value.
     43     */
    3944    public Date getExpiration() {
    40         return _expiration;
     45        return _daf.getDate();
     46    }
     47
     48    /**
     49     *  Use this instead of getExpiration().getTime()
     50     *  @since 0.8.4
     51     */
     52    public long getExpirationTime() {
     53        return _daf.getTime();
    4154    }
    4255
    4356    public void setExpiration(Date d) {
    44         _expiration = d;
     57        _daf.setDate(d);
     58    }
     59
     60    /**
     61     *  @since 0.8.4
     62     */
     63    public void setExpiration(long d) {
     64        _daf.setDate(d);
     65    }
     66
     67    /**
     68     *  @since 0.8.4
     69     */
     70    public int getFlags() {
     71        return _daf.getFlags();
     72    }
     73
     74    /**
     75     *  @since 0.8.4
     76     */
     77    public void setFlags(int f) {
     78        _daf.setFlags(f);
    4579    }
    4680
     
    5589
    5690        try {
    57             _expiration = DataHelper.readDate(in);
     91            _daf.readBytes(in);
    5892        } catch (DataFormatException dfe) {
    5993            throw new I2CPMessageException("Unable to load the message data", dfe);
     
    69103    @Override
    70104    public void writeMessage(OutputStream out) throws I2CPMessageException, IOException {
    71         if ((getSessionId() == null) || (getDestination() == null) || (getPayload() == null) || (getNonce() <= 0) || (_expiration == null))
     105        if ((getSessionId() == null) || (getDestination() == null) || (getPayload() == null) || (getNonce() <= 0))
    72106            throw new I2CPMessageException("Unable to write out the message as there is not enough data");
    73107        int len = 2 + getDestination().size() + getPayload().getSize() + 4 + 4 + DataHelper.DATE_LENGTH;
     
    80114            getPayload().writeBytes(out);
    81115            DataHelper.writeLong(out, 4, getNonce());
    82             DataHelper.writeDate(out, _expiration);
     116            _daf.writeBytes(out);
    83117        } catch (DataFormatException dfe) {
    84118            throw new I2CPMessageException("Error writing the msg", dfe);
     
    97131            SendMessageExpiresMessage msg = (SendMessageExpiresMessage) object;
    98132            return super.equals(object)
    99                    && DataHelper.eq(getExpiration(), msg.getExpiration());
     133                   && _daf.equals(msg._daf);
    100134        }
    101135         
  • router/java/src/net/i2p/router/ClientMessage.java

    rc92a885 rf679ef2  
    2929    private MessageId _messageId;
    3030    private long _expiration;
     31    /** only for outbound messages */
     32    private int _flags;
    3133   
    3234    public ClientMessage() {
    33         setPayload(null);
    34         setDestination(null);
    35         setFromDestination(null);
    36         setReceptionInfo(null);
    37         setSenderConfig(null);
    38         setDestinationHash(null);
    39         setMessageId(null);
    40         setExpiration(0);
    4135    }
    4236   
     
    10296    public long getExpiration() { return _expiration; }
    10397    public void setExpiration(long e) { _expiration = e; }
     98
     99    /**
     100     * Flags requested by the client that sent the message.  This will only be available
     101     * for locally originated messages.
     102     *
     103     * @since 0.8.4
     104     */
     105    public int getFlags() { return _flags; }
     106
     107    /**
     108     * @since 0.8.4
     109     */
     110    public void setFlags(int f) { _flags = f; }
    104111}
  • router/java/src/net/i2p/router/client/ClientConnectionRunner.java

    rc92a885 rf679ef2  
    281281        id.setMessageId(getNextMessageId());
    282282        long expiration = 0;
    283         if (message instanceof SendMessageExpiresMessage)
    284             expiration = ((SendMessageExpiresMessage) message).getExpiration().getTime();
     283        int flags = 0;
     284        if (message.getType() == SendMessageExpiresMessage.MESSAGE_TYPE) {
     285            SendMessageExpiresMessage msg = (SendMessageExpiresMessage) message;
     286            expiration = msg.getExpirationTime();
     287            flags = msg.getFlags();
     288        }
    285289        if (!_dontSendMSM)
    286290            _acceptedPending.add(id);
     
    290294                       + payload.getSize() + "]" + " for session [" + _sessionId.getSessionId()
    291295                       + "]");
    292         long beforeDistribute = _context.clock().now();
     296        //long beforeDistribute = _context.clock().now();
    293297        // the following blocks as described above
    294298        SessionConfig cfg = _config;
    295299        if (cfg != null)
    296             _manager.distributeMessage(cfg.getDestination(), dest, payload, id, expiration);
    297         long timeToDistribute = _context.clock().now() - beforeDistribute;
    298         if (_log.shouldLog(Log.DEBUG))
    299             _log.warn("Time to distribute in the manager to "
    300                       + dest.calculateHash().toBase64() + ": "
    301                       + timeToDistribute);
     300            _manager.distributeMessage(cfg.getDestination(), dest, payload, id, expiration, flags);
     301        // else log error?
     302        //long timeToDistribute = _context.clock().now() - beforeDistribute;
     303        //if (_log.shouldLog(Log.DEBUG))
     304        //    _log.warn("Time to distribute in the manager to "
     305        //              + dest.calculateHash().toBase64() + ": "
     306        //              + timeToDistribute);
    302307        return id;
    303308    }
  • router/java/src/net/i2p/router/client/ClientManager.java

    rc92a885 rf679ef2  
    194194    }
    195195   
    196     void distributeMessage(Destination fromDest, Destination toDest, Payload payload, MessageId msgId, long expiration) {
     196    /**
     197     * Distribute message to a local or remote destination.
     198     * @param flags ignored for local
     199     */
     200    void distributeMessage(Destination fromDest, Destination toDest, Payload payload, MessageId msgId, long expiration, int flags) {
    197201        // check if there is a runner for it
    198202        ClientConnectionRunner runner = getRunner(toDest);
     
    205209                return;
    206210            }
     211            // TODO can we just run this inline instead?
    207212            _ctx.jobQueue().addJob(new DistributeLocal(toDest, runner, sender, fromDest, payload, msgId));
    208213        } else {
     
    218223            msg.setDestination(toDest);
    219224            msg.setPayload(payload);
    220             msg.setReceptionInfo(null);
    221225            msg.setSenderConfig(runner.getConfig());
    222226            msg.setFromDestination(runner.getConfig().getDestination());
    223227            msg.setMessageId(msgId);
    224228            msg.setExpiration(expiration);
     229            msg.setFlags(flags);
    225230            _ctx.clientMessagePool().add(msg, true);
    226231        }
     
    228233   
    229234    private class DistributeLocal extends JobImpl {
    230         private Destination _toDest;
    231         private ClientConnectionRunner _to;
    232         private ClientConnectionRunner _from;
    233         private Destination _fromDest;
    234         private Payload _payload;
    235         private MessageId _msgId;
     235        private final Destination _toDest;
     236        private final ClientConnectionRunner _to;
     237        private final ClientConnectionRunner _from;
     238        private final Destination _fromDest;
     239        private final Payload _payload;
     240        private final MessageId _msgId;
    236241       
    237242        public DistributeLocal(Destination toDest, ClientConnectionRunner to, ClientConnectionRunner from, Destination fromDest, Payload payload, MessageId id) {
  • router/java/src/net/i2p/router/message/OutboundClientMessageOneShotJob.java

    rc92a885 rf679ef2  
    4848 */
    4949public class OutboundClientMessageOneShotJob extends JobImpl {
    50     private Log _log;
     50    private final Log _log;
    5151    private long _overallExpiration;
    5252    private ClientMessage _clientMessage;
    53     private MessageId _clientMessageId;
    54     private int _clientMessageSize;
    55     private Destination _from;
    56     private Destination _to;
    57     private String _toString;
     53    private final MessageId _clientMessageId;
     54    private final int _clientMessageSize;
     55    private final Destination _from;
     56    private final Destination _to;
     57    private final String _toString;
    5858    /** target destination's leaseSet, if known */
    5959    private LeaseSet _leaseSet;
     
    6262    private PayloadGarlicConfig _clove;
    6363    private long _cloveId;
    64     private long _start;
     64    private final long _start;
    6565    private boolean _finished;
    6666    private long _leaseSetLookupBegin;
Note: See TracChangeset for help on using the changeset viewer.