Noble Connect
Add relays and punchthrough to Mirror or UNet
NobleConnect.Ice.Candidate Class Reference

Public Member Functions

 Candidate (CandidateType candidateType, Candidate baseCandidate, IPEndPoint transportEndPoint, IPEndPoint relatedEndPoint=null, byte[] foundation=null)
 
 Candidate (CandidateType candidateType, Stun.Controller stunController, IPEndPoint transportEndPoint, IPEndPoint relatedEndPoint=null, byte[] foundation=null)
 
 Candidate (byte[] bytes, ref int i)
 Construct a candidate from a sip message More...
 
void Serialize (BufferView buffer)
 Serialize a candidate to a buffer More...
 
IPEndPoint GetTransportEndPoint (AddressFamily family, bool allowNonMatching=false)
 Get the end point with the specified address family More...
 
void AddRemoteCredentials (Candidate remoteCandidate, Credentials cred)
 Add credentials to communicate with a remote candidate More...
 
bool HasEndPoint (IPEndPoint endPoint)
 Check if the candidate has the provided end point More...
 
string ToString (bool includePriority)
 A human readable representation of a candidate, with the option to include priority More...
 
override string ToString ()
 A human readable representation of a candidate More...
 

Static Public Member Functions

static Candidate CreateHostCandidate (Stun.Controller stunController)
 
static Candidate CreateRelayedCandidate (Stun.Controller stunController, IPEndPoint transportEndPoint, IPEndPoint relatedEndPoint)
 
static Candidate CreateServerReflexiveCandidate (Candidate baseCandidate, IPEndPoint transportEndPoint)
 
static Candidate CreatePeerReflexiveCandidateFromResponse (Candidate baseCandidate, IPEndPoint transportEndPoint, uint priority)
 
static Candidate CreatePeerReflexiveCandidateFromRequest (Stun.Controller stunController, IPEndPoint transportEndPoint, uint priority)
 
static uint CalculatePriority (CandidateType candidateType, ushort localPreference)
 Calculate candidate priority based on candidate type and local preference More...
 
static bool IsValidCandidateBytes (byte[] bytes, int i)
 Determine if some bytes look like a valid candidate More...
 

Public Attributes

CandidateType candidateType
 
Candidate baseCandidate
 
IPEndPoint transportEndPoint = null
 The primary endpoint that peers will try and connect to. More...
 
IPEndPoint transportEndPointDualStack = null
 A secondary endpoint that peers may try and connect to. More...
 
IPEndPoint relatedEndPoint
 The related address. See RFC 5245 Section 15.1 More...
 
readonly ReadOnlyByteArray foundation
 A hash of base address, candidate type, and stun server endpoint. If two candidates have the same foundation they are a good match More...
 
uint priority
 Higher priority candidates are more likely to be used More...
 
byte localPreference
 Preference based on the format of the local address. More...
 
bool isDefault
 

Static Public Attributes

const ushort MIN_SDP_BYTES = 24
 The minimum number of bytes that can be required to encode a Candidate in an sdp message More...
 
const ushort MAX_SDP_BYTES = 50
 The maximum number of bytes that can be required to encode a Candidate in an sdp message More...
 
static readonly Dictionary< CandidateType, byte > CandidateTypePreferences
 Determines the priority of each candidate type. More direct connections are preferred. Relay is not preferred. More...
 

Properties

bool IsDualStack [get]
 Dual stack candidates have a second endpoint, transportEndPointDualStack. More...
 
IPAddress? TransportAddress [get]
 
ushort? TransportPort [get]
 
IPAddress? TransportAddressDualStack [get]
 
ushort? TransportPortDualStack [get]
 
Stun.Controller stunController [get]
 

Constructor & Destructor Documentation

◆ Candidate() [1/3]

NobleConnect.Ice.Candidate.Candidate ( CandidateType  candidateType,
Candidate  baseCandidate,
IPEndPoint  transportEndPoint,
IPEndPoint  relatedEndPoint = null,
byte[]  foundation = null 
)

◆ Candidate() [2/3]

NobleConnect.Ice.Candidate.Candidate ( CandidateType  candidateType,
Stun.Controller  stunController,
IPEndPoint  transportEndPoint,
IPEndPoint  relatedEndPoint = null,
byte[]  foundation = null 
)

◆ Candidate() [3/3]

NobleConnect.Ice.Candidate.Candidate ( byte[]  bytes,
ref int  i 
)

Construct a candidate from a sip message

Member Function Documentation

◆ AddRemoteCredentials()

void NobleConnect.Ice.Candidate.AddRemoteCredentials ( Candidate  remoteCandidate,
Credentials  cred 
)

Add credentials to communicate with a remote candidate

Adds credentials for both transport end point and dual stack end point for both candidates

Parameters
remoteCandidate
cred

◆ CalculatePriority()

static uint NobleConnect.Ice.Candidate.CalculatePriority ( CandidateType  candidateType,
ushort  localPreference 
)
static

Calculate candidate priority based on candidate type and local preference

Parameters
candidateType
localPreference
Returns

◆ CreateHostCandidate()

static Candidate NobleConnect.Ice.Candidate.CreateHostCandidate ( Stun.Controller  stunController)
static

◆ CreatePeerReflexiveCandidateFromRequest()

static Candidate NobleConnect.Ice.Candidate.CreatePeerReflexiveCandidateFromRequest ( Stun.Controller  stunController,
IPEndPoint  transportEndPoint,
uint  priority 
)
static

◆ CreatePeerReflexiveCandidateFromResponse()

static Candidate NobleConnect.Ice.Candidate.CreatePeerReflexiveCandidateFromResponse ( Candidate  baseCandidate,
IPEndPoint  transportEndPoint,
uint  priority 
)
static

◆ CreateRelayedCandidate()

static Candidate NobleConnect.Ice.Candidate.CreateRelayedCandidate ( Stun.Controller  stunController,
IPEndPoint  transportEndPoint,
IPEndPoint  relatedEndPoint 
)
static

◆ CreateServerReflexiveCandidate()

static Candidate NobleConnect.Ice.Candidate.CreateServerReflexiveCandidate ( Candidate  baseCandidate,
IPEndPoint  transportEndPoint 
)
static

◆ GetTransportEndPoint()

IPEndPoint NobleConnect.Ice.Candidate.GetTransportEndPoint ( AddressFamily  family,
bool  allowNonMatching = false 
)

Get the end point with the specified address family

For dual stack support candidates can have multiple end points. This method can be used to get the end point of a specific family. Throws an exception if neither address matches.

Parameters
family
Returns

◆ HasEndPoint()

bool NobleConnect.Ice.Candidate.HasEndPoint ( IPEndPoint  endPoint)

Check if the candidate has the provided end point

Returns true if either the transportEndPoint or transportEndPointDualStack match the provided endpoint.

Parameters
endPoint
Returns

◆ IsValidCandidateBytes()

static bool NobleConnect.Ice.Candidate.IsValidCandidateBytes ( byte[]  bytes,
int  i 
)
static

Determine if some bytes look like a valid candidate

Looks at local preference, encoded byte, and candidate type to check for valid values

Parameters
bytes
i
Returns

◆ Serialize()

void NobleConnect.Ice.Candidate.Serialize ( BufferView  buffer)

Serialize a candidate to a buffer

Serialized foundation, encoded byte, transport end point, and dual stack transport end point. The encoded byte contains the transport address family, the dual stack flag, and the candidate type.

Parameters
buffer

◆ ToString() [1/2]

override string NobleConnect.Ice.Candidate.ToString ( )

A human readable representation of a candidate

Format is: candidateType transportEndPoint [transportEndPointDualStack] base: baseCandidate.transportEndPoint related: relatedEndPoint [DEFAULT]

Returns

◆ ToString() [2/2]

string NobleConnect.Ice.Candidate.ToString ( bool  includePriority)

A human readable representation of a candidate, with the option to include priority

Format is: candidateType transportEndPoint [transportEndPointDualStack] base: baseCandidate.transportEndPoint related: relatedEndPoint [DEFAULT] priority

Returns

Member Data Documentation

◆ baseCandidate

Candidate NobleConnect.Ice.Candidate.baseCandidate

◆ candidateType

CandidateType NobleConnect.Ice.Candidate.candidateType

◆ CandidateTypePreferences

readonly Dictionary<CandidateType, byte> NobleConnect.Ice.Candidate.CandidateTypePreferences
static
Initial value:
= new Dictionary<CandidateType, byte>()
{
{ CandidateType.HOST, 126 },
{ CandidateType.SERVER_REFLEXIVE, 100 },
{ CandidateType.SERVER_REFLEXIVE_EXCLUSIVE, 105 },
{ CandidateType.PEER_REFLEXIVE, 110 },
{ CandidateType.RELAYED, 0 }
}

Determines the priority of each candidate type. More direct connections are preferred. Relay is not preferred.

◆ foundation

readonly ReadOnlyByteArray NobleConnect.Ice.Candidate.foundation

A hash of base address, candidate type, and stun server endpoint. If two candidates have the same foundation they are a good match

◆ isDefault

bool NobleConnect.Ice.Candidate.isDefault

◆ localPreference

byte NobleConnect.Ice.Candidate.localPreference

Preference based on the format of the local address.

IPv6 is favored over IPv4 unless it's some weird set of IPv6 like toredo.

◆ MAX_SDP_BYTES

const ushort NobleConnect.Ice.Candidate.MAX_SDP_BYTES = 50
static

The maximum number of bytes that can be required to encode a Candidate in an sdp message

◆ MIN_SDP_BYTES

const ushort NobleConnect.Ice.Candidate.MIN_SDP_BYTES = 24
static

The minimum number of bytes that can be required to encode a Candidate in an sdp message

◆ priority

uint NobleConnect.Ice.Candidate.priority

Higher priority candidates are more likely to be used

This is calculated from local preference and candidate type.

◆ relatedEndPoint

IPEndPoint NobleConnect.Ice.Candidate.relatedEndPoint

The related address. See RFC 5245 Section 15.1

This is only used for diagnostic purposes. For Host candidates this will be unset. For reflexive candidates this will be the host address. For relay candidates this will be the reflexive address that is received with the allocate response.

◆ transportEndPoint

IPEndPoint NobleConnect.Ice.Candidate.transportEndPoint = null

The primary endpoint that peers will try and connect to.

Local candidates get their endpoints from probing the OS and opening sockets (for host candidates) or from the allocation response in OnAllocateSuccess (for server reflexive and relay candidates). Remote candidates get their endpoints from the sip invite or response.

◆ transportEndPointDualStack

IPEndPoint NobleConnect.Ice.Candidate.transportEndPointDualStack = null

A secondary endpoint that peers may try and connect to.

Dual stack relays have two endpoints, one for ipv4 and one for ipv6. Both ipv4 and ipv6 local candidates can be paired with dual stack remote candidates and vice versa. The same credentials are used to communicate with either end point. When sending bind requests or other messages to a remote candidate, we send to whichever endpoint matches the address family of the sending socket. When a messages is received from either end point it will be recognized as coming from the same remote candidate.

Local candidates get their endpoints from probing the OS and opening sockets(for host candidates) or from the allocation response in OnAllocateSuccess(for server reflexive and relay candidates). Remote candidates get their endpoints from the sip invite or response.

Property Documentation

◆ IsDualStack

bool NobleConnect.Ice.Candidate.IsDualStack
get

Dual stack candidates have a second endpoint, transportEndPointDualStack.

If the transportEndPoint is IPv4 the transportEndPointDualStack will be IPv6 and vice-versa Either end point can be used to communicate with this candidate.

◆ stunController

Stun.Controller NobleConnect.Ice.Candidate.stunController
get

◆ TransportAddress

IPAddress? NobleConnect.Ice.Candidate.TransportAddress
get

◆ TransportAddressDualStack

IPAddress? NobleConnect.Ice.Candidate.TransportAddressDualStack
get

◆ TransportPort

ushort? NobleConnect.Ice.Candidate.TransportPort
get

◆ TransportPortDualStack

ushort? NobleConnect.Ice.Candidate.TransportPortDualStack
get
NobleConnect.Ice.CandidateType
CandidateType
Definition: CandidateType.cs:3