/// <summary> /// TODO: Documentation ConnectionBind /// </summary> /// <param name="connectionId"></param> /// <param name="username"></param> /// <param name="password"></param> public void ConnectionBind(StunAttribute connectionId, String username, String password) { this.TurnTcpManager = new TurnManager(this.StunClient.ServerEP, this.StunClient.ProtocolType, this.StunClient.ClientCertificate, this.StunClient.RemoteCertificateValidation); this.TurnTcpManager.OnAllocateSucceed += (object sender, TurnAllocation allocation, StunMessage sentMsg, StunMessage receivedMsg) => { StunMessage msg = new StunMessage(StunMethodType.ConnectionBind, StunMethodClass.Request, StunUtilities.NewTransactionId); msg.Turn.ConnectionId = connectionId; msg.Stun.Username = new UTF8Attribute(StunAttributeType.Username, allocation.Username); msg.Stun.Realm = new UTF8Attribute(StunAttributeType.Realm, allocation.Realm); msg.Stun.Nonce = new UTF8Attribute(StunAttributeType.Nonce, allocation.Nonce); msg.AddMessageIntegrity(allocation.Password, true); this.TurnTcpManager.StunClient.BeginSendMessage(msg, this.TurnTcpManager.StunClient.Socket); }; this.TurnTcpManager.OnConnectionBindSucceed += (object sender, Socket connectedSocket, StunMessage receivedMsg) => { this.TurnTcpManager.Allocations.Clear(); this.TurnTcpManager.StunClient.Cancel = true; if (this.OnConnectionBindSucceed != null) { this.OnConnectionBindSucceed(sender, connectedSocket, receivedMsg); } }; this.TurnTcpManager.Connect(); this.TurnTcpManager.Allocate(username, password); }
/// <summary> /// TODO: Documentation CreatePermission /// </summary> /// <param name="xorPeerAddress"></param> /// <param name="allocation"></param> public void CreatePermission(XorMappedAddress xorPeerAddress, TurnAllocation allocation) { StunMessage msg = new StunMessage(StunMethodType.CreatePermission, StunMethodClass.Request, StunUtilities.NewTransactionId); msg.Turn.XorPeerAddress = xorPeerAddress; msg.Stun.Username = new UTF8Attribute(StunAttributeType.Username, allocation.Username); msg.Stun.Realm = new UTF8Attribute(StunAttributeType.Realm, allocation.Realm); msg.Stun.Nonce = new UTF8Attribute(StunAttributeType.Nonce, allocation.Nonce); msg.AddMessageIntegrity(allocation.Password, true); this.StunClient.BeginSendMessage(msg, allocation); }
/// <summary> /// TODO: Documentation RefreshAllocation /// </summary> /// <param name="allocation"></param> /// <param name="lifeTime"></param> public void RefreshAllocation(TurnAllocation allocation, UInt32 lifeTime) { StunMessage msg = new StunMessage(StunMethodType.Refresh, StunMethodClass.Request, StunUtilities.NewTransactionId); msg.Stun.Username = new UTF8Attribute(StunAttributeType.Username, allocation.Username); msg.Stun.Realm = new UTF8Attribute(StunAttributeType.Realm, allocation.Realm); msg.Stun.Nonce = new UTF8Attribute(StunAttributeType.Nonce, allocation.Nonce); msg.Turn.LifeTime = new StunAttribute(StunAttributeType.LifeTime, BitConverter.GetBytes(StunUtilities.ReverseBytes(lifeTime))); msg.AddMessageIntegrity(allocation.Password, true); this.StunClient.BeginSendMessage(msg, null); }
/// <summary> /// TODO: Documentation AllocateRetry /// </summary> /// <param name="receivedMsg"></param> /// <param name="username"></param> /// <param name="password"></param> private void AllocateRetry(StunMessage receivedMsg, String username, String password) { StunMessage msg = new StunMessage(StunMethodType.Allocate, StunMethodClass.Request, StunUtilities.NewTransactionId); msg.Turn.RequestedTransport = new StunAttribute(StunAttributeType.RequestedTransport, BitConverter.GetBytes(StunMessage.CODE_POINT_TCP)); msg.Stun.Username = new UTF8Attribute(StunAttributeType.Username, username); msg.Stun.Realm = receivedMsg.Stun.Realm; msg.Stun.Nonce = receivedMsg.Stun.Nonce; msg.AddMessageIntegrity(password, true); this.StunClient.BeginSendMessage(msg, password); }
/// <summary> /// TODO: Documentation SendIndication /// </summary> /// <param name="xorPeerAddress"></param> /// <param name="data"></param> /// <param name="allocation"></param> public void SendIndication(XorMappedAddress xorPeerAddress, byte[] data, TurnAllocation allocation) { StunMessage msg = new StunMessage(StunMethodType.Send, StunMethodClass.Indication, StunUtilities.NewTransactionId); msg.Turn.XorPeerAddress = xorPeerAddress; msg.Turn.Data = new StunAttribute(StunAttributeType.Data, data); msg.Stun.Username = new UTF8Attribute(StunAttributeType.Username, allocation.Username); msg.Stun.Realm = new UTF8Attribute(StunAttributeType.Realm, allocation.Realm); msg.Stun.Nonce = new UTF8Attribute(StunAttributeType.Nonce, allocation.Nonce); msg.AddMessageIntegrity(allocation.Password, true); this.StunClient.BeginSendMessage(msg, null); }
/// <summary> /// TODO: Documentation ConnectionBind /// </summary> /// <param name="connectionId"></param> /// <param name="username"></param> /// <param name="password"></param> public void ConnectionBind(StunAttribute connectionId, String username, String password) { this.TurnTcpManager = new TurnManager(this.StunClient.ServerEP, this.StunClient.ProtocolType, this.StunClient.ClientCertificate, this.StunClient.RemoteCertificateValidation); this.TurnTcpManager.OnAllocateSucceed += (object sender, TurnAllocation allocation, StunMessage sentMsg, StunMessage receivedMsg) => { StunMessage msg = new StunMessage(StunMethodType.ConnectionBind, StunMethodClass.Request, StunUtilities.NewTransactionId); msg.Turn.ConnectionId = connectionId; msg.Stun.Username = new UTF8Attribute(StunAttributeType.Username, allocation.Username); msg.Stun.Realm = new UTF8Attribute(StunAttributeType.Realm, allocation.Realm); msg.Stun.Nonce = new UTF8Attribute(StunAttributeType.Nonce, allocation.Nonce); msg.AddMessageIntegrity(allocation.Password, true); this.TurnTcpManager.StunClient.BeginSendMessage(msg, this.TurnTcpManager.StunClient.Socket); }; this.TurnTcpManager.OnConnectionBindSucceed += (object sender, Socket connectedSocket, StunMessage receivedMsg) => { this.TurnTcpManager.Allocations.Clear(); this.TurnTcpManager.StunClient.Cancel = true; if (this.OnConnectionBindSucceed != null) this.OnConnectionBindSucceed(sender, connectedSocket, receivedMsg); }; this.TurnTcpManager.Connect(); this.TurnTcpManager.Allocate(username, password); }
/// <summary> /// TODO: Documentation BindChannel /// </summary> /// <param name="channelNumber"></param> /// <param name="xorPeerAddress"></param> /// <param name="allocation"></param> public void BindChannel(byte[] channelNumber, XorMappedAddress xorPeerAddress, TurnAllocation allocation) { StunMessage msg = new StunMessage(StunMethodType.ChannelBind, StunMethodClass.Request, StunUtilities.NewTransactionId); msg.Turn.ChannelNumber = new StunAttribute(StunAttributeType.ChannelNumber, channelNumber); msg.Turn.XorPeerAddress = xorPeerAddress; msg.Stun.Username = new UTF8Attribute(StunAttributeType.Username, allocation.Username); msg.Stun.Realm = new UTF8Attribute(StunAttributeType.Realm, allocation.Realm); msg.Stun.Nonce = new UTF8Attribute(StunAttributeType.Nonce, allocation.Nonce); msg.AddMessageIntegrity(allocation.Password, true); this.StunClient.BeginSendMessage(msg, allocation); }