Beispiel #1
0
 public void AddToQueue(byte[] Packet, UdpTransmissionEventHandler Callback, object State)
 {
     lock (this.Queue)
     {
         this.Queue.AddLast(new Tuple <byte[], UdpTransmissionEventHandler, object>(Packet,
                                                                                    Callback, State));
     }
 }
Beispiel #2
0
        /// <summary>
        /// Sends a packet to a remote endpoint.
        /// </summary>
        /// <param name="Packet">Packet to send.</param>
        /// <param name="RemoteEndpoint">Remote endpoint.</param>
        /// <param name="Credentials">Optional credentials.</param>
        /// <param name="Callback">Method to call when operation concludes.</param>
        /// <param name="State">State object to pass on to callback method.</param>
        public void Send(byte[] Packet, IPEndPoint RemoteEndpoint, IDtlsCredentials Credentials,
                         UdpTransmissionEventHandler Callback, object State)
        {
            if (this.dtlsStates.TryGetValue(RemoteEndpoint, out DtlsOverUdpState DtlsState))
            {
                switch (DtlsState.CurrentState)
                {
                case Security.DTLS.DtlsState.SessionEstablished:
                    this.dtls.SendApplicationData(Packet, RemoteEndpoint);
                    break;

                case Security.DTLS.DtlsState.Handshake:
                    DtlsState.AddToQueue(Packet, Callback, State);
                    break;

                case Security.DTLS.DtlsState.Closed:
                case Security.DTLS.DtlsState.Failed:
                case Security.DTLS.DtlsState.Created:
                default:
                    DtlsState.AddToQueue(Packet, Callback, State);
                    this.dtls.StartHandshake(RemoteEndpoint, Credentials);
                    break;
                }
            }
            else
            {
                DtlsState = new DtlsOverUdpState()
                {
                    RemoteEndpoint = RemoteEndpoint,
                    Queue          = new LinkedList <Tuple <byte[], UdpTransmissionEventHandler, object> >(),
                    CurrentState   = Security.DTLS.DtlsState.Handshake
                };

                DtlsState.AddToQueue(Packet, Callback, State);
                this.dtlsStates.Add(RemoteEndpoint, DtlsState);

                this.dtls.StartHandshake(RemoteEndpoint, Credentials);
            }
        }