Class SdpUtil

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

public final class SdpUtil extends Object
Helpers for the SDP documents exchanged during signaling.
  • 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 signaledFrom)
      Candidates for the address a peer signaled 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 signaled 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
      signaledFrom - 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)
      Announces only the addresses in allowed, each in the form it calls for.

      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.

      An allowed address this host did not gather is the public side of a NAT that forwards the media port here, and is announced as a server reflexive candidate on the port of a host candidate of the same family. That works because libjuice matches inbound traffic by its source and never by the address it was sent to. Nothing here can tell a forward from a mistake, so the list only ever narrows the host candidates, and only to addresses this host holds: one naming none of them leaves every candidate in place, and a wrong address costs the peer a failed check rather than the connection. Reflexive and relayed candidates always stay, since they are what the outside sees rather than an interface.

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