Class TLSBabelChannelBuilder

All Implemented Interfaces:
BabelChannelBuilder

public class TLSBabelChannelBuilder extends AbstractIPBabelChannelBuilder<TLSBabelChannelBuilder>
Builder for TLSBabelChannel instances.

Configures TLS channel parameters such as the local binding address, event loop group, connection capacity, maximum buffered messages, trust manager factory, key material, tie-breaking comparator, authentication mode, handshake identity verification, and permitted peer nodes prior to channel creation.

Example usage:

TLSBabelChannelBuilder builder = TLSBabelChannel.builder()
        .setBindingAddress(new InetSocketAddress("0.0.0.0", 7000))
        .setNumberOfConnections(100)
        .setAuthMode(TCPBabelChannelAuthMode.MIXED_AUTH)
        .setPermittedNodes(Set.of(allowedPeer1, allowedPeer2))
        .setTrustManagerFactory(new PeerIdentityTrustManagerFactory())
        .verifyIdentity();

When registered with Babel via Babel.builder().registerProtocol(protocol, holderFactory, builder), build(Babel, NodeStore, BabelNode, BabelProtocol) is invoked for each registering protocol. The underlying TLSBabelChannel is created on the first invocation and shared across protocols.

  • Constructor Details

    • TLSBabelChannelBuilder

      public TLSBabelChannelBuilder()
      Constructs a new, unconfigured TLSBabelChannelBuilder.
  • Method Details

    • setTrustManagerFactory

      public TLSBabelChannelBuilder setTrustManagerFactory(TrustManagerFactory trustManager)
      Sets the TrustManagerFactory used to validate peer TLS certificates during the TLS handshake.
      Parameters:
      trustManager - the trust manager factory to use
      Returns:
      this builder instance for method chaining
    • setTrustManager

      public TLSBabelChannelBuilder setTrustManager(TrustManager trustManager)
      Sets the TrustManager used to validate peer TLS certificates during the TLS handshake.

      If the trust manager is an instance of PeerIdentityTrustManager, it is converted using PeerIdentityTrustManager.toTrustManagerFactory(). Otherwise, it is wrapped in a SimpleTrustManagerFactory.

      Parameters:
      trustManager - the trust manager to use
      Returns:
      this builder instance for method chaining
    • setKeyMaterial

      public TLSBabelChannelBuilder setKeyMaterial(CertGenerator.KeyMaterial keyMaterial)
      Sets pre-generated CertGenerator.KeyMaterial containing the ephemeral private key and certificate.
      Parameters:
      keyMaterial - the key material to use
      Returns:
      this builder instance for method chaining
    • setComparator

      public TLSBabelChannelBuilder setComparator(Comparator<? extends BabelNode> comparator)
      Sets the comparator used for tie-breaking when two nodes connect to each other simultaneously.

      Defaults to PublicKeyBabelNodeComparator.INSTANCE if not explicitly configured.

      Parameters:
      comparator - the comparator used to determine connection priority
      Returns:
      this builder instance for method chaining
    • verifyIdentity

      public TLSBabelChannelBuilder verifyIdentity()
      Enables cryptographic handshake identity verification using the local node's private key.
      Returns:
      this builder instance for method chaining
    • setAuthMode

      Configures the authentication mode for the channel, controlling which message types (unsigned, signed, or mixed) are permitted.
      Parameters:
      authMode - the desired AbstractTCPBabelChannel.TCPBabelChannelAuthMode
      Returns:
      this builder instance for method chaining
    • setPermittedNodes

      public TLSBabelChannelBuilder setPermittedNodes(@Nullable Set<? extends BabelNode> permittedNodes)
      Sets the set of permitted nodes for the channel.

      When configured, incoming handshake connections from nodes not present in this set will be rejected. If null, all nodes are permitted.

      Parameters:
      permittedNodes - the set of permitted nodes, or null to allow all nodes
      Returns:
      this builder instance for method chaining
    • build

      public BabelChannel build(Babel runtime, NodeStore store, BabelNode identity, BabelProtocol protocol)
      Creates a new BabelChannel instance, registering it with the given runtime and limiting its interest to the provided message types.

      Creates the underlying TLSBabelChannel on the first invocation and stores it, returning the existing instance on subsequent calls.

      Parameters:
      runtime - the owning Babel runtime
      store - the NodeStore that will be used by this channel
      identity - BabelNode object used to represent this Babel instance to other instances
      protocol - the protocol instance associated with this channel
      Returns:
      a ready-to-use BabelChannel