package org.bouncycastle.crypto.tls;

import java.security.SecureRandom;

public class DTLSProtocolHandler {

    private final SecureRandom secureRandom;

    public DTLSProtocolHandler(SecureRandom secureRandom) {
        this.secureRandom = secureRandom;
    }

    public DTLSTransport connect(DatagramTransport transport) {
        return new DTLSTransport(transport);
        
//        if (client_version.isDTLS())
//        {
//            for (int cipherSuite : offeredCipherSuites)
//            {
//                switch (cipherSuite)
//                {
//                case CipherSuite.TLS_RSA_EXPORT_WITH_RC4_40_MD5:
//                case CipherSuite.TLS_RSA_WITH_RC4_128_MD5:
//                case CipherSuite.TLS_RSA_WITH_RC4_128_SHA:
//                case CipherSuite.TLS_DH_anon_EXPORT_WITH_RC4_40_MD5:
//                case CipherSuite.TLS_DH_anon_WITH_RC4_128_MD5:
//                case CipherSuite.TLS_PSK_WITH_RC4_128_SHA:
//                case CipherSuite.TLS_DHE_PSK_WITH_RC4_128_SHA:
//                case CipherSuite.TLS_RSA_PSK_WITH_RC4_128_SHA:
//                case CipherSuite.TLS_ECDH_ECDSA_WITH_RC4_128_SHA:
//                case CipherSuite.TLS_ECDHE_ECDSA_WITH_RC4_128_SHA:
//                case CipherSuite.TLS_ECDH_RSA_WITH_RC4_128_SHA:
//                case CipherSuite.TLS_ECDHE_RSA_WITH_RC4_128_SHA:
//                case CipherSuite.TLS_ECDH_anon_WITH_RC4_128_SHA:
//                    throw new IllegalStateException("Client offered an RC4 cipher suite: RC4 MUST NOT be used with DTLS");
//                }
//            }
//        }
    }
}

@@ -303,16 +303,34 @@
 connect(
+TlsClient client, 
 Datagram
@@ -349,24 +349,246 @@
 ansport) %7B%0D%0A
+%0D%0A        if (client == null)%0D%0A            throw new IllegalArgumentException(%22'tlsClient' cannot be null%22);%0D%0A%0D%0A        TlsClientContextImpl clientContext = createClientContext();%0D%0A%0D%0A        client.init(clientContext);%0D%0A%0D%0A
         retu
@@ -621,24 +621,16 @@
 port);%0D%0A
-        
 %0D%0A//    
@@ -1863,11 +1863,437 @@
 %0A    %7D%0D%0A
+    %0D%0A    private TlsClientContextImpl createClientContext()%0D%0A    %7B%0D%0A        SecurityParameters securityParameters = new SecurityParameters();%0D%0A%0D%0A        securityParameters.clientRandom = new byte%5B32%5D;%0D%0A        secureRandom.nextBytes(securityParameters.clientRandom);%0D%0A        TlsUtils.writeGMTUnixTime(securityParameters.clientRandom, 0);%0D%0A%0D%0A        return new TlsClientContextImpl(secureRandom, securityParameters);%0D%0A    %7D%0D%0A
 %7D%0D%0A

Add TlsClient to connect and initialise client context