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
    • hasIpAddress

      public static boolean hasIpAddress(String candidate)
      Whether a candidate points at an IP literal rather than a name.
      Parameters:
      candidate - The candidate line
      Returns:
      Whether its address is an IP literal
    • relayEndpoint

      public static @Nullable InetSocketAddress relayEndpoint(String candidate)
      Where a TURN relay candidate points, the relayed address its checks come from.
      Parameters:
      candidate - The candidate line, with or without a=
      Returns:
      The endpoint, or null for any other type or one without an IP literal and port
    • withIpCandidates

      public static String withIpCandidates(String sdp, int max)
      A description holding only the candidates hasIpAddress(java.lang.String) accepts, the first max of them. One that needs no change comes back as it was.
      Parameters:
      sdp - The description to filter
      max - How many candidates to keep
      Returns:
      The filtered description
    • 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, List<InetSocketAddress> allowed)
      Announces only the endpoints 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 endpoint this host did not gather is the public side of a NAT that forwards it to the media port here, and is announced as a server reflexive candidate based on a host candidate of the same family, on that host's port when the endpoint has none. 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 endpoints this host holds: one naming none of them leaves every candidate in place, and a wrong endpoint 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 endpoints that may be announced, port 0 for any, empty to announce everything
      Returns:
      The filtered description
    • withRelayedCandidates

      public static String withRelayedCandidates(String sdp, List<InetSocketAddress> relays)
      Announces only the endpoints in relays, for media that PROXY protocol relays front, each as withAdvertisedCandidates(java.lang.String, java.util.List<java.net.InetSocketAddress>) translates an endpoint this host did not gather, with its related address hidden. So players only learn the relays, and neither reach nor learn this host's own addresses. A relay is announced only when ICE gathered a host candidate of its family.
      Parameters:
      sdp - The description to filter
      relays - The relay endpoints, port 0 for the media port
      Returns:
      The filtered description, with no candidates when none of the relays can be announced
    • withAddedEndpoints

      public static String withAddedEndpoints(String sdp, List<InetSocketAddress> endpoints)
      Adds each endpoint no UDP candidate announces yet, as withAdvertisedCandidates(java.lang.String, java.util.List<java.net.InetSocketAddress>) adds one this host did not gather, port 0 taking the media port. Nothing is removed. A candidate at the same address on another port does not count: a router that moved the port on its way out may still forward the original one in.
      Parameters:
      sdp - The description to add to
      endpoints - The endpoints to add
      Returns:
      The description with the endpoints added