Noble Connect
Add relays and punchthrough to Mirror or UNet
NobleConnect.Turn.TurnExtension Class Reference

Inherits NobleConnect.Stun.IStunExtension.

Public Member Functions

 TurnExtension (IPEndPoint turnServerEndpoint=null)
 
override Stun.MessageMethod CreateMessageMethod (byte[] buffer, int bufferIndex)
 
override Stun.Attribute CreateAttribute (byte[] buffer, int bufferIndex, ReadOnlyByteArray transactionID)
 
override bool HandleReceive (byte[] buffer, int index, int count, IPEndPoint remoteEndPoint, IPEndPoint receivedAt)
 
Message ConstructAllocateRequest (byte[] sessionGUID=null, int lifetime=60, Credentials c=null)
 
Transaction< MessageSendAllocateRequest (Action< Message > onSuccess, Action< Message > onFailure=null, Action< Message > onConnectionLost=null, byte[] sessionGUID=null, int lifetime=60, int refreshTime=30, int overrideMaxResend=-1, int overrideTimeout=-1)
 Send an Allocation Request to the Turn server in order to receive our allocated relay address More...
 
void OnAllocateComplete (Transaction< Message > transaction, int refreshTime, Action< Message > onSuccess=null, Action< Message > onFailure=null, Action< Message > onConnectionLost=null)
 
void QueueRefreshRequest (int allocationLifetime, int refreshTime, Transaction< Message > transaction, Action< Message > onFailure=null, bool sendImmediately=false)
 
Transaction< MessageSendRefreshRequest (int lifetime=60, int refreshTime=30, Action< Message > onSuccess=null, Action< Message > onFailure=null)
 
void RevokeAllocation ()
 
Transaction< MessageSendChannelBindRequest (IPEndPoint peerEndPoint)
 
Transaction< MessageSendChannelBindRequest (IPEndPoint peerEndPoint, Action< Message > onSuccess, Action< Message > onFail)
 
Transaction< MessageSendChannelBindRequest (IPEndPoint peerEndPoint, IPEndPoint target, IPEndPoint source, Action< Message > onChannelBind, Action< Message > onFail, bool dontRefresh=false)
 
Transaction< MessageSendChannelBindRequest (ChannelTuple channelTuple, Action< Message > onChannelBind, Action< Message > onFail, bool dontRefresh=false)
 
void QueueChannelBindRefresh (ChannelTuple channelTuple, ChannelIDTuple channelIDTuple)
 
void OnChannelBindRefreshSuccess (ChannelTuple channelTuple, ChannelIDTuple channelIDTuple)
 
void OnChannelBindRefreshFailure (Message response, ChannelTuple channelTuple, ChannelIDTuple channelIDTuple)
 
void RevokeChannel (IPEndPoint peerEndPoint)
 
void RevokeChannel (ChannelTuple tuple)
 
void RevokeAllChannels ()
 
void SendCreatePermissionRequest (IPAddress peerIP, Action< Message > onSuccess, Action< Message > onFail)
 
void SendCreatePermissionRequest (IPAddress peerIP, Action< Message > onSuccess, Action< Message > onFail, IPEndPoint relayEndPoint, IPEndPoint target, IPEndPoint source, bool dontRefresh=false, int overrideMaxResend=-1)
 Send a Create Permission Request to the Turn server More...
 
Message ConstructCreatePermissionMessage (IPAddress peerIP, IPEndPoint relayEndPoint, IPEndPoint target, IPEndPoint source)
 Construct a create permission message More...
 
void QueuePermissionRefresh (IPAddress peerAddress, IPEndPoint relayEndPoint, IPEndPoint target, IPEndPoint source)
 
void RevokePermission (IPAddress peerIP)
 
void RevokePermission (IPAddress peerIP, IPEndPoint relayEndPoint, IPEndPoint target, IPEndPoint source)
 
void RevokeAllPermissions ()
 
void SendData (byte[] data, int offset, int length, IPEndPoint peer)
 
void SendData (byte[] data, int offset, int length, IPEndPoint peer, IPEndPoint target, IPEndPoint source)
 Send some data from a Turn client, over a relay, to a Turn peer More...
 
void SendChannelMessage (byte[] data, int offset, int length, IPEndPoint peer)
 
void SendChannelMessage (PaddedBuffer buffer, int numBytes, IPEndPoint peer)
 
override bool HandleIndication (Message message, IPEndPoint remoteEndPoint, IPEndPoint receivedAt)
 Handle an INDICATION Message from the Turn server. More...
 
override bool Send (Message message, IPEndPoint target, IPEndPoint source)
 
override bool HandleErrorResponse (Transaction< Message > transaction, Message message, IPEndPoint source, ref bool isComplete)
 
bool HandleErrorAlternateServer (Transaction< Message > transaction, Message response, IPEndPoint source)
 
override int GetExtensionPriority ()
 
- Public Member Functions inherited from NobleConnect.Stun.IStunExtension
virtual MessageClass CreateMessageClass (byte[] buffer, int bufferIndex)
 
virtual bool HandleRequest (Message request, IPEndPoint source, IPEndPoint receivedAt)
 
virtual bool HandleResponse (Transaction< Message > transaction, Message response, IPEndPoint source, IPEndPoint receivedAt)
 
virtual Credentials FindLocalCredentials (Message request)
 
void Dispose ()
 

Public Attributes

IPEndPoint allocationEndPoint
 The relay allocation endpoints associated with this stun controller More...
 
int numConsecutiveTimesAllocationLost = 0
 
- Public Attributes inherited from NobleConnect.Stun.IStunExtension
Controller stunController
 

Protected Member Functions

override void Dispose (bool disposing)
 

Properties

IPEndPoint TurnServerEndpoint [get, set]
 

Constructor & Destructor Documentation

◆ TurnExtension()

NobleConnect.Turn.TurnExtension.TurnExtension ( IPEndPoint  turnServerEndpoint = null)

Member Function Documentation

◆ ConstructAllocateRequest()

Message NobleConnect.Turn.TurnExtension.ConstructAllocateRequest ( byte[]  sessionGUID = null,
int  lifetime = 60,
Credentials  c = null 
)

◆ ConstructCreatePermissionMessage()

Message NobleConnect.Turn.TurnExtension.ConstructCreatePermissionMessage ( IPAddress  peerIP,
IPEndPoint  relayEndPoint,
IPEndPoint  target,
IPEndPoint  source 
)

Construct a create permission message

Parameters
peerIPThe IP of the peer to allow communication with over the relay
relayEndPointThe IP of the relay allocation to allow sending over. If left out then the stun server will automatically use the allocation associated with this stun controller
targetThe IP of the stun server to send the request to. If left out the stun server associated with this stun controller is used.)
sourceThe source, either a stun controller local end point or a relay end point that we are sending from
Returns

◆ CreateAttribute()

override Stun.Attribute NobleConnect.Turn.TurnExtension.CreateAttribute ( byte[]  buffer,
int  bufferIndex,
ReadOnlyByteArray  transactionID 
)
virtual

Reimplemented from NobleConnect.Stun.IStunExtension.

◆ CreateMessageMethod()

override Stun.MessageMethod NobleConnect.Turn.TurnExtension.CreateMessageMethod ( byte[]  buffer,
int  bufferIndex 
)
virtual

Reimplemented from NobleConnect.Stun.IStunExtension.

◆ Dispose()

override void NobleConnect.Turn.TurnExtension.Dispose ( bool  disposing)
protectedvirtual

Reimplemented from NobleConnect.Stun.IStunExtension.

◆ GetExtensionPriority()

override int NobleConnect.Turn.TurnExtension.GetExtensionPriority ( )
virtual

◆ HandleErrorAlternateServer()

bool NobleConnect.Turn.TurnExtension.HandleErrorAlternateServer ( Transaction< Message transaction,
Message  response,
IPEndPoint  source 
)

◆ HandleErrorResponse()

override bool NobleConnect.Turn.TurnExtension.HandleErrorResponse ( Transaction< Message transaction,
Message  message,
IPEndPoint  source,
ref bool  isComplete 
)
virtual

Reimplemented from NobleConnect.Stun.IStunExtension.

◆ HandleIndication()

override bool NobleConnect.Turn.TurnExtension.HandleIndication ( Message  message,
IPEndPoint  remoteEndPoint,
IPEndPoint  receivedAt 
)
virtual

Handle an INDICATION Message from the Turn server.

This is where incoming Data messages from Turn peers are received on a Turn client. Theoretically other indications would be handled here as well but if there are any I haven't come across them yet.

Parameters
message
transaction

Reimplemented from NobleConnect.Stun.IStunExtension.

◆ HandleReceive()

override bool NobleConnect.Turn.TurnExtension.HandleReceive ( byte[]  buffer,
int  index,
int  count,
IPEndPoint  remoteEndPoint,
IPEndPoint  receivedAt 
)
virtual

Reimplemented from NobleConnect.Stun.IStunExtension.

◆ OnAllocateComplete()

void NobleConnect.Turn.TurnExtension.OnAllocateComplete ( Transaction< Message transaction,
int  refreshTime,
Action< Message onSuccess = null,
Action< Message onFailure = null,
Action< Message onConnectionLost = null 
)

◆ OnChannelBindRefreshFailure()

void NobleConnect.Turn.TurnExtension.OnChannelBindRefreshFailure ( Message  response,
ChannelTuple  channelTuple,
ChannelIDTuple  channelIDTuple 
)

◆ OnChannelBindRefreshSuccess()

void NobleConnect.Turn.TurnExtension.OnChannelBindRefreshSuccess ( ChannelTuple  channelTuple,
ChannelIDTuple  channelIDTuple 
)

◆ QueueChannelBindRefresh()

void NobleConnect.Turn.TurnExtension.QueueChannelBindRefresh ( ChannelTuple  channelTuple,
ChannelIDTuple  channelIDTuple 
)

◆ QueuePermissionRefresh()

void NobleConnect.Turn.TurnExtension.QueuePermissionRefresh ( IPAddress  peerAddress,
IPEndPoint  relayEndPoint,
IPEndPoint  target,
IPEndPoint  source 
)

◆ QueueRefreshRequest()

void NobleConnect.Turn.TurnExtension.QueueRefreshRequest ( int  allocationLifetime,
int  refreshTime,
Transaction< Message transaction,
Action< Message onFailure = null,
bool  sendImmediately = false 
)

◆ RevokeAllChannels()

void NobleConnect.Turn.TurnExtension.RevokeAllChannels ( )

◆ RevokeAllocation()

void NobleConnect.Turn.TurnExtension.RevokeAllocation ( )

◆ RevokeAllPermissions()

void NobleConnect.Turn.TurnExtension.RevokeAllPermissions ( )

◆ RevokeChannel() [1/2]

void NobleConnect.Turn.TurnExtension.RevokeChannel ( ChannelTuple  tuple)

◆ RevokeChannel() [2/2]

void NobleConnect.Turn.TurnExtension.RevokeChannel ( IPEndPoint  peerEndPoint)

◆ RevokePermission() [1/2]

void NobleConnect.Turn.TurnExtension.RevokePermission ( IPAddress  peerIP)

◆ RevokePermission() [2/2]

void NobleConnect.Turn.TurnExtension.RevokePermission ( IPAddress  peerIP,
IPEndPoint  relayEndPoint,
IPEndPoint  target,
IPEndPoint  source 
)

◆ Send()

override bool NobleConnect.Turn.TurnExtension.Send ( Message  message,
IPEndPoint  target,
IPEndPoint  source 
)
virtual

Reimplemented from NobleConnect.Stun.IStunExtension.

◆ SendAllocateRequest()

Transaction<Message> NobleConnect.Turn.TurnExtension.SendAllocateRequest ( Action< Message onSuccess,
Action< Message onFailure = null,
Action< Message onConnectionLost = null,
byte[]  sessionGUID = null,
int  lifetime = 60,
int  refreshTime = 30,
int  overrideMaxResend = -1,
int  overrideTimeout = -1 
)

Send an Allocation Request to the Turn server in order to receive our allocated relay address

The provided onAllocateComplete method is called when the response is received.

Parameters
onSuccess

◆ SendChannelBindRequest() [1/4]

Transaction<Message> NobleConnect.Turn.TurnExtension.SendChannelBindRequest ( ChannelTuple  channelTuple,
Action< Message onChannelBind,
Action< Message onFail,
bool  dontRefresh = false 
)

◆ SendChannelBindRequest() [2/4]

Transaction<Message> NobleConnect.Turn.TurnExtension.SendChannelBindRequest ( IPEndPoint  peerEndPoint)

◆ SendChannelBindRequest() [3/4]

Transaction<Message> NobleConnect.Turn.TurnExtension.SendChannelBindRequest ( IPEndPoint  peerEndPoint,
Action< Message onSuccess,
Action< Message onFail 
)

◆ SendChannelBindRequest() [4/4]

Transaction<Message> NobleConnect.Turn.TurnExtension.SendChannelBindRequest ( IPEndPoint  peerEndPoint,
IPEndPoint  target,
IPEndPoint  source,
Action< Message onChannelBind,
Action< Message onFail,
bool  dontRefresh = false 
)

◆ SendChannelMessage() [1/2]

void NobleConnect.Turn.TurnExtension.SendChannelMessage ( byte[]  data,
int  offset,
int  length,
IPEndPoint  peer 
)

◆ SendChannelMessage() [2/2]

void NobleConnect.Turn.TurnExtension.SendChannelMessage ( PaddedBuffer  buffer,
int  numBytes,
IPEndPoint  peer 
)

◆ SendCreatePermissionRequest() [1/2]

void NobleConnect.Turn.TurnExtension.SendCreatePermissionRequest ( IPAddress  peerIP,
Action< Message onSuccess,
Action< Message onFail 
)

◆ SendCreatePermissionRequest() [2/2]

void NobleConnect.Turn.TurnExtension.SendCreatePermissionRequest ( IPAddress  peerIP,
Action< Message onSuccess,
Action< Message onFail,
IPEndPoint  relayEndPoint,
IPEndPoint  target,
IPEndPoint  source,
bool  dontRefresh = false,
int  overrideMaxResend = -1 
)

Send a Create Permission Request to the Turn server

Before the Turn server will pass data over a relay the Turn client must install a permission for the Turn peer it wishes to communicate with by calling this method and passing in the peer's server reflexive ip. This is the address that the peer receives in response to a Bind Request. How you get the peer address to the client is up to the application developer. For a game this would mean some sort of matchmaking server. The provided onCreatePermission method will be called when a response is received.

Parameters
peerIPThe IP of the peer to allow communication with over the relay
onSuccessMethod to call after permission is succesfully created
onFailMethod to call if permission creation fails
relayEndPointThe IP of the relay allocation to allow sending over. If left out then the stun server will automatically use the allocation associated with this stun controller
targetThe stun server to send the request to
sourceThe end point to send from, either a local socket address or relay
dontRefreshShould the permission be automatically refreshed
overrideMaxResendOptionally override number of retries

◆ SendData() [1/2]

void NobleConnect.Turn.TurnExtension.SendData ( byte[]  data,
int  offset,
int  length,
IPEndPoint  peer 
)

◆ SendData() [2/2]

void NobleConnect.Turn.TurnExtension.SendData ( byte[]  data,
int  offset,
int  length,
IPEndPoint  peer,
IPEndPoint  target,
IPEndPoint  source 
)

Send some data from a Turn client, over a relay, to a Turn peer

You'll have to know the server reflexive IP Address and Port of the peer you want to send data to. This is the address that the peer receives in response to a Bind Request. How you get the peer address to the client is up to the application developer. For a game this would mean some sort of matchmaking server.

Parameters
data
offset
length
peer

◆ SendRefreshRequest()

Transaction<Message> NobleConnect.Turn.TurnExtension.SendRefreshRequest ( int  lifetime = 60,
int  refreshTime = 30,
Action< Message onSuccess = null,
Action< Message onFailure = null 
)

Member Data Documentation

◆ allocationEndPoint

IPEndPoint NobleConnect.Turn.TurnExtension.allocationEndPoint

The relay allocation endpoints associated with this stun controller

◆ numConsecutiveTimesAllocationLost

int NobleConnect.Turn.TurnExtension.numConsecutiveTimesAllocationLost = 0

Property Documentation

◆ TurnServerEndpoint

IPEndPoint NobleConnect.Turn.TurnExtension.TurnServerEndpoint
getset