Change DTLS connection's remote peer address (#24)

* Make it possible to change the DTLS connection's remote peer address.
Add `dtls_set_peer` function

* Add `dtls_peer` getter function
Change `dtls_set_peer` signature, leave comparison of the remote address up to the user application

* Fix typo in docstring
This commit is contained in:
Lennart Grahl 2016-11-02 13:56:30 +01:00 committed by Alfred E. Heggestad
parent afa2f1e21e
commit a627951aeb
2 changed files with 33 additions and 0 deletions

View file

@ -78,3 +78,5 @@ int dtls_accept(struct tls_conn **ptc, struct tls *tls,
int dtls_send(struct tls_conn *tc, struct mbuf *mb);
void dtls_set_handlers(struct tls_conn *tc, dtls_estab_h *estabh,
dtls_recv_h *recvh, dtls_close_h *closeh, void *arg);
const struct sa *dtls_peer(const struct tls_conn *tc);
void dtls_set_peer(struct tls_conn *tc, const struct sa *peer);

View file

@ -651,6 +651,37 @@ void dtls_set_handlers(struct tls_conn *tc, dtls_estab_h *estabh,
}
/**
* Get the remote peer of a DTLS Connection
*
* @param tc DTLS Connection
*
* @return Remote peer
*/
const struct sa *dtls_peer(const struct tls_conn *tc)
{
return tc ? &tc->peer : NULL;
}
/**
* Set the remote peer of a DTLS Connection
*
* @param tc DTLS Connection
* @param peer Peer address
*/
void dtls_set_peer(struct tls_conn *tc, const struct sa *peer)
{
if (!tc || !peer)
return;
hash_unlink(&tc->he);
hash_append(tc->sock->ht, sa_hash(peer, SA_ALL), &tc->he, tc);
tc->peer = *peer;
}
static void sock_destructor(void *arg)
{
struct dtls_sock *sock = arg;