Class SdpUtil
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringcandidateAddress(String candidate) The connection address of ana=candidate:line, or null if it has none.static booleanhasIpAddress(String candidate) Whether a candidate points at an IP literal rather than a name.static booleanWhether a description holds a host candidate at a routable address.inferredPeerCandidates(String sdp, InetSocketAddress signaledFrom) Candidates for the address a peer signaled from, one per port it gathered locally.static StringwithAddedEndpoints(String sdp, List<InetSocketAddress> endpoints) Adds each endpoint no UDP candidate announces yet, aswithAdvertisedCandidates(java.lang.String, java.util.List<java.net.InetSocketAddress>)adds one this host did not gather, port 0 taking the media port.static StringwithAdvertisedCandidates(String sdp, List<InetSocketAddress> allowed) Announces only the endpoints inallowed, each in the form it calls for.static StringwithIpCandidates(String sdp, int max) A description holding only the candidateshasIpAddress(java.lang.String)accepts, the firstmaxof them.static StringwithRelayedCandidates(String sdp, List<InetSocketAddress> relays) Announces only the endpoints inrelays, for media that PROXY protocol relays front, each aswithAdvertisedCandidates(java.lang.String, java.util.List<java.net.InetSocketAddress>)translates an endpoint this host did not gather, with its related address hidden.
-
Method Details
-
candidateAddress
The connection address of ana=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
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
-
withIpCandidates
A description holding only the candidateshasIpAddress(java.lang.String)accepts, the firstmaxof them. One that needs no change comes back as it was.- Parameters:
sdp- The description to filtermax- How many candidates to keep- Returns:
- The filtered description
-
hasRoutableHostCandidate
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
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 ofsignaledFrom- 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
Announces only the endpoints inallowed, 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 filterallowed- The endpoints that may be announced, port 0 for any, empty to announce everything- Returns:
- The filtered description
-
withRelayedCandidates
Announces only the endpoints inrelays, for media that PROXY protocol relays front, each aswithAdvertisedCandidates(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 filterrelays- 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
Adds each endpoint no UDP candidate announces yet, aswithAdvertisedCandidates(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 toendpoints- The endpoints to add- Returns:
- The description with the endpoints added
-