/**
   * Distribute the message. If the dest is local, it blocks until its passed to the target
   * ClientConnectionRunner (which then fires it into a MessageReceivedJob). If the dest is remote,
   * it blocks until it is added into the ClientMessagePool
   */
  MessageId distributeMessage(SendMessageMessage message) {
    Payload payload = message.getPayload();
    Destination dest = message.getDestination();
    MessageId id = new MessageId();
    id.setMessageId(getNextMessageId());
    long expiration = 0;
    int flags = 0;
    if (message.getType() == SendMessageExpiresMessage.MESSAGE_TYPE) {
      SendMessageExpiresMessage msg = (SendMessageExpiresMessage) message;
      expiration = msg.getExpirationTime();
      flags = msg.getFlags();
    }
    if (message.getNonce() != 0 && !_dontSendMSM) _acceptedPending.add(id);

    if (_log.shouldLog(Log.DEBUG))
      _log.debug(
          "** Receiving message "
              + id.getMessageId()
              + " with payload of size "
              + payload.getSize()
              + " for session "
              + _sessionId.getSessionId());
    // long beforeDistribute = _context.clock().now();
    // the following blocks as described above
    SessionConfig cfg = _config;
    if (cfg != null)
      _manager.distributeMessage(cfg.getDestination(), dest, payload, id, expiration, flags);
    // else log error?
    // long timeToDistribute = _context.clock().now() - beforeDistribute;
    // if (_log.shouldLog(Log.DEBUG))
    //    _log.warn("Time to distribute in the manager to "
    //              + dest.calculateHash().toBase64() + ": "
    //              + timeToDistribute);
    return id;
  }
Пример #2
0
  /* FIXME missing hashCode() method FIXME */
  @Override
  public boolean equals(Object object) {
    if ((object != null) && (object instanceof SessionConfig)) {
      SessionConfig cfg = (SessionConfig) object;
      return DataHelper.eq(getSignature(), cfg.getSignature())
          && DataHelper.eq(getDestination(), cfg.getDestination())
          && DataHelper.eq(getCreationDate(), cfg.getCreationDate())
          && DataHelper.eq(getOptions(), cfg.getOptions());
    }

    return false;
  }
 void sessionEstablished(SessionConfig config) {
   _destHashCache = config.getDestination().calculateHash();
   if (_log.shouldLog(Log.DEBUG))
     _log.debug("SessionEstablished called for destination " + _destHashCache.toBase64());
   _config = config;
   // We process a few options here, but most are handled by the tunnel manager.
   // The ones here can't be changed later.
   Properties opts = config.getOptions();
   if (opts != null) {
     _dontSendMSM =
         "none".equals(opts.getProperty(I2PClient.PROP_RELIABILITY, "").toLowerCase(Locale.US));
     _dontSendMSMOnReceive = Boolean.parseBoolean(opts.getProperty(I2PClient.PROP_FAST_RECEIVE));
   }
   // per-destination session key manager to prevent rather easy correlation
   if (_sessionKeyManager == null) {
     int tags = TransientSessionKeyManager.DEFAULT_TAGS;
     int thresh = TransientSessionKeyManager.LOW_THRESHOLD;
     if (opts != null) {
       String ptags = opts.getProperty(PROP_TAGS);
       if (ptags != null) {
         try {
           tags = Integer.parseInt(ptags);
         } catch (NumberFormatException nfe) {
         }
       }
       String pthresh = opts.getProperty(PROP_THRESH);
       if (pthresh != null) {
         try {
           thresh = Integer.parseInt(pthresh);
         } catch (NumberFormatException nfe) {
         }
       }
     }
     _sessionKeyManager = new TransientSessionKeyManager(_context, tags, thresh);
   } else {
     _log.error(
         "SessionEstablished called for twice for destination "
             + _destHashCache.toBase64().substring(0, 4));
   }
   _manager.destinationEstablished(this);
 }