From fc33da579874f81621521875f9e4cffda0a327b1 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Sat, 10 Mar 2007 11:19:11 +0000 Subject: Started working on sample TURN client git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@1053 74dad513-b988-da41-8d7b-12977e46ad98 --- pjlib-util/include/pjlib-util.h | 3 +- pjlib-util/include/pjlib-util/stun_auth.h | 6 +- pjlib-util/include/pjlib-util/stun_endpoint.h | 6 +- pjlib-util/include/pjlib-util/stun_msg.h | 6 +- pjlib-util/include/pjlib-util/stun_session.h | 5 +- pjlib-util/include/pjlib-util/stun_transaction.h | 6 +- pjlib-util/include/pjlib-util/turn_client.h | 132 +++++++++++++++++++++++ 7 files changed, 148 insertions(+), 16 deletions(-) create mode 100644 pjlib-util/include/pjlib-util/turn_client.h (limited to 'pjlib-util/include') diff --git a/pjlib-util/include/pjlib-util.h b/pjlib-util/include/pjlib-util.h index 6c4f871a..3ad0c7d1 100644 --- a/pjlib-util/include/pjlib-util.h +++ b/pjlib-util/include/pjlib-util.h @@ -1,4 +1,4 @@ -/* $Id */ +/* $Id$ */ /* * Copyright (C)2003-2007 Benny Prijono * @@ -54,6 +54,7 @@ #include #include #include +/*#include */ /* Old STUN */ #include diff --git a/pjlib-util/include/pjlib-util/stun_auth.h b/pjlib-util/include/pjlib-util/stun_auth.h index 2e0f81ee..49b2acbb 100644 --- a/pjlib-util/include/pjlib-util/stun_auth.h +++ b/pjlib-util/include/pjlib-util/stun_auth.h @@ -16,8 +16,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef __PJ_STUN_AUTH_H__ -#define __PJ_STUN_AUTH_H__ +#ifndef __PJLIB_UTIL_STUN_AUTH_H__ +#define __PJLIB_UTIL_STUN_AUTH_H__ /** * @file stun_auth.h @@ -271,5 +271,5 @@ void pj_stun_calc_md5_key(pj_uint8_t digest[16], PJ_END_DECL -#endif /* __PJ_STUN_AUTH_H__ */ +#endif /* __PJLIB_UTIL_STUN_AUTH_H__ */ diff --git a/pjlib-util/include/pjlib-util/stun_endpoint.h b/pjlib-util/include/pjlib-util/stun_endpoint.h index f6e12115..b341309a 100644 --- a/pjlib-util/include/pjlib-util/stun_endpoint.h +++ b/pjlib-util/include/pjlib-util/stun_endpoint.h @@ -16,8 +16,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef __PJ_STUN_ENDPOINT_H__ -#define __PJ_STUN_ENDPOINT_H__ +#ifndef __PJLIB_UTIL_STUN_ENDPOINT_H__ +#define __PJLIB_UTIL_STUN_ENDPOINT_H__ /** * @file stun_endpoint.h @@ -113,5 +113,5 @@ PJ_DECL(pj_status_t) pj_stun_endpoint_destroy(pj_stun_endpoint *endpt); PJ_END_DECL -#endif /* __PJ_STUN_ENDPOINT_H__ */ +#endif /* __PJLIB_UTIL_STUN_ENDPOINT_H__ */ diff --git a/pjlib-util/include/pjlib-util/stun_msg.h b/pjlib-util/include/pjlib-util/stun_msg.h index b9b9275d..f7f4d086 100644 --- a/pjlib-util/include/pjlib-util/stun_msg.h +++ b/pjlib-util/include/pjlib-util/stun_msg.h @@ -16,8 +16,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef __PJ_STUN_MSG_H__ -#define __PJ_STUN_MSG_H__ +#ifndef __PJLIB_UTIL_STUN_MSG_H__ +#define __PJLIB_UTIL_STUN_MSG_H__ /** * @file stun_msg.h @@ -1529,5 +1529,5 @@ PJ_DECL(pj_status_t) pj_stun_msg_add_binary_attr(pj_pool_t *pool, PJ_END_DECL -#endif /* __PJ_STUN_MSG_H__ */ +#endif /* __PJLIB_UTIL_STUN_MSG_H__ */ diff --git a/pjlib-util/include/pjlib-util/stun_session.h b/pjlib-util/include/pjlib-util/stun_session.h index 81fc5640..fa18dc3a 100644 --- a/pjlib-util/include/pjlib-util/stun_session.h +++ b/pjlib-util/include/pjlib-util/stun_session.h @@ -55,12 +55,11 @@ typedef struct pj_stun_session_cb /** * Callback to be called by the STUN session to send outgoing message. * - * @param tdata The STUN transmit data containing the original - * STUN message + * @param sess The STUN session. * @param pkt Packet to be sent. * @param pkt_size Size of the packet to be sent. - * @param addr_len Length of destination address. * @param dst_addr The destination address. + * @param addr_len Length of destination address. * * @return The callback should return the status of the * packet sending. diff --git a/pjlib-util/include/pjlib-util/stun_transaction.h b/pjlib-util/include/pjlib-util/stun_transaction.h index 5463d3d7..c7a5bf93 100644 --- a/pjlib-util/include/pjlib-util/stun_transaction.h +++ b/pjlib-util/include/pjlib-util/stun_transaction.h @@ -16,8 +16,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef __PJ_STUN_TRANSACTION_H__ -#define __PJ_STUN_TRANSACTION_H__ +#ifndef __PJLIB_UTIL_STUN_TRANSACTION_H__ +#define __PJLIB_UTIL_STUN_TRANSACTION_H__ /** * @file stun_transaction.h @@ -213,5 +213,5 @@ PJ_DECL(pj_status_t) pj_stun_client_tsx_on_rx_msg(pj_stun_client_tsx *tsx, PJ_END_DECL -#endif /* __PJ_STUN_TRANSACTION_H__ */ +#endif /* __PJLIB_UTIL_STUN_TRANSACTION_H__ */ diff --git a/pjlib-util/include/pjlib-util/turn_client.h b/pjlib-util/include/pjlib-util/turn_client.h new file mode 100644 index 00000000..83d8d2d6 --- /dev/null +++ b/pjlib-util/include/pjlib-util/turn_client.h @@ -0,0 +1,132 @@ +/* $Id$ */ +/* + * Copyright (C) 2003-2005 Benny Prijono + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef __PJLIB_UTIL_TURN_CLIENT_H__ +#define __PJLIB_UTIL_TURN_CLIENT_H__ + +/** + * @file turn_client.h + * @brief TURN client session. + */ + +#include + + +PJ_BEGIN_DECL + + +/** + * @defgroup PJLIB_UTIL_TURN_CLIENT TURN Client Session + * @brief Management of STUN/TURN client session + * @ingroup PJLIB_UTIL_STUN + * @{ + */ + +typedef struct pj_turn_client pj_turn_client; + +/** + * This describes TURN client config. + */ +typedef struct pj_turn_client_cb +{ + /** + * Callback to be called by the TURN session to send outgoing message. + * + * @param client The TURN client session. + * @param pkt Packet to be sent. + * @param pkt_size Size of the packet to be sent. + * @param dst_addr The destination address. + * @param addr_len Length of destination address. + * + * @return The callback should return the status of the + * packet sending. + */ + pj_status_t (*on_send_msg)(pj_turn_client *client, + const void *pkt, + pj_size_t pkt_size, + const pj_sockaddr_t *dst_addr, + unsigned addr_len); + + /** + * Callback to be called by TURN session when its state has changed. + */ + pj_status_t (*on_state_changed)(pj_turn_client *client); + +} pj_turn_client_cb; + + +/** + * Options + */ +typedef struct pj_turn_client_config +{ + int bandwidth; + int lifetime; + int sock_type; + int port; +} pj_turn_client_config; + + +PJ_INLINE(void) pj_turn_client_config_default(pj_turn_client_config *cfg) +{ + pj_bzero(cfg, sizeof(*cfg)); + cfg->bandwidth = -1; + cfg->lifetime = -1; + cfg->sock_type = -1; + cfg->port = -1; +} + + +/** + * This describes the TURN client session. + */ +struct pj_turn_client +{ + pj_pool_t *pool; + pj_stun_session *session; + pj_timer_entry alloc_timer; + pj_sockaddr_in mapped_addr; + pj_sockaddr_in relay_addr; +}; + + + + +/** + * Create the TURN client session. + */ +PJ_DECL(pj_status_t) pj_turn_client_create(pj_stun_endpoint *endpt, + const pj_turn_client_config *cfg, + const pj_turn_client_cb *cb, + pj_turn_client **p_client); + +/** + * Start the TURN client session by sending Allocate request to the server. + */ + + +/** + * @} + */ + + +PJ_END_DECL + + +#endif /* __PJLIB_UTIL_TURN_CLIENT_H__ */ + -- cgit v1.2.3