Changeset a93666c


Ignore:
Timestamp:
May 14, 2014 1:49:42 PM (7 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
8371b8f
Parents:
dbb7eb3
Message:
  • I2CP: Prep for per-message reliability settings (ticket #788) Router side:

Store message nonce in ClientMessage?, so we may send
a MessageStatusMessage? with a failure code to the client
without sending an ACCEPTED MessageStatusMessage? first.
All MessageStatusMessages? sent in response to outbound messages will now have a valid nonce.

Location:
router/java/src/net/i2p/router
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/ClientManagerFacade.java

    rdbb7eb3 ra93666c  
    7171
    7272    /**
     73     *  @param id the router's ID for this message
     74     *  @param messageNonce the client's ID for this message
    7375     *  @param status see I2CP MessageStatusMessage for success/failure codes
    7476     */
    75     public abstract void messageDeliveryStatusUpdate(Destination fromDest, MessageId id, int status);
     77    public abstract void messageDeliveryStatusUpdate(Destination fromDest, MessageId id,
     78                                                     long messageNonce, int status);
    7679   
    7780    public abstract void messageReceived(ClientMessage msg);
  • router/java/src/net/i2p/router/ClientMessage.java

    rdbb7eb3 ra93666c  
    3030    private final Hash _destinationHash;
    3131    private final MessageId _messageId;
     32    private final long _messageNonce;
    3233    private final long _expiration;
    3334    /** only for outbound messages */
     
    3637    /**
    3738     *  For outbound (locally originated)
     39     *  @param msgID the router's ID for this message
     40     *  @param messageNonce the client's ID for this message
    3841     *  @since 0.9.9
    3942     */
    4043    public ClientMessage(Destination toDest, Payload payload, SessionConfig config, Destination fromDest,
    41                          MessageId msgID, long expiration, int flags) {
     44                         MessageId msgID, long messageNonce, long expiration, int flags) {
    4245        _destination = toDest;
    4346        _destinationHash = null;
     
    4649        _fromDestination = fromDest;
    4750        _messageId = msgID;
     51        _messageNonce = messageNonce;
    4852        _expiration = expiration;
    4953        _flags = flags;
     
    6165        _fromDestination = null;
    6266        _messageId = null;
     67        _messageNonce = 0;
    6368        _expiration = 0;
    6469        _flags = 0;
     
    96101   
    97102    /**
     103     * Valid for outbound; 0 for inbound.
     104     * @since 0.9.14
     105     */
     106    public long getMessageNonce() { return _messageNonce; }
     107   
     108    /**
    98109     * Retrieve the information regarding how the router received this message.  Only
    99110     * messages received from the network will have this information, not locally
  • router/java/src/net/i2p/router/client/ClientConnectionRunner.java

    rdbb7eb3 ra93666c  
    6767    private SessionConfig _config;
    6868    private String _clientVersion;
    69     /** static mapping of MessageId to Payload, storing messages for retrieval */
     69    /**
     70     *  Mapping of MessageId to Payload, storing messages for retrieval.
     71     *  Unused for i2cp.fastReceive = "true" (_dontSendMSMOnRecive = true)
     72     */
    7073    private final Map<MessageId, Payload> _messages;
    7174    /** lease set request state, or null if there is no request pending on at the moment */
     
    7477    /** currently allocated leaseSet, or null if none is allocated */
    7578    private LeaseSet _currentLeaseSet;
    76     /** set of messageIds created but not yet ACCEPTED */
     79    /**
     80     *  Set of messageIds created but not yet ACCEPTED.
     81     *  Unused for i2cp.messageReliability = "none" (_dontSendMSM = true)
     82     */
    7783    private final Set<MessageId> _acceptedPending;
    7884    /** thingy that does stuff */
     
    324330     *  Do not use for status = STATUS_SEND_ACCEPTED; use ackSendMessage() for that.
    325331     *
     332     *  @param id the router's ID for this message
     333     *  @param messageNonce the client's ID for this message
    326334     *  @param status see I2CP MessageStatusMessage for success/failure codes
    327335     */
    328     void updateMessageDeliveryStatus(MessageId id, int status) {
    329         if (_dead || _dontSendMSM)
     336    void updateMessageDeliveryStatus(MessageId id, long messageNonce, int status) {
     337        if (_dead || messageNonce <= 0)
    330338            return;
    331         _context.jobQueue().addJob(new MessageDeliveryStatusUpdate(id, status));
     339        _context.jobQueue().addJob(new MessageDeliveryStatusUpdate(id, messageNonce, status));
    332340    }
    333341
     
    415423            flags = msg.getFlags();
    416424        }
    417         if (message.getNonce() != 0 && !_dontSendMSM)
     425        if ((!_dontSendMSM) && message.getNonce() != 0)
    418426            _acceptedPending.add(id);
    419427
     
    425433        SessionConfig cfg = _config;
    426434        if (cfg != null)
    427             _manager.distributeMessage(cfg.getDestination(), dest, payload, id, expiration, flags);
     435            _manager.distributeMessage(cfg.getDestination(), dest, payload,
     436                                       id, message.getNonce(), expiration, flags);
    428437        // else log error?
    429438        //long timeToDistribute = _context.clock().now() - beforeDistribute;
     
    688697    private class MessageDeliveryStatusUpdate extends JobImpl {
    689698        private final MessageId _messageId;
     699        private final long _messageNonce;
    690700        private final int _status;
    691701        private long _lastTried;
     
    695705         *  Do not use for status = STATUS_SEND_ACCEPTED; use ackSendMessage() for that.
    696706         *
     707         *  @param id the router's ID for this message
     708         *  @param messageNonce the client's ID for this message
    697709         *  @param status see I2CP MessageStatusMessage for success/failure codes
    698710         */
    699         public MessageDeliveryStatusUpdate(MessageId id, int status) {
     711        public MessageDeliveryStatusUpdate(MessageId id, long messageNonce, int status) {
    700712            super(ClientConnectionRunner.this._context);
    701713            _messageId = id;
     714            _messageNonce = messageNonce;
    702715            _status = status;
    703716        }
     
    715728            msg.setSessionId(_sessionId.getSessionId());
    716729            // has to be >= 0, it is initialized to -1
    717             msg.setNonce(2);
     730            msg.setNonce(_messageNonce);
    718731            msg.setSize(0);
    719732            msg.setStatus(_status);
  • router/java/src/net/i2p/router/client/ClientManager.java

    rdbb7eb3 ra93666c  
    266266    /**
    267267     * Distribute message to a local or remote destination.
     268     * @param msgId the router's ID for this message
     269     * @param messageNonce the client's ID for this message
    268270     * @param flags ignored for local
    269271     */
    270     void distributeMessage(Destination fromDest, Destination toDest, Payload payload, MessageId msgId, long expiration, int flags) {
     272    void distributeMessage(Destination fromDest, Destination toDest, Payload payload,
     273                           MessageId msgId, long messageNonce, long expiration, int flags) {
    271274        // check if there is a runner for it
    272275        ClientConnectionRunner runner = getRunner(toDest);
     
    280283            }
    281284            // TODO can we just run this inline instead?
    282             _ctx.jobQueue().addJob(new DistributeLocal(toDest, runner, sender, fromDest, payload, msgId));
     285            _ctx.jobQueue().addJob(new DistributeLocal(toDest, runner, sender, fromDest, payload, msgId, messageNonce));
    283286        } else {
    284287            // remote.  w00t
     
    292295            ClientMessage msg = new ClientMessage(toDest, payload, runner.getConfig(),
    293296                                                  runner.getConfig().getDestination(), msgId,
    294                                                   expiration, flags);
     297                                                  messageNonce, expiration, flags);
    295298            _ctx.clientMessagePool().add(msg, true);
    296299        }
     
    304307        private final Payload _payload;
    305308        private final MessageId _msgId;
     309        private final long _messageNonce;
    306310       
    307         public DistributeLocal(Destination toDest, ClientConnectionRunner to, ClientConnectionRunner from, Destination fromDest, Payload payload, MessageId id) {
     311        /**
     312         * @param msgId the router's ID for this message
     313         * @param messageNonce the client's ID for this message
     314         */
     315        public DistributeLocal(Destination toDest, ClientConnectionRunner to, ClientConnectionRunner from,
     316                               Destination fromDest, Payload payload, MessageId id, long messageNonce) {
    308317            super(_ctx);
    309318            _toDest = toDest;
     
    313322            _payload = payload;
    314323            _msgId = id;
     324            _messageNonce = messageNonce;
    315325        }
    316326
     
    320330            _to.receiveMessage(_toDest, _fromDest, _payload);
    321331            if (_from != null) {
    322                 _from.updateMessageDeliveryStatus(_msgId, MessageStatusMessage.STATUS_SEND_SUCCESS_LOCAL);
     332                _from.updateMessageDeliveryStatus(_msgId, _messageNonce, MessageStatusMessage.STATUS_SEND_SUCCESS_LOCAL);
    323333            }
    324334        }
     
    438448   
    439449    /**
     450     *  @param id the router's ID for this message
     451     *  @param messageNonce the client's ID for this message
    440452     *  @param status see I2CP MessageStatusMessage for success/failure codes
    441453     */
    442     public void messageDeliveryStatusUpdate(Destination fromDest, MessageId id, int status) {
     454    public void messageDeliveryStatusUpdate(Destination fromDest, MessageId id, long messageNonce, int status) {
    443455        ClientConnectionRunner runner = getRunner(fromDest);
    444456        if (runner != null) {
     
    446458                _log.debug("Delivering status " + status + " to "
    447459                           + fromDest.calculateHash() + " for message " + id);
    448             runner.updateMessageDeliveryStatus(id, status);
     460            runner.updateMessageDeliveryStatus(id, messageNonce, status);
    449461        } else {
    450462            if (_log.shouldLog(Log.WARN))
  • router/java/src/net/i2p/router/client/ClientManagerFacadeImpl.java

    rdbb7eb3 ra93666c  
    180180   
    181181    /**
     182     *  @param id the router's ID for this message
     183     *  @param messageNonce the client's ID for this message
    182184     *  @param status see I2CP MessageStatusMessage for success/failure codes
    183185     */
    184     public void messageDeliveryStatusUpdate(Destination fromDest, MessageId id, int status) {
    185         if (_manager != null)
    186             _manager.messageDeliveryStatusUpdate(fromDest, id, status);
     186    public void messageDeliveryStatusUpdate(Destination fromDest, MessageId id, long messageNonce, int status) {
     187        if (_manager != null)
     188            _manager.messageDeliveryStatusUpdate(fromDest, id, messageNonce, status);
    187189        else
    188190            _log.error("Null manager on messageDeliveryStatusUpdate!");
  • router/java/src/net/i2p/router/dummy/DummyClientManagerFacade.java

    rdbb7eb3 ra93666c  
    4444    public void restart() {}
    4545   
    46     public void messageDeliveryStatusUpdate(Destination fromDest, MessageId id, int status) {}
     46    public void messageDeliveryStatusUpdate(Destination fromDest, MessageId id, long msgNonce, int status) {}
    4747   
    4848    public SessionConfig getClientSessionConfig(Destination _dest) { return null; }
  • router/java/src/net/i2p/router/message/OutboundClientMessageOneShotJob.java

    rdbb7eb3 ra93666c  
    770770        clearCaches();
    771771        getContext().messageHistory().sendPayloadMessage(_clientMessageId.getMessageId(), false, sendTime);
    772         getContext().clientManager().messageDeliveryStatusUpdate(_from, _clientMessageId, status);
     772        getContext().clientManager().messageDeliveryStatusUpdate(_from, _clientMessageId,
     773                                                                 _clientMessage.getMessageNonce(), status);
    773774        getContext().statManager().updateFrequency("client.sendMessageFailFrequency");
    774775    }
     
    918919            //long dataMsgId = _cloveId;   // fake ID 99999
    919920            getContext().messageHistory().sendPayloadMessage(99999, true, sendTime);
    920             getContext().clientManager().messageDeliveryStatusUpdate(_from, _clientMessageId,
     921            getContext().clientManager().messageDeliveryStatusUpdate(_from, _clientMessageId, _clientMessage.getMessageNonce(),
    921922                                                                     MessageStatusMessage.STATUS_SEND_GUARANTEED_SUCCESS);
    922923            // unused
Note: See TracChangeset for help on using the changeset viewer.