Class TCPBabelChannelBuilder
- All Implemented Interfaces:
BabelChannelBuilder
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.
-
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
ConstructorsConstructorDescriptionCreates a new builder instance with default settings (identity verification disabled andAbstractTCPBabelChannel.TCPBabelChannelAuthMode.NO_AUTH). -
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.setPermittedNodes(Set<? extends BabelNode> permittedNodes) Sets the set of permitted nodes for the channel.Enables cryptographic peer identity verification during the connection handshake.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 TCPBabelChannelBuildersetBindingAddress(InetSocketAddress bindingAddress) Sets the local IP socket address to which the channel should bind.final TCPBabelChannelBuildersetConnectionUpDelay(long delayMillis) Sets the delay in milliseconds before notifying the runtime that a connection is fully up.final TCPBabelChannelBuildersetConnectionUpDelay(long delay, TimeUnit unit) Sets the delay and unit before notifying the runtime that a connection is fully up.final TCPBabelChannelBuildersetEventLoopGroup(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 TCPBabelChannelBuildersetNumberOfConnections(int numberOfConnections) Sets the default number of connections expected.final TCPBabelChannelBuildersetNumberOfMessages(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
-
TCPBabelChannelBuilder
public TCPBabelChannelBuilder()Creates a new builder instance with default settings (identity verification disabled andAbstractTCPBabelChannel.TCPBabelChannelAuthMode.NO_AUTH).
-
-
Method Details
-
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
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
-
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
AbstractTCPBabelChannelon 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
-