Class NetherNetHTTPServerSignaling

java.lang.Object
org.cloudburstmc.netty.channel.nethernet.signaling.NetherNetHTTPServerSignaling
All Implemented Interfaces:
AutoCloseable, NetherNetServerSignaling, NetherNetSignaling

public class NetherNetHTTPServerSignaling extends Object implements NetherNetServerSignaling
This class implements a signaling server using HTTP(S) for the NetherNet protocol.

Follows ...

  • Method Details

    • bind

      public void bind(SocketAddress localAddress, @Nullable InetSocketAddress iceAddress, io.netty.channel.EventLoop eventLoop) throws ConnectException
      Description copied from interface: NetherNetServerSignaling
      Binds the signaling medium to listen for incoming connections (Server mode).
      Specified by:
      bind in interface NetherNetServerSignaling
      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 with serveHttp off. 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 after close() 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:
      close in interface AutoCloseable
      Specified by:
      close in interface NetherNetSignaling
    • isActive

      public boolean isActive()
      Description copied from interface: NetherNetSignaling
      Whether the signaling is connected and able to carry messages
      Specified by:
      isActive in interface NetherNetSignaling
    • setNewConnectionHandler

      public void setNewConnectionHandler(NetherNetServerSignaling.NewConnectionHandler handler)
      Description copied from interface: NetherNetServerSignaling
      Specified by:
      setNewConnectionHandler in interface NetherNetServerSignaling
      Parameters:
      handler - The handler for new connections
    • setAdvertisementData

      public void setAdvertisementData(PongData pongData)
      Serves this as the status document from here on, in place of whatever the builder set.
      Specified by:
      setAdvertisementData in interface NetherNetServerSignaling
      Parameters:
      pongData - The advertisement.
    • setMetrics

      public void setMetrics(@Nullable NetherServerMetrics metrics)
      Description copied from interface: NetherNetServerSignaling
      Sets where to report joins this signaling turns away. Signaling that refuses nothing of its own ignores it.
      Specified by:
      setMetrics in interface NetherNetServerSignaling
      Parameters:
      metrics - The metrics to report to, or null to report nothing.
    • serverIdentity

      public OperatorIdentity serverIdentity()
      Description copied from interface: NetherNetServerSignaling
      Returns the identity used to sign SDP answers, or null to have each server channel generate one of its own under the domain self, which is then what players see in the trust prompt and which changes on every start.
      Specified by:
      serverIdentity in interface NetherNetServerSignaling
      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:
      allowsIceOnLocalPort in interface NetherNetServerSignaling
      Returns:
      true if ICE should be pinned to the bound address
    • usesTrickleIce

      public boolean usesTrickleIce()
      Description copied from interface: NetherNetSignaling
      Whether this signaling delivers ICE candidates one by one as they are gathered. Signaling that cannot, such as a single HTTP exchange, receives one NetherNetSignaling.sendDescription(java.lang.String, java.lang.String) once gathering is complete and no candidate signals at all.
      Specified by:
      usesTrickleIce in interface NetherNetSignaling
      Returns:
      true if candidates are trickled as they are gathered
    • getLocalNetworkId

      public String getLocalNetworkId()
      Description copied from interface: NetherNetSignaling
      Returns 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:
      getLocalNetworkId in interface NetherNetSignaling
    • pendingJoins

      public int pendingJoins()
      How many joins are waiting for an answer, which is what setMaxPendingJoins caps.
      Returns:
      The joins in flight
    • 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 ID
      sdpOffer - The raw SDP offer
      clientAddress - The address the offer came from, used for the peer's identity and to seed the child channel, or null if it is not known
      host - The host the peer asked for, passed to the player filter
      client - 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

      public void sendDescription(String targetNetworkId, String sdp)
      Description copied from interface: NetherNetSignaling
      Sends a complete session description, every gathered candidate included, to the remote peer. This is how a description travels when NetherNetSignaling.usesTrickleIce() is false, on either side.
      Specified by:
      sendDescription in interface NetherNetSignaling
      Parameters:
      targetNetworkId - The Network ID of the destination (String to support Realms).
      sdp - The complete description.
    • setSignalHandler

      public void setSignalHandler(String connectionId, NetherNetSignaling.SignalHandler handler)
      Description copied from interface: NetherNetSignaling
      Sets a handler to receive signaling messages for a specific connection ID.
      Specified by:
      setSignalHandler in interface NetherNetSignaling
      Parameters:
      connectionId - The connection ID to listen for, the token the initiator chose.
      handler - The handler to process incoming signaling messages.
    • removeSignalHandler

      public void removeSignalHandler(String connectionId)
      Description copied from interface: NetherNetSignaling
      Removes the signaling handler for a specific connection ID.
      Specified by:
      removeSignalHandler in interface NetherNetSignaling
      Parameters:
      connectionId - The connection ID whose handler should be removed.