net.i2p.router.message

## Class GarlicMessageBuilder

- java.lang.Object
- - net.i2p.router.message.GarlicMessageBuilder

-     public class GarlicMessageBuilder
      extends Object

  Build garlic messages based on a GarlicConfig

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `GarlicMessageBuilder()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static GarlicMessage` | `buildECIESMessage(RouterContext ctx, GarlicConfig config)` Encrypt from an anonymous source.
    `(package private) static GarlicMessage` | `buildECIESMessage(RouterContext ctx, GarlicConfig config, Hash from, Destination to, SessionKeyManager skm, ReplyCallback callback)` ECIES_X25519 and PQ only.
    `static GarlicMessage` | `buildMessage(RouterContext ctx, GarlicConfig config, SessionKey encryptKey, RatchetSessionTag encryptTag)` Ratchet only.
    `static GarlicMessage` | `buildMessage(RouterContext ctx, GarlicConfig config, SessionKey wrappedKey, Set<SessionTag> wrappedTags, int numTagsToDeliver, int lowTagsThreshold, SessionKeyManager skm)` ELGAMAL_2048 only.
    `static GarlicMessage` | `buildMessage(RouterContext ctx, GarlicConfig config, SessionKey wrappedKey, Set<SessionTag> wrappedTags, int numTagsToDeliver, SessionKeyManager skm)` ELGAMAL_2048 only Called by OCMJH
    `static GarlicMessage` | `buildMessage(RouterContext ctx, GarlicConfig config, SessionKey wrappedKey, Set<SessionTag> wrappedTags, SessionKeyManager skm)` Now unused, since we have to generate a reply token first in OCMOSJ but we don't know if tags are required yet.
    `static GarlicMessage` | `buildMessage(RouterContext ctx, GarlicConfig config, Set<SessionTag> wrappedTags, PublicKey target, SessionKey encryptKey, SessionTag encryptTag)` ELGAMAL_2048 only.
    `(package private) static boolean` | `needsTags(RouterContext ctx, PublicKey key, Hash local, int minTagOverride)` ELGAMAL_2048 only; returns false for others

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### GarlicMessageBuilder

          public GarlicMessageBuilder()

  - ### Method Detail

    - #### buildECIESMessage

          public static GarlicMessage buildECIESMessage(RouterContext ctx,
                                                        GarlicConfig config)

      Encrypt from an anonymous source. ECIES_X25519 only. PQ not supported. Called by MessageWrapper only.
      Parameters:
        `ctx` - scope
        `config` - how/what to wrap, must have key set with setRecipientPublicKey()
      Throws:
        `IllegalArgumentException` - on error

    - #### buildECIESMessage

          static GarlicMessage buildECIESMessage(RouterContext ctx,
                                                 GarlicConfig config,
                                                 Hash from,
                                                 Destination to,
                                                 SessionKeyManager skm,
                                                 ReplyCallback callback)

      ECIES_X25519 and PQ only. Called by OCMJH only.
      Parameters:
        `ctx` - scope
        `config` - how/what to wrap, must have key set with setRecipientPublicKey()
        `callback` - may be null
      Returns:
        null if expired or on other errors
      Throws:
        `IllegalArgumentException` - on error

    - #### buildMessage

          public static GarlicMessage buildMessage(RouterContext ctx,
                                                   GarlicConfig config,
                                                   SessionKey encryptKey,
                                                   RatchetSessionTag encryptTag)

      Ratchet only. Used by TestJob, and by MessageWrapper for encrypting DatabaseLookupMessages and DSM/DSRM replies.
      Parameters:
        `ctx` - scope
        `config` - how/what to wrap
        `encryptKey` - sessionKey used to encrypt the current message, non-null
        `encryptTag` - sessionTag used to encrypt the current message, non-null

    - #### buildMessage

          public static GarlicMessage buildMessage(RouterContext ctx,
                                                   GarlicConfig config,
                                                   SessionKey wrappedKey,
                                                   Set<SessionTag> wrappedTags,
                                                   int numTagsToDeliver,
                                                   int lowTagsThreshold,
                                                   SessionKeyManager skm)

      ELGAMAL_2048 only. Called by netdb and above.
      Parameters:
        `ctx` - scope
        `config` - how/what to wrap
        `wrappedKey` - non-null with null data, output parameter that will be filled with the SessionKey used
        `wrappedTags` - Output parameter that will be filled with the sessionTags used. If non-empty on return you must call skm.tagsDelivered() when sent and then call skm.tagsAcked() or skm.failTags() later.
        `numTagsToDeliver` - only if the estimated available tags are below the threshold. Set to zero to disable tag delivery. You must set to zero if you are not equipped to confirm delivery and call skm.tagsAcked() or failTags() later. If this is always 0, it forces ElGamal every time.
        `lowTagsThreshold` - the threshold
        `skm` - non-null
      Returns:
        null if expired
      Throws:
        `IllegalArgumentException` - on error

    - #### buildMessage

          public static GarlicMessage buildMessage(RouterContext ctx,
                                                   GarlicConfig config,
                                                   SessionKey wrappedKey,
                                                   Set<SessionTag> wrappedTags,
                                                   int numTagsToDeliver,
                                                   SessionKeyManager skm)

      ELGAMAL_2048 only Called by OCMJH
      Parameters:
        `ctx` - scope
        `config` - how/what to wrap
        `wrappedKey` - non-null with null data, output parameter that will be filled with the SessionKey used
        `wrappedTags` - Output parameter that will be filled with the sessionTags used. If non-empty on return you must call skm.tagsDelivered() when sent and then call skm.tagsAcked() or skm.failTags() later.
        `numTagsToDeliver` - Only if the estimated available tags are below the threshold. Set to zero to disable tag delivery. You must set to zero if you are not equipped to confirm delivery and call skm.tagsAcked() or skm.failTags() later.
        `skm` - non-null
      Returns:
        null if expired
      Throws:
        `IllegalArgumentException` - on error

    - #### buildMessage

          public static GarlicMessage buildMessage(RouterContext ctx,
                                                   GarlicConfig config,
                                                   SessionKey wrappedKey,
                                                   Set<SessionTag> wrappedTags,
                                                   SessionKeyManager skm)

      Now unused, since we have to generate a reply token first in OCMOSJ but we don't know if tags are required yet. ELGAMAL_2048 only.
      Parameters:
        `ctx` - scope
        `config` - how/what to wrap
        `wrappedKey` - non-null with null data, output parameter that will be filled with the SessionKey used
        `wrappedTags` - Output parameter that will be filled with the sessionTags used. If non-empty on return you must call skm.tagsDelivered() when sent and then call skm.tagsAcked() or skm.failTags() later.
        `skm` - non-null
      Returns:
        null if expired
      Throws:
        `IllegalArgumentException` - on error

    - #### buildMessage

          public static GarlicMessage buildMessage(RouterContext ctx,
                                                   GarlicConfig config,
                                                   Set<SessionTag> wrappedTags,
                                                   PublicKey target,
                                                   SessionKey encryptKey,
                                                   SessionTag encryptTag)

      ELGAMAL_2048 only. Used by TestJob, and directly above, and by MessageWrapper for encrypting DatabaseLookupMessages and DSM/DSRM replies.
      Parameters:
        `ctx` - scope
        `config` - how/what to wrap
        `wrappedTags` - New tags to be sent along with the message. 200 max enforced at receiver; null OK
        `target` - public key of the location being garlic routed to (may be null if we know the encryptKey and encryptTag)
        `encryptKey` - sessionKey used to encrypt the current message, non-null
        `encryptTag` - sessionTag used to encrypt the current message, null to force ElG
      Returns:
        null if expired
      Throws:
        `IllegalArgumentException` - on error

    - #### needsTags

          static boolean needsTags(RouterContext ctx,
                                   PublicKey key,
                                   Hash local,
                                   int minTagOverride)

      ELGAMAL_2048 only; returns false for others
      Parameters:
        `local` - non-null; do not use this method for the router's SessionKeyManager
        `minTagOverride` - 0 for no override, > 0 to override SKM's settings