Class NetherNetHTTPServerSignaling.Builder
- Enclosing class:
- NetherNetHTTPServerSignaling
NetherNetHTTPServerSignaling.
Only the identity is required, see setIdentity(org.cloudburstmc.netty.util.nethernet.OperatorIdentity). TLS is optional and comes from a
PEM pair or a PKCS12 keystore. The defaults suit a retail client on the open internet:
tokens are checked against Minecraft's auth service, TLS once served is required, and ICE
gathers on the signaling port's UDP side.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds the signaling instance.setAdvertisedAddresses(Collection<String> advertisedAddresses) Sets the endpoints announced as ICE candidates.setAnswerTimeoutSeconds(int answerTimeoutSeconds) Sets how long a join may wait for the channel to answer before it is refused asJoinRefusal.TIMEOUT.setForwardedForProxies(Collection<String> proxies) Sets the reverse proxies whoseX-Forwarded-Forheader is honored, such as an HTTP load balancer.setForwardedForProxies(IpRangeSet proxies) Sets the reverse proxies whoseX-Forwarded-Forheader is honored, from a set that is already parsed.setHttpsKeystore(File httpsKeystore) Serves TLS using an unprotected PKCS12 keystore.setHttpsKeystore(File httpsKeystore, String httpsPassword) Serves TLS using a PKCS12 keystore.setHttpsPem(File certificateChain, File privateKey) Serves TLS using PEM files, the form most certificate authorities hand out.setHttpsPem(File certificateChain, File privateKey, @Nullable String keyPassword) Serves TLS using PEM files.setIceOnLocalPort(boolean iceOnLocalPort) Sets whether ICE may gather on the port signaling binds to.setIdentity(OperatorIdentity identity) Sets the identity used to sign SDP answers.setIdentityPem(File identityPem, String domain) Sets the identity from an unencrypted PEM private key, which carries no certificate and so no domain of its own.setMaxConnectionsPerAddress(int maxConnectionsPerAddress) Caps the connections one address may hold at once.setMaxPendingJoins(int maxPendingJoins) Caps how many joins may be waiting for an answer at once.Sets a fixed MOTD to advertise for every status request.setMotdProvider(MotdProvider motdProvider) Sets the provider called for each status request, which answers null to leave a client to its other transport.setPlayerFilter(PlayerFilter playerFilter) Sets the filter consulted for each join once its identity has been validated.setProxyProtocolProxies(Collection<String> proxies) Sets the proxies whose HAProxy PROXY header, v1 or v2, is read.setProxyProtocolProxies(IpRangeSet proxies) Sets the proxies whose PROXY header is read, from a set that is already parsed.setRequiresTls(boolean requiresTls) Sets whether plaintext requests are answered while TLS is served.setResponseHeaders(Map<String, String> headers) Adds headers to every signaling response, refusals included, for example to tell a proxy in front what this host supports.setServeHttp(boolean serveHttp) Sets whether to serve the HTTP join endpoint.setSslContext(io.netty.handler.ssl.SslContext sslContext) Sets the TLS context for the listener.setStunMaxAge(Duration maxAge) Sets how long a mapping found throughsetStunServers(java.util.Collection<java.lang.String>)is still announced after its last answer, as long as the server reports no other.setStunServers(Collection<String> stunServers) Finds this host's public address through these STUN servers and adds it to every answer, the waysetAdvertisedAddresses(java.util.Collection<java.lang.String>)adds an endpoint this host does not hold.setTokenTrust(TokenTrust tokenTrust) Sets who to trust to have signed the token in a joining peer's identity assertion.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
setIdentity
Sets the identity used to sign SDP answers. Required.Load it with
OperatorIdentity.fromPemOrCreate(java.io.File, java.lang.String),OperatorIdentity.fromPem(java.io.File, java.lang.String)orOperatorIdentity.generate(java.lang.String), or build one straight from a keypair.- Parameters:
identity- The identity to sign with- Returns:
- This builder
-
setIdentityPem
Sets the identity from an unencrypted PEM private key, which carries no certificate and so no domain of its own.- Parameters:
identityPem- PEM file holding the EC P-384 identity keydomain- The name the identity carries, seeOperatorIdentity- Returns:
- This builder
- Throws:
IllegalArgumentException- If the key cannot be read
-
setSslContext
public NetherNetHTTPServerSignaling.Builder setSslContext(io.netty.handler.ssl.SslContext sslContext) Sets the TLS context for the listener. If unset the server listens in plaintext.- Parameters:
sslContext- The context to serve TLS with- Returns:
- This builder
-
setHttpsKeystore
Serves TLS using an unprotected PKCS12 keystore.- Parameters:
httpsKeystore- PKCS12 keystore holding the TLS certificate and key- Returns:
- This builder
-
setHttpsKeystore
public NetherNetHTTPServerSignaling.Builder setHttpsKeystore(File httpsKeystore, String httpsPassword) Serves TLS using a PKCS12 keystore.- Parameters:
httpsKeystore- PKCS12 keystore holding the TLS certificate and keyhttpsPassword- Password forhttpsKeystore, or "" if unprotected- Returns:
- This builder
- Throws:
IllegalArgumentException- If the keystore cannot be read
-
setHttpsPem
Serves TLS using PEM files, the form most certificate authorities hand out.- Parameters:
certificateChain- PEM certificate chain, leaf firstprivateKey- PEM private key for the leaf certificate- Returns:
- This builder
- Throws:
IllegalArgumentException- If either file cannot be read
-
setHttpsPem
public NetherNetHTTPServerSignaling.Builder setHttpsPem(File certificateChain, File privateKey, @Nullable String keyPassword) Serves TLS using PEM files.- Parameters:
certificateChain- PEM certificate chain, leaf firstprivateKey- PEM private key for the leaf certificatekeyPassword- Password forprivateKey, or null if unencrypted- Returns:
- This builder
- Throws:
IllegalArgumentException- If either file cannot be read
-
setMaxConnectionsPerAddress
public NetherNetHTTPServerSignaling.Builder setMaxConnectionsPerAddress(int maxConnectionsPerAddress) Caps the connections one address may hold at once. Defaults to 8, which is one player's worth with room for a status check: players behind one NAT share an address, so a host expecting a household or a LAN party behind one raises it. The proxies of either header are exempt, since every client behind one shares its address.- Parameters:
maxConnectionsPerAddress- Connections per address, must be positive- Returns:
- This builder
-
setMaxPendingJoins
Caps how many joins may be waiting for an answer at once. Each one holds a peer connection open until it is answered or times out, so this bounds what the host spends on connections nobody has completed. Joins past it are refused as unavailable, whoever they came from: it guards a finite resource rather than one peer's share of it.- Parameters:
maxPendingJoins- Joins in flight, must be positive- Returns:
- This builder
-
setAnswerTimeoutSeconds
Sets how long a join may wait for the channel to answer before it is refused asJoinRefusal.TIMEOUT. Defaults to 30 seconds, which covers gathering through STUN and TURN servers. A child that fails sooner ends the wait at once.- Parameters:
answerTimeoutSeconds- The wait in seconds- Returns:
- This builder
-
setForwardedForProxies
Sets the reverse proxies whoseX-Forwarded-Forheader is honored, such as an HTTP load balancer. Requests from anywhere else keep their peer address. Empty by default.The client is the rightmost entry that none of these proxies accounts for, as entries left of it are whatever the client sent. Behind a chain of proxies, list every one of them.
- Parameters:
proxies- Addresses or CIDR ranges, such as10.0.0.0/8- Returns:
- This builder
-
setForwardedForProxies
Sets the reverse proxies whoseX-Forwarded-Forheader is honored, from a set that is already parsed.- Parameters:
proxies- The proxies to trust- Returns:
- This builder
-
setProxyProtocolProxies
Sets the proxies whose HAProxy PROXY header, v1 or v2, is read. Empty by default, which reads none. A connection from one that carries no header is served normally, so a listener can take both. The header is read before TLS, which is where a proxy puts it.- Parameters:
proxies- Addresses or CIDR ranges, such as10.0.0.0/8- Returns:
- This builder
-
setProxyProtocolProxies
Sets the proxies whose PROXY header is read, from a set that is already parsed.- Parameters:
proxies- The proxies to trust- Returns:
- This builder
-
setIceOnLocalPort
Sets whether ICE may gather on the port signaling binds to. Defaults to true, so a host needs one port open for both. Set it false when another transport already holds the UDP side of that port, which is the case for RakNet on the usual 19132, and give ICE its own port throughNetherChannelOption.NETHER_SERVER_ICE_ADDRESS.- Parameters:
iceOnLocalPort- Whether ICE may use the signaling port- Returns:
- This builder
-
setAdvertisedAddresses
public NetherNetHTTPServerSignaling.Builder setAdvertisedAddresses(Collection<String> advertisedAddresses) Sets the endpoints announced as ICE candidates. Each is an IP literal or a host name, alone or with a port ashost:port,IPv4:portor[IPv6]:port; one without a port takes the media port. Listed endpoints this host holds narrow its host candidates to those; any other is announced as the public side of a NAT forwarding it to the media port here. A signaling proxy's address does not belong here unless it also forwards the media port.A name stands for every address it resolves to. It is looked up once, when binding, which fails if it does not resolve, so a change takes a new bind. Binding also fails beyond 32 endpoints.
Empty, the default, announces everything ICE gathers, plus what
setStunServers(java.util.Collection<java.lang.String>)finds and the IP literal a player typed in, when those are not among them. The typed one reaches a host behind NAT or in a container nobody configured, but not a player who typed a name or arrived through a trusted proxy. Behind PROXY protocol relays, list the relays. Left empty there, answers carry this host's own addresses, which only works when a front rewrites them to the relays.- Parameters:
advertisedAddresses- Endpoints reachable by connecting peers- Returns:
- This builder
- Throws:
IllegalArgumentException- If an entry is none of those forms, or an address no player can reach- See Also:
-
setStunServers
Finds this host's public address through these STUN servers and adds it to every answer, the waysetAdvertisedAddresses(java.util.Collection<java.lang.String>)adds an endpoint this host does not hold. Off by default. Each is astun:host[:port]URL, port 3478 when it names none.They are asked from the ICE port in the background, every 15 seconds, which also keeps the NAT mapping open, so no join waits for them. A mapping is announced until
setStunMaxAge(java.time.Duration)after its last answer, or until the server reports another. That suits a router that keeps one mapping for all incoming traffic, as a port forward does. A monitor that fails is opened again afterStunObserver.RETRY_DELAY, seeStunObserver. A router that moved the port on the way out, which it does when the port is taken outside, often by a forward to this host, gets the address announced on the ICE port as well, costing a peer one failed check when there is no such forward.Binding fails without a fixed ICE port, see
setIceOnLocalPort(boolean), or behind PROXY protocol relays. Building fails when advertised addresses are set too.- Parameters:
stunServers- The servers to ask, empty for none- Returns:
- This builder
- Throws:
IllegalArgumentException- If an entry is not astun:URL
-
setStunMaxAge
Sets how long a mapping found throughsetStunServers(java.util.Collection<java.lang.String>)is still announced after its last answer, as long as the server reports no other. Defaults to 5 minutes.- Parameters:
maxAge- The age past which a mapping is dropped, must be positive- Returns:
- This builder
-
setTokenTrust
Sets who to trust to have signed the token in a joining peer's identity assertion. Defaults toTokenTrust.MINECRAFT_AUTH, which is what a retail client presents. A peer built with this library, such as a proxy presentingOperatorIdentity.forPlayer(java.lang.String, java.lang.String), signs its own token, which onlyTokenTrust.ANYaccepts.- Parameters:
tokenTrust- The trust policy- Returns:
- This builder
-
setServeHttp
Sets whether to serve the HTTP join endpoint. Defaults to true. With it off nothing is listened on: a host hands in the connections it accepted throughNetherNetHTTPServerSignaling.initChannel(io.netty.channel.Channel), or an endpoint outside this process hands in offers throughNetherNetHTTPServerSignaling.acceptOffer(java.lang.String, java.lang.String, java.net.InetSocketAddress, java.lang.String, org.cloudburstmc.netty.channel.nethernet.signaling.ClientInfo).- Parameters:
serveHttp- Whether to bind the join endpoint- Returns:
- This builder
-
setRequiresTls
Sets whether plaintext requests are answered while TLS is served. Defaults to true, so they are not: a plaintext request gets a 426 and the peer is left to fall back to whatever other transport it has, rather than joining over plaintext, where a client shows its first use trust prompt. Has no effect without a TLS context.- Parameters:
requiresTls- Whether to refuse plaintext requests- Returns:
- This builder
-
setPlayerFilter
Sets the filter consulted for each join once its identity has been validated. Defaults to allowing everyone.- Parameters:
playerFilter- The filter to consult- Returns:
- This builder
-
setMotdProvider
Sets the provider called for each status request, which answers null to leave a client to its other transport. Defaults toPongData.DEFAULT.- Parameters:
motdProvider- The provider to call- Returns:
- This builder
-
setMotd
Sets a fixed MOTD to advertise for every status request. The same assetAdvertisementDataon the built signaling.- Parameters:
motd- The MOTD to advertise- Returns:
- This builder
-
setResponseHeaders
Adds headers to every signaling response, refusals included, for example to tell a proxy in front what this host supports. None by default.Content-Type,Content-Length,Transfer-Encoding,Connection,Keep-AliveandUpgradeare reserved.- Parameters:
headers- Header names to values- Returns:
- This builder
- Throws:
IllegalArgumentException- If a name or value is invalid, or the name is reserved
-
build
Builds the signaling instance.- Returns:
- A new signaling instance
- Throws:
IllegalStateException- If no identity was set, or STUN discovery and advertised addresses both were
-