private void Dtls_OnIncomingHandshakeStarted(object Sender, RemoteEndpointEventArgs e) { IPEndPoint EP = (IPEndPoint)e.RemoteEndpoint; if (!this.dtlsStates.TryGetValue(EP, out DtlsOverUdpState State)) { State = new DtlsOverUdpState() { RemoteEndpoint = EP, Queue = new LinkedList <Tuple <byte[], UdpTransmissionEventHandler, object> >(), CurrentState = DtlsState.Handshake }; this.dtlsStates.Add(EP, State); } }
private void Dtls_OnHandshakeSuccessful(object sender, RemoteEndpointEventArgs e) { IPEndPoint EP = (IPEndPoint)e.RemoteEndpoint; if (this.dtlsStates.TryGetValue(EP, out DtlsOverUdpState State)) { State.Done(this, true); } else { State = new DtlsOverUdpState() { RemoteEndpoint = EP, Queue = new LinkedList <Tuple <byte[], UdpTransmissionEventHandler, object> >(), CurrentState = DtlsState.SessionEstablished }; this.dtlsStates.Add(EP, State); } }
/// <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); } }