tinydtls  0.8.6
peer.h
Go to the documentation of this file.
1 /*******************************************************************************
2  *
3  * Copyright (c) 2011, 2012, 2013, 2014, 2015 Olaf Bergmann (TZI) and others.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
7  *
8  * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
9  * and the Eclipse Distribution License is available at
10  * http://www.eclipse.org/org/documents/edl-v10.php.
11  *
12  * Contributors:
13  * Olaf Bergmann - initial API and implementation
14  * Hauke Mehrtens - memory optimization, ECC integration
15  *
16  *******************************************************************************/
17 
23 #ifndef _DTLS_PEER_H_
24 #define _DTLS_PEER_H_
25 
26 #include <sys/types.h>
27 
28 #include "tinydtls.h"
29 #include "global.h"
30 #include "session.h"
31 
32 #include "state.h"
33 #include "crypto.h"
34 
35 #ifndef DTLS_PEERS_NOHASH
36 #include "uthash.h"
37 #endif /* DTLS_PEERS_NOHASH */
38 
40 
44 typedef struct dtls_peer_t {
45 #ifdef DTLS_PEERS_NOHASH
46  struct dtls_peer_t *next;
47 #else /* DTLS_PEERS_NOHASH */
49 #endif /* DTLS_PEERS_NOHASH */
50 
58 } dtls_peer_t;
59 
61 {
62  if (peer->security_params[0] && peer->security_params[0]->epoch == epoch) {
63  return peer->security_params[0];
64  } else if (peer->security_params[1] && peer->security_params[1]->epoch == epoch) {
65  return peer->security_params[1];
66  } else {
67  return NULL;
68  }
69 }
70 
72 {
73  return peer->security_params[0];
74 }
75 
77 {
78  if (peer->security_params[1])
80 
82  if (!peer->security_params[1]) {
83  return NULL;
84  }
85  peer->security_params[1]->epoch = peer->security_params[0]->epoch + 1;
86  return peer->security_params[1];
87 }
88 
90 {
91  dtls_security_parameters_t * security0 = peer->security_params[0];
92  dtls_security_parameters_t * security1 = peer->security_params[1];
93 
94  if (!security0 || !security1 || security0->epoch < security1->epoch)
95  return;
96 
97  dtls_security_free(security1);
98  peer->security_params[1] = NULL;
99 }
100 
101 static inline void dtls_security_params_switch(dtls_peer_t *peer)
102 {
103  dtls_security_parameters_t * security = peer->security_params[1];
104 
105  peer->security_params[1] = peer->security_params[0];
106  peer->security_params[0] = security;
107 }
108 
109 void peer_init(void);
110 
123 
125 void dtls_free_peer(dtls_peer_t *peer);
126 
128 static inline dtls_state_t dtls_peer_state(const dtls_peer_t *peer) {
129  return peer->state;
130 }
131 
136 static inline int dtls_peer_is_connected(const dtls_peer_t *peer) {
137  return peer->state == DTLS_STATE_CONNECTED;
138 }
139 
140 #endif /* _DTLS_PEER_H_ */
static dtls_state_t dtls_peer_state(const dtls_peer_t *peer)
Definition: peer.h:128
public tinydtls API
void peer_init(void)
Definition: peer.c:23
dtls_state_t
Definition: state.h:32
struct dtls_peer_t dtls_peer_t
dtls_state_t state
Definition: peer.h:54
static dtls_security_parameters_t * dtls_security_params_epoch(dtls_peer_t *peer, uint16_t epoch)
Definition: peer.h:60
dtls_peer_t * dtls_new_peer(const session_t *session)
Definition: peer.c:64
session_t session
Definition: peer.h:51
static void dtls_security_params_free_other(dtls_peer_t *peer)
Definition: peer.h:89
dtls_handshake_parameters_t * handshake_params
Definition: peer.h:57
dtls_security_parameters_t * dtls_security_new(void)
Definition: crypto.c:145
static dtls_security_parameters_t * dtls_security_params(dtls_peer_t *peer)
Definition: peer.h:71
static void dtls_security_params_switch(dtls_peer_t *peer)
Definition: peer.h:101
dtls_peer_type
Definition: peer.h:39
void dtls_security_free(dtls_security_parameters_t *security)
Definition: crypto.c:164
dtls_security_parameters_t * security_params[2]
Definition: peer.h:56
state information for DTLS FSM
UT_hash_handle hh
Definition: peer.h:48
static dtls_security_parameters_t * dtls_security_params_next(dtls_peer_t *peer)
Definition: peer.h:76
void dtls_free_peer(dtls_peer_t *peer)
Definition: peer.c:33
static int dtls_peer_is_connected(const dtls_peer_t *peer)
Definition: peer.h:136
dtls_peer_type role
Definition: peer.h:53