1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
/*
* Copyright (C) 2009 Free Software Foundation (copyright assignement pending)
*
* Author: Jonathan Bastien-Filiatrault
*
* This file is part of GNUTLS.
*
* The GNUTLS library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA
*
*/
#ifndef DTLS_H
# define DTLS_H
#include "gnutls_int.h"
#include "gnutls_buffers.h"
#include "gnutls_mbuffers.h"
int _dtls_transmit(gnutls_session_t session);
int _dtls_retransmit(gnutls_session_t session);
int _dtls_record_check(gnutls_session_t session, uint64 * _seq);
#define MAX_DTLS_TIMEOUT 60000
/* returns true or false depending on whether we need to
* handle asynchronously handshake data.
*/
inline static int _dtls_is_async(gnutls_session_t session)
{
if ((session->security_parameters.entity == GNUTLS_SERVER && session->internals.resumed == RESUME_FALSE) ||
(session->security_parameters.entity == GNUTLS_CLIENT && session->internals.resumed == RESUME_TRUE))
return 1;
else
return 0;
}
inline static void _dtls_async_timer_init(gnutls_session_t session)
{
if (_dtls_is_async(session))
{
_gnutls_dtls_log ("DTLS[%p]: Initializing timer for handshake state.\n", session);
session->internals.dtls.async_term = time(0) + MAX_DTLS_TIMEOUT/1000;
}
else
session->internals.dtls.async_term = 0;
}
inline static void _dtls_async_timer_delete(gnutls_session_t session)
{
if (session->internals.dtls.async_term != 0)
{
_gnutls_dtls_log ("DTLS[%p]: Deinitializing handshake state.\n", session);
_gnutls_handshake_io_buffer_clear (session);
session->internals.dtls.async_term = 0; /* turn off "timer" */
}
}
/* Checks whether it is time to terminate the timer
*/
inline static void _dtls_async_timer_check(gnutls_session_t session)
{
if (!IS_DTLS(session))
return;
if (session->internals.dtls.async_term != 0)
{
time_t now = time(0);
/* check if we need to expire the queued handshake data */
if (now > session->internals.dtls.async_term)
{
_dtls_async_timer_delete(session);
}
}
}
/* Returns non-zero if the async timer is active */
inline static int _dtls_async_timer_active(gnutls_session_t session)
{
if (!IS_DTLS(session))
return 0;
return session->internals.dtls.async_term;
}
#endif
|