Class NetherNetHTTPServerSignaling
java.lang.Object
org.cloudburstmc.netty.channel.nethernet.signaling.NetherNetHTTPServerSignaling
- All Implemented Interfaces:
AutoCloseable,NetherNetServerSignaling,NetherNetSignaling
This class implements a signaling server using HTTP(S) for the NetherNet protocol.
Follows ...
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface org.cloudburstmc.netty.channel.nethernet.signaling.NetherNetServerSignaling
NetherNetServerSignaling.NewConnectionHandlerNested classes/interfaces inherited from interface org.cloudburstmc.netty.channel.nethernet.signaling.NetherNetSignaling
NetherNetSignaling.SignalHandler -
Method Summary
Modifier and TypeMethodDescriptionacceptOffer(String networkId, String sdpOffer, @Nullable InetSocketAddress clientAddress, @Nullable String host, @Nullable ClientInfo client) Answers an SDP offer, whether it arrived over this server's HTTP endpoint or was handed in from outside it.The configured advertised addresses as resolved when binding.booleanWhether ICE may gather on the port signaling is bound to.voidbind(SocketAddress localAddress, @Nullable InetSocketAddress iceAddress, io.netty.channel.EventLoop eventLoop) Binds the signaling medium to listen for incoming connections (Server mode).voidclose()Stops serving for good.The public mappings STUN discovery currently finds, seeNetherNetHTTPServerSignaling.Builder.setStunServers(java.util.Collection<java.lang.String>).Returns the Local Network ID this side is addressed by.voidinitChannel(io.netty.channel.Channel channel) Serves signaling on a TCP connection the host accepted itself, such as one on a port it shares with another protocol, usually withserveHttpoff.booleanisActive()Whether the signaling is connected and able to carry messagesintHow many joins are waiting for an answer, which is whatsetMaxPendingJoinscaps.voidremoveSignalHandler(String connectionId) Removes the signaling handler for a specific connection ID.voidsendDescription(String targetNetworkId, String sdp) Sends a complete session description, every gathered candidate included, to the remote peer.Returns the identity used to sign SDP answers, or null to have each server channel generate one of its own under the domainself, which is then what players see in the trust prompt and which changes on every start.voidsetAdvertisementData(PongData pongData) Serves this as the status document from here on, in place of whatever the builder set.voidsetMediaRelayed(boolean relayed) Called by the server channel beforeNetherNetServerSignaling.bind(java.net.SocketAddress, java.net.InetSocketAddress, io.netty.channel.EventLoop)when PROXY protocol relays front its media port, so answers name the relays and none of this host's own addresses.voidsetMetrics(@Nullable NetherServerMetrics metrics) Sets where to report joins this signaling turns away.voidSets the handler a new connection is handed to, seeNetherNetServerSignaling.NewConnectionHandler.onConnect(java.lang.String, java.lang.String, java.lang.String, java.net.InetSocketAddress, org.cloudburstmc.netty.util.nethernet.PlayerInfo).voidsetSignalHandler(String connectionId, NetherNetSignaling.SignalHandler handler) Sets a handler to receive signaling messages for a specific connection ID.booleanWhether this signaling delivers ICE candidates one by one as they are gathered.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.cloudburstmc.netty.channel.nethernet.signaling.NetherNetServerSignaling
getIceServersMethods inherited from interface org.cloudburstmc.netty.channel.nethernet.signaling.NetherNetSignaling
sendSignal
-
Method Details
-
bind
public void bind(SocketAddress localAddress, @Nullable InetSocketAddress iceAddress, io.netty.channel.EventLoop eventLoop) throws ConnectException Description copied from interface:NetherNetServerSignalingBinds the signaling medium to listen for incoming connections (Server mode).- Specified by:
bindin interfaceNetherNetServerSignaling- Parameters:
localAddress- The local address to bind to.iceAddress- Where ICE binds, on a fixed port shared by every connection, or null when each connection takes a port of its own. A wildcard address gathers on every interface.eventLoop- The owning channel's event loop, where new connections are handed over.- Throws:
ConnectException- If the signaling cannot bind
-
initChannel
public void initChannel(io.netty.channel.Channel channel) Serves signaling on a TCP connection the host accepted itself, such as one on a port it shares with another protocol, usually withserveHttpoff. Call it on the connection's event loop. What the host already read may be passed on after this returns, untouched and PROXY header included, for instance by removing the decoder that held it. A connection handed in afterclose()is closed.- Parameters:
channel- The accepted connection- Throws:
IllegalArgumentException- If the channel is not an IP connection
-
close
public void close()Stops serving for good. Every connection is closed, those a host handed in included, and the signaling cannot be bound again.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceNetherNetSignaling
-
isActive
public boolean isActive()Description copied from interface:NetherNetSignalingWhether the signaling is connected and able to carry messages- Specified by:
isActivein interfaceNetherNetSignaling
-
setNewConnectionHandler
Description copied from interface:NetherNetServerSignalingSets the handler a new connection is handed to, seeNetherNetServerSignaling.NewConnectionHandler.onConnect(java.lang.String, java.lang.String, java.lang.String, java.net.InetSocketAddress, org.cloudburstmc.netty.util.nethernet.PlayerInfo). The server channel installs its own on bind.- Specified by:
setNewConnectionHandlerin interfaceNetherNetServerSignaling- Parameters:
handler- The handler for new connections
-
setAdvertisementData
Serves this as the status document from here on, in place of whatever the builder set.- Specified by:
setAdvertisementDatain interfaceNetherNetServerSignaling- Parameters:
pongData- The advertisement.
-
setMetrics
Description copied from interface:NetherNetServerSignalingSets where to report joins this signaling turns away. Signaling that refuses nothing of its own ignores it.- Specified by:
setMetricsin interfaceNetherNetServerSignaling- Parameters:
metrics- The metrics to report to, or null to report nothing.
-
serverIdentity
Description copied from interface:NetherNetServerSignalingReturns the identity used to sign SDP answers, or null to have each server channel generate one of its own under the domainself, which is then what players see in the trust prompt and which changes on every start.- Specified by:
serverIdentityin interfaceNetherNetServerSignaling- Returns:
- The server identity, or null if this signaling has none
-
allowsIceOnLocalPort
public boolean allowsIceOnLocalPort()Whether ICE may gather on the port signaling is bound to. Set it false when another transport already holds the UDP side of that port, so ICE uses its own.- Specified by:
allowsIceOnLocalPortin interfaceNetherNetServerSignaling- Returns:
- true if ICE should be pinned to the bound address
-
usesTrickleIce
public boolean usesTrickleIce()Description copied from interface:NetherNetSignalingWhether this signaling delivers ICE candidates one by one as they are gathered. Signaling that cannot, such as a single HTTP exchange, receives oneNetherNetSignaling.sendDescription(java.lang.String, java.lang.String)once gathering is complete and no candidate signals at all.- Specified by:
usesTrickleIcein interfaceNetherNetSignaling- Returns:
- true if candidates are trickled as they are gathered
-
getLocalNetworkId
Description copied from interface:NetherNetSignalingReturns the Local Network ID this side is addressed by. A client puts it in its join, a server that is addressed by host name rather than network id, such as HTTP signaling, returns an empty string.- Specified by:
getLocalNetworkIdin interfaceNetherNetSignaling
-
pendingJoins
public int pendingJoins()How many joins are waiting for an answer, which is whatsetMaxPendingJoinscaps.- Returns:
- The joins in flight
-
advertisedAddresses
The configured advertised addresses as resolved when binding. When there are any, answers announce these, seeNetherNetHTTPServerSignaling.Builder.setAdvertisedAddresses(java.util.Collection<java.lang.String>). Safe to call from any thread.- Returns:
- The endpoints, port 0 for an entry that names none, which answers announce on the port ICE uses. Empty before binding or when none are configured
-
setMediaRelayed
public void setMediaRelayed(boolean relayed) Description copied from interface:NetherNetServerSignalingCalled by the server channel beforeNetherNetServerSignaling.bind(java.net.SocketAddress, java.net.InetSocketAddress, io.netty.channel.EventLoop)when PROXY protocol relays front its media port, so answers name the relays and none of this host's own addresses. Signaling that cannot refuses.- Specified by:
setMediaRelayedin interfaceNetherNetServerSignaling- Parameters:
relayed- Whether the media is only reached through relays
-
discoveredEndpoints
The public mappings STUN discovery currently finds, seeNetherNetHTTPServerSignaling.Builder.setStunServers(java.util.Collection<java.lang.String>). Answers announce these along with what ICE gathers and the endpoint the player typed in. Safe to call from any thread.- Returns:
- The endpoints, empty when discovery is off or no server has answered recently
-
acceptOffer
public CompletableFuture<String> acceptOffer(String networkId, String sdpOffer, @Nullable InetSocketAddress clientAddress, @Nullable String host, @Nullable ClientInfo client) Answers an SDP offer, whether it arrived over this server's HTTP endpoint or was handed in from outside it.The returned description already carries the ICE candidates and the server identity assertion, so it can be written back to the peer verbatim.
Callable from any thread. The identity is validated on the signaling's own thread and the rest happens on the event loop, which is also where the future completes.
- Parameters:
networkId- The peer's network IDsdpOffer- The raw SDP offerclientAddress- The address the offer came from, used for the peer's identity and to seed the child channel, or null if it is not knownhost- The host the peer asked for, passed to the player filterclient- What the peer said about itself alongside the offer, or null if it said nothing usable- Returns:
- The signed SDP answer, or a failure carrying an
OfferRejected
-
sendDescription
Description copied from interface:NetherNetSignalingSends a complete session description, every gathered candidate included, to the remote peer. This is how a description travels whenNetherNetSignaling.usesTrickleIce()is false, on either side.- Specified by:
sendDescriptionin interfaceNetherNetSignaling- Parameters:
targetNetworkId- The Network ID of the destination (String to support Realms).sdp- The complete description.
-
setSignalHandler
Description copied from interface:NetherNetSignalingSets a handler to receive signaling messages for a specific connection ID.- Specified by:
setSignalHandlerin interfaceNetherNetSignaling- Parameters:
connectionId- The connection ID to listen for, the token the initiator chose.handler- The handler to process incoming signaling messages.
-
removeSignalHandler
Description copied from interface:NetherNetSignalingRemoves the signaling handler for a specific connection ID.- Specified by:
removeSignalHandlerin interfaceNetherNetSignaling- Parameters:
connectionId- The connection ID whose handler should be removed.
-