Class TLSBabelChannelBuilder
- All Implemented Interfaces:
BabelChannelBuilder
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.
-
Field Summary
Fields inherited from class AbstractIPBabelChannelBuilder
DEFAULT_CONNECTION_UP_DELAY, DEFAULT_CONNECTION_UP_DELAY_UNITModifier and TypeFieldDescriptionstatic final longDefault delay in milliseconds before dispatching connection-up notifications.static final TimeUnitDefault time unit forAbstractIPBabelChannelBuilder.DEFAULT_CONNECTION_UP_DELAY.Fields inherited from class AbstractBabelChannelBuilder
DEFAULT_NUMBER_OF_CONNECTIONS, DEFAULT_NUMBER_OF_MESSAGESModifier and TypeFieldDescriptionstatic final intDefault number of connections to expect when initializing the channel.static final intDefault number of message types expected by this channel. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new, unconfiguredTLSBabelChannelBuilder. -
Method Summary
Modifier and TypeMethodDescriptionbuild(Babel runtime, NodeStore store, BabelNode identity, BabelProtocol protocol) Creates a newBabelChannelinstance, registering it with the givenruntimeand limiting its interest to the provided message types.Configures the authentication mode for the channel, controlling which message types (unsigned, signed, or mixed) are permitted.setComparator(Comparator<? extends BabelNode> comparator) Sets the comparator used for tie-breaking when two nodes connect to each other simultaneously.setKeyMaterial(CertGenerator.KeyMaterial keyMaterial) Sets pre-generatedCertGenerator.KeyMaterialcontaining the ephemeral private key and certificate.setPermittedNodes(@Nullable Set<? extends BabelNode> permittedNodes) Sets the set of permitted nodes for the channel.setTrustManager(TrustManager trustManager) Sets theTrustManagerused to validate peer TLS certificates during the TLS handshake.setTrustManagerFactory(TrustManagerFactory trustManager) Sets theTrustManagerFactoryused to validate peer TLS certificates during the TLS handshake.Enables cryptographic handshake identity verification using the local node's private key.Methods inherited from class AbstractIPBabelChannelBuilder
getBindingAddress, getConnectionUpDelay, getConnectionUpDelayUnit, getEventLoopGroup, setBindingAddress, setConnectionUpDelay, setConnectionUpDelay, setEventLoopGroupModifier and TypeMethodDescriptionprotected final InetSocketAddressReturns the currently configured binding address.protected final longReturns the configured connection up delay value.protected final TimeUnitReturns the time unit of the connection up delay.protected final io.netty.channel.EventLoopGroupReturns the configured event loop group, initializing a default one viaBabelIpUtils.createLoopGroup()if none has been set.final TLSBabelChannelBuildersetBindingAddress(InetSocketAddress bindingAddress) Sets the local IP socket address to which the channel should bind.final TLSBabelChannelBuildersetConnectionUpDelay(long delayMillis) Sets the delay in milliseconds before notifying the runtime that a connection is fully up.final TLSBabelChannelBuildersetConnectionUpDelay(long delay, TimeUnit unit) Sets the delay and unit before notifying the runtime that a connection is fully up.final TLSBabelChannelBuildersetEventLoopGroup(io.netty.channel.EventLoopGroup eventLoopGroup) Configures the NettyEventLoopGroupused for network I/O.Methods inherited from class AbstractBabelChannelBuilder
getChannel, getNumberOfConnections, getNumberOfMessages, setChannel, setNumberOfConnections, setNumberOfMessages, validateStateOrThrowModifier and TypeMethodDescriptionprotected final @Nullable BabelChannelReturns the channel instance created by this builder, ornullif not yet built.protected final intGets the expected number of connections set in this builder.protected final intGets the expected number of messages set in this builder.protected final voidsetChannel(BabelChannel channel) Sets the constructed channel instance created by this builder.final TLSBabelChannelBuildersetNumberOfConnections(int numberOfConnections) Sets the default number of connections expected.final TLSBabelChannelBuildersetNumberOfMessages(int numberOfMessages) Sets the expected number of distinct message types handled by this channel.protected final voidValidates that this builder has not yet built its channel instance.
-
Constructor Details
-
TLSBabelChannelBuilder
public TLSBabelChannelBuilder()Constructs a new, unconfiguredTLSBabelChannelBuilder.
-
-
Method Details
-
setTrustManagerFactory
Sets theTrustManagerFactoryused 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
Sets theTrustManagerused to validate peer TLS certificates during the TLS handshake.If the trust manager is an instance of
PeerIdentityTrustManager, it is converted usingPeerIdentityTrustManager.toTrustManagerFactory(). Otherwise, it is wrapped in aSimpleTrustManagerFactory.- Parameters:
trustManager- the trust manager to use- Returns:
- this builder instance for method chaining
-
setKeyMaterial
Sets pre-generatedCertGenerator.KeyMaterialcontaining the ephemeral private key and certificate.- Parameters:
keyMaterial- the key material to use- Returns:
- this builder instance for method chaining
-
setComparator
Sets the comparator used for tie-breaking when two nodes connect to each other simultaneously.Defaults to
PublicKeyBabelNodeComparator.INSTANCEif not explicitly configured.- Parameters:
comparator- the comparator used to determine connection priority- Returns:
- this builder instance for method chaining
-
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 desiredAbstractTCPBabelChannel.TCPBabelChannelAuthMode- Returns:
- this builder instance for method chaining
-
setPermittedNodes
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, ornullto allow all nodes- Returns:
- this builder instance for method chaining
-
build
public BabelChannel build(Babel runtime, NodeStore store, BabelNode identity, BabelProtocol protocol) Creates a newBabelChannelinstance, registering it with the givenruntimeand limiting its interest to the provided message types.Creates the underlying
TLSBabelChannelon the first invocation and stores it, returning the existing instance on subsequent calls.- Parameters:
runtime- the owningBabelruntimestore- theNodeStorethat will be used by this channelidentity-BabelNodeobject used to represent this Babel instance to other instancesprotocol- the protocol instance associated with this channel- Returns:
- a ready-to-use
BabelChannel
-