tinydtls  0.8.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
peer.c
Go to the documentation of this file.
1 /* dtls -- a very basic DTLS implementation
2  *
3  * Copyright (C) 2011--2013 Olaf Bergmann <bergmann@tzi.org>
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without
8  * restriction, including without limitation the rights to use, copy,
9  * modify, merge, publish, distribute, sublicense, and/or sell copies
10  * of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  */
25 
26 #include "global.h"
27 #include "peer.h"
28 #include "debug.h"
29 
30 #ifndef WITH_CONTIKI
31 void peer_init()
32 {
33 }
34 
35 static inline dtls_peer_t *
37  return (dtls_peer_t *)malloc(sizeof(dtls_peer_t));
38 }
39 
40 void
45  free(peer);
46 }
47 #else /* WITH_CONTIKI */
48 
49 #include "memb.h"
50 MEMB(peer_storage, dtls_peer_t, DTLS_PEER_MAX);
51 
52 void
53 peer_init() {
54  memb_init(&peer_storage);
55 }
56 
57 static inline dtls_peer_t *
59  return memb_alloc(&peer_storage);
60 }
61 
62 void
67  memb_free(&peer_storage, peer);
68 }
69 #endif /* WITH_CONTIKI */
70 
72 dtls_new_peer(const session_t *session) {
74 
75  peer = dtls_malloc_peer();
76  if (peer) {
77  memset(peer, 0, sizeof(dtls_peer_t));
78  memcpy(&peer->session, session, sizeof(session_t));
80 
81  if (!peer->security_params[0]) {
82  dtls_free_peer(peer);
83  return NULL;
84  }
85 
86  dtls_dsrv_log_addr(DTLS_LOG_DEBUG, "dtls_new_peer", session);
87  }
88 
89  return peer;
90 }
void dtls_handshake_free(dtls_handshake_parameters_t *handshake)
Definition: crypto.c:146
session_t session
Definition: peer.h:59
information about peers in a DTLS session
void dtls_dsrv_log_addr(log_t level, const char *name, const session_t *addr)
Definition: debug.c:277
static dtls_peer_t * dtls_malloc_peer()
Definition: peer.c:36
dtls_handshake_parameters_t * handshake_params
Definition: peer.h:65
dtls_peer_t * peer
Definition: netq.h:44
void dtls_free_peer(dtls_peer_t *peer)
Definition: peer.c:41
void dtls_security_free(dtls_security_parameters_t *security)
Definition: crypto.c:174
dtls_security_parameters_t * security_params[2]
Definition: peer.h:64
dtls_security_parameters_t * dtls_security_new()
Definition: crypto.c:155
void peer_init()
Definition: peer.c:31
dtls_peer_t * dtls_new_peer(const session_t *session)
Definition: peer.c:72