@@ -48,6 +48,8 @@ public class DTLSWontNegotiateV10 {
48
48
private static final String DTLS = "DTLS" ;
49
49
private static final String DTLSV_1_2 = "DTLSv1.2" ;
50
50
51
+ private static final int READ_TIMEOUT_SECS = Integer .getInteger ("readtimeout" , 30 );
52
+
51
53
public static void main (String [] args ) throws Exception {
52
54
if (args [0 ].equals (DTLSV_1_0 )) {
53
55
SecurityUtils .removeFromDisabledTlsAlgs (DTLSV_1_0 );
@@ -63,20 +65,43 @@ public static void main(String[] args) throws Exception {
63
65
} else {
64
66
// server process
65
67
// args: protocol
66
- try (DTLSServer server = new DTLSServer (args [0 ])) {
67
- List <String > command = List .of (
68
- Path .of (System .getProperty ("java.home" ), "bin" , "java" ).toString (),
69
- "DTLSWontNegotiateV10" ,
70
- // if server is "DTLS" then the client should be v1.0 and vice versa
71
- args [0 ].equals (DTLS ) ? DTLSV_1_0 : DTLS ,
72
- Integer .toString (server .getListeningPortNumber ())
73
- );
74
-
75
- ProcessBuilder builder = new ProcessBuilder (command );
76
- Process p = builder .inheritIO ().start ();
77
- server .run ();
78
- p .destroy ();
79
- System .out .println ("Success: DTLSv1.0 connection was not established." );
68
+ final int totalAttempts = 5 ;
69
+ int tries ;
70
+ for (tries = 0 ; tries < totalAttempts ; ++tries ) {
71
+ try {
72
+ System .out .printf ("Starting server %d/%d attempts%n" , tries +1 , totalAttempts );
73
+ runServer (args [0 ]);
74
+ break ;
75
+ } catch (SocketTimeoutException exc ) {
76
+ System .out .println ("The server timed-out waiting for packets from the client." );
77
+ }
78
+ }
79
+ if (tries == totalAttempts ) {
80
+ throw new RuntimeException ("The server/client communications timed-out after " + totalAttempts + " tries." );
81
+ }
82
+ }
83
+ }
84
+
85
+ private static void runServer (String protocol ) throws Exception {
86
+ // args: protocol
87
+ Process clientProcess = null ;
88
+ try (DTLSServer server = new DTLSServer (protocol )) {
89
+ List <String > command = List .of (
90
+ Path .of (System .getProperty ("java.home" ), "bin" , "java" ).toString (),
91
+ "DTLSWontNegotiateV10" ,
92
+ // if server is "DTLS" then the client should be v1.0 and vice versa
93
+ protocol .equals (DTLS ) ? DTLSV_1_0 : DTLS ,
94
+ Integer .toString (server .getListeningPortNumber ())
95
+ );
96
+
97
+ ProcessBuilder builder = new ProcessBuilder (command );
98
+ clientProcess = builder .inheritIO ().start ();
99
+ server .run ();
100
+ System .out .println ("Success: DTLSv1.0 connection was not established." );
101
+
102
+ } finally {
103
+ if (clientProcess != null ) {
104
+ clientProcess .destroy ();
80
105
}
81
106
}
82
107
}
@@ -89,6 +114,9 @@ private static class DTLSClient extends DTLSEndpoint {
89
114
public DTLSClient (String protocol , int portNumber ) throws Exception {
90
115
super (true , protocol );
91
116
remotePort = portNumber ;
117
+ socket .setSoTimeout (READ_TIMEOUT_SECS * 1000 );
118
+ log ("Client listening on port " + socket .getLocalPort ()
119
+ + ". Sending data to server port " + remotePort );
92
120
log ("Enabled protocols: " + String .join (" " , engine .getEnabledProtocols ()));
93
121
}
94
122
@@ -287,6 +315,8 @@ private static class DTLSServer extends DTLSEndpoint implements AutoCloseable {
287
315
288
316
public DTLSServer (String protocol ) throws Exception {
289
317
super (false , protocol );
318
+ socket .setSoTimeout (READ_TIMEOUT_SECS * 1000 );
319
+ log ("Server listening on port: " + socket .getLocalPort ());
290
320
log ("Enabled protocols: " + String .join (" " , engine .getEnabledProtocols ()));
291
321
}
292
322
1 commit comments
openjdk-notifier[bot] commentedon Jun 23, 2024
Review
Issues