Class TCPBabelChannelBuilder

All Implemented Interfaces:
BabelChannelBuilder

public class TCPBabelChannelBuilder extends AbstractIPBabelChannelBuilder<TCPBabelChannelBuilder>
Builder for AbstractTCPBabelChannel instances.

Configures TCP channel parameters such as the local binding address, event loop group, connection capacity, tie-breaking comparator, authentication mode, handshake identity verification, and permitted peer nodes prior to channel creation. Example usage:

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

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

  • Constructor Details

  • Method Details

    • verifyIdentity

      public TCPBabelChannelBuilder verifyIdentity()
      Enables cryptographic peer identity verification during the connection handshake.

      When enabled, handshake frames are digitally signed with the local node's private key and validated using the peer's public key (retrieved from PublicKeyBabelNode).

      Returns:
      this builder instance for method chaining
    • setComparator

      public TCPBabelChannelBuilder 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
    • 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 TCPBabelChannelBuilder setPermittedNodes(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 AbstractTCPBabelChannel 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