tinydtls  0.8.6
peer.c
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 
18 #include "global.h"
19 #include "peer.h"
20 #include "dtls_debug.h"
21 
22 #ifndef WITH_CONTIKI
23 void peer_init(void)
24 {
25 }
26 
27 static inline dtls_peer_t *
29  return (dtls_peer_t *)malloc(sizeof(dtls_peer_t));
30 }
31 
32 void
37  free(peer);
38 }
39 #else /* WITH_CONTIKI */
40 
41 #include "memb.h"
42 MEMB(peer_storage, dtls_peer_t, DTLS_PEER_MAX);
43 
44 void
45 peer_init(void) {
46  memb_init(&peer_storage);
47 }
48 
49 static inline dtls_peer_t *
50 dtls_malloc_peer(void) {
51  return memb_alloc(&peer_storage);
52 }
53 
54 void
59  memb_free(&peer_storage, peer);
60 }
61 #endif /* WITH_CONTIKI */
62 
64 dtls_new_peer(const session_t *session) {
66 
67  peer = dtls_malloc_peer();
68  if (peer) {
69  memset(peer, 0, sizeof(dtls_peer_t));
70  memcpy(&peer->session, session, sizeof(session_t));
72 
73  if (!peer->security_params[0]) {
74  dtls_free_peer(peer);
75  return NULL;
76  }
77 
78  dtls_dsrv_log_addr(DTLS_LOG_DEBUG, "dtls_new_peer", session);
79  }
80 
81  return peer;
82 }
void dtls_handshake_free(dtls_handshake_parameters_t *handshake)
Definition: crypto.c:136
session_t session
Definition: peer.h:51
information about peers in a DTLS session
dtls_handshake_parameters_t * handshake_params
Definition: peer.h:57
dtls_peer_t * peer
Definition: netq.h:53
void peer_init(void)
Definition: peer.c:23
void dtls_dsrv_log_addr(log_t level, const char *name, const session_t *addr)
Definition: dtls_debug.c:278
dtls_security_parameters_t * dtls_security_new(void)
Definition: crypto.c:145
void dtls_free_peer(dtls_peer_t *peer)
Definition: peer.c:33
void dtls_security_free(dtls_security_parameters_t *security)
Definition: crypto.c:164
dtls_security_parameters_t * security_params[2]
Definition: peer.h:56
static dtls_peer_t * dtls_malloc_peer(void)
Definition: peer.c:28
dtls_peer_t * dtls_new_peer(const session_t *session)
Definition: peer.c:64