Class SdpUtil

java.lang.Object
org.cloudburstmc.netty.util.nethernet.SdpUtil

public final class SdpUtil extends Object
Helpers for the SDP documents exchanged during signalling.
  • Method Details

    • candidateAddress

      public static String candidateAddress(String candidate)
      The connection address of an a=candidate: line, or null if it has none.

      The grammar of RFC 5245 section 15.1 puts the address in the fifth token, after the foundation, component, transport and priority.

      Parameters:
      candidate - The candidate line
      Returns:
      The address it points at
    • hasRoutableHostCandidate

      public static boolean hasRoutableHostCandidate(String sdp)
      Whether a description holds a host candidate at a routable address.

      A host that gathered one is reachable as the protocol expects, and needs none of the guessing inferredPeerCandidates(java.lang.String, java.net.InetSocketAddress) does.

      Parameters:
      sdp - The description to read
      Returns:
      Whether a peer elsewhere can reach one of its host candidates
    • inferredPeerCandidates

      public static List<String> inferredPeerCandidates(String sdp, InetSocketAddress signalledFrom)
      Candidates for the address a peer signalled from, one per port it gathered locally.

      A peer that holds no reflexive candidate of its own offers nothing a host on another network can reach, and its own checks die on the first NAT they meet. Its public address is known anyway, because it just made an HTTP request from it, and consumer NATs usually keep the port a socket already uses. Checking there costs a few packets, and if it does map that way the check opens the path in both directions.

      Nothing is inferred for a peer that already carries a reflexive or relayed candidate, or that signalled from an address on this network, since there is a real path in both cases.

      Parameters:
      sdp - The offer to read the peer's ports out of
      signalledFrom - The address the offer arrived from, or null if it is not known
      Returns:
      Candidate lines to add to the peer connection, empty when there is nothing to infer
    • withAdvertisedCandidates

      public static String withAdvertisedCandidates(String sdp, Set<String> allowed)
      Drops every ICE candidate whose address is not in allowed.

      ICE gathers a candidate on every interface it can see, which on a host network includes container and overlay addresses that are unreachable from outside. Each one costs the remote peer a round of connectivity checks before it gives up, so a host that knows which of its addresses are reachable can announce only those. If nothing would be left the description is returned untouched, since no candidates at all can never connect.

      Parameters:
      sdp - The description to filter
      allowed - The addresses that may be announced, empty to announce everything
      Returns:
      The filtered description