static PseudoTcpWriteResult
-pseudo_tcp_socket_write_packet (PseudoTcpSocket *socket,
+pseudo_tcp_socket_write_packet (PseudoTcpSocket *psocket,
const gchar *buffer, guint32 len, gpointer user_data)
{
Component *component = user_data;
static void
priv_add_new_candidate_discovery_stun (NiceAgent *agent,
- NiceSocket *socket, NiceAddress server,
+ NiceSocket *nicesock, NiceAddress server,
Stream *stream, guint component_id)
{
CandidateDiscovery *cdisco;
cdisco = g_slice_new0 (CandidateDiscovery);
cdisco->type = NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE;
- cdisco->nicesock = socket;
+ cdisco->nicesock = nicesock;
cdisco->server = server;
cdisco->stream = stream;
cdisco->component = stream_find_component_by_id (stream, component_id);
static void
priv_add_new_candidate_discovery_turn (NiceAgent *agent,
- NiceSocket *socket, TurnServer *turn,
+ NiceSocket *nicesock, TurnServer *turn,
Stream *stream, guint component_id)
{
CandidateDiscovery *cdisco;
if (turn->type == NICE_RELAY_TYPE_TURN_UDP) {
if (agent->compatibility == NICE_COMPATIBILITY_GOOGLE) {
- NiceAddress addr = socket->addr;
+ NiceAddress addr = nicesock->addr;
NiceSocket *new_socket;
nice_address_set_port (&addr, 0);
if (new_socket) {
_priv_set_socket_tos (agent, new_socket, stream->tos);
component_attach_socket (component, new_socket);
- socket = new_socket;
+ nicesock = new_socket;
}
}
- cdisco->nicesock = socket;
+ cdisco->nicesock = nicesock;
} else {
NiceAddress proxy_server;
- socket = NULL;
+ nicesock = NULL;
if (agent->proxy_type != NICE_PROXY_TYPE_NONE &&
agent->proxy_ip != NULL &&
nice_address_set_from_string (&proxy_server, agent->proxy_ip)) {
nice_address_set_port (&proxy_server, agent->proxy_port);
- socket = nice_tcp_bsd_socket_new (agent->main_context, &proxy_server);
+ nicesock = nice_tcp_bsd_socket_new (agent->main_context, &proxy_server);
- if (socket) {
- _priv_set_socket_tos (agent, socket, stream->tos);
+ if (nicesock) {
+ _priv_set_socket_tos (agent, nicesock, stream->tos);
if (agent->proxy_type == NICE_PROXY_TYPE_SOCKS5) {
- socket = nice_socks5_socket_new (socket, &turn->server,
+ nicesock = nice_socks5_socket_new (nicesock, &turn->server,
agent->proxy_username, agent->proxy_password);
} else if (agent->proxy_type == NICE_PROXY_TYPE_HTTP){
- socket = nice_http_socket_new (socket, &turn->server,
+ nicesock = nice_http_socket_new (nicesock, &turn->server,
agent->proxy_username, agent->proxy_password);
} else {
- nice_socket_free (socket);
- socket = NULL;
+ nice_socket_free (nicesock);
+ nicesock = NULL;
}
}
}
- if (socket == NULL) {
- socket = nice_tcp_bsd_socket_new (agent->main_context, &turn->server);
+ if (nicesock == NULL) {
+ nicesock = nice_tcp_bsd_socket_new (agent->main_context, &turn->server);
- if (socket)
- _priv_set_socket_tos (agent, socket, stream->tos);
+ if (nicesock)
+ _priv_set_socket_tos (agent, nicesock, stream->tos);
}
/* The TURN server may be invalid or not listening */
- if (socket == NULL)
+ if (nicesock == NULL)
return;
if (turn->type == NICE_RELAY_TYPE_TURN_TLS &&
agent->compatibility == NICE_COMPATIBILITY_GOOGLE) {
- socket = nice_pseudossl_socket_new (socket);
+ nicesock = nice_pseudossl_socket_new (nicesock);
}
- cdisco->nicesock = nice_tcp_turn_socket_new (socket,
+ cdisco->nicesock = nice_tcp_turn_socket_new (nicesock,
agent_to_turn_socket_compatibility (agent));
component_attach_socket (component, cdisco->nicesock);
} else {
for (i = agent->local_addresses; i; i = i->next) {
NiceAddress *addr = i->data;
- NiceAddress *dup = nice_address_dup (addr);
+ NiceAddress *dupaddr = nice_address_dup (addr);
- local_addresses = g_slist_append (local_addresses, dup);
+ local_addresses = g_slist_append (local_addresses, dupaddr);
}
}
NICEAPI_EXPORT gboolean
nice_agent_add_local_address (NiceAgent *agent, NiceAddress *addr)
{
- NiceAddress *dup;
+ NiceAddress *dupaddr;
agent_lock();
- dup = nice_address_dup (addr);
- nice_address_set_port (dup, 0);
- agent->local_addresses = g_slist_append (agent->local_addresses, dup);
+ dupaddr = nice_address_dup (addr);
+ nice_address_set_port (dupaddr, 0);
+ agent->local_addresses = g_slist_append (agent->local_addresses, dupaddr);
agent_unlock_and_emit (agent);
return TRUE;
NiceAgent *agent,
Stream *stream,
Component *component,
- NiceSocket *socket,
+ NiceSocket *nicesock,
NiceInputMessage *message)
{
NiceAddress from;
message->from = &from;
}
- retval = nice_socket_recv_messages (socket, message, 1);
+ retval = nice_socket_recv_messages (nicesock, message, 1);
nice_debug ("%s: Received %d valid messages of length %" G_GSIZE_FORMAT
- " from base socket %p.", G_STRFUNC, retval, message->length, socket);
+ " from base socket %p.", G_STRFUNC, retval, message->length, nicesock);
if (retval == 0) {
retval = RECV_WOULD_BLOCK; /* EWOULDBLOCK */
gchar tmpbuf[INET6_ADDRSTRLEN];
nice_address_to_string (message->from, tmpbuf);
nice_debug ("Agent %p : Packet received on local socket %d from [%s]:%u (%" G_GSSIZE_FORMAT " octets).", agent,
- g_socket_get_fd (socket->fileno), tmpbuf,
+ g_socket_get_fd (nicesock->fileno), tmpbuf,
nice_address_get_port (message->from), message->length);
}
if (cand->type == NICE_CANDIDATE_TYPE_RELAYED &&
cand->stream_id == stream->id &&
cand->component_id == component->id) {
- retval = nice_turn_socket_parse_recv_message (cand->sockptr, &socket,
+ retval = nice_turn_socket_parse_recv_message (cand->sockptr, &nicesock,
message);
break;
}
if (stun_message_validate_buffer_length (big_buf, big_buf_len,
(agent->compatibility != NICE_COMPATIBILITY_OC2007 &&
agent->compatibility != NICE_COMPATIBILITY_OC2007R2)) == (gint) big_buf_len &&
- conn_check_handle_inbound_stun (agent, stream, component, socket,
+ conn_check_handle_inbound_stun (agent, stream, component, nicesock,
message->from, (gchar *) big_buf, big_buf_len)) {
/* Handled STUN message. */
nice_debug ("%s: Valid STUN packet received.", G_STRFUNC);
}
gboolean
-component_io_cb (GSocket *socket, GIOCondition condition, gpointer user_data)
+component_io_cb (GSocket *gsocket, GIOCondition condition, gpointer user_data)
{
SocketSource *socket_source = user_data;
Component *component;
/* This takes ownership of the socket.
* It creates and attaches a source to the component’s context. */
void
-component_attach_socket (Component *component, NiceSocket *socket)
+component_attach_socket (Component *component, NiceSocket *nicesock)
{
GSList *l;
SocketSource *socket_source;
g_assert (component != NULL);
- g_assert (socket != NULL);
+ g_assert (nicesock != NULL);
g_assert (component->ctx != NULL);
* or discovery failure, which are both unrecoverable states.
*
* An empty socket_sources corresponds to age 0. */
- l = g_slist_find_custom (component->socket_sources, socket,
+ l = g_slist_find_custom (component->socket_sources, nicesock,
_find_socket_source);
if (l != NULL) {
socket_source = l->data;
} else {
socket_source = g_slice_new0 (SocketSource);
- socket_source->socket = socket;
+ socket_source->socket = nicesock;
socket_source->component = component;
component->socket_sources =
g_slist_prepend (component->socket_sources, socket_source);
* If the @socket doesn’t exist in this @component, do nothing.
*/
void
-component_detach_socket (Component *component, NiceSocket *socket)
+component_detach_socket (Component *component, NiceSocket *nicesock)
{
GSList *l;
SocketSource *socket_source;
- nice_debug ("Detach socket %p.", socket);
+ nice_debug ("Detach socket %p.", nicesock);
/* Find the SocketSource for the socket. */
l = g_slist_find_custom (component->socket_sources, socket,
NiceCandidate *candidate);
void
-component_attach_socket (Component *component, NiceSocket *socket);
+component_attach_socket (Component *component, NiceSocket *nsocket);
void
-component_detach_socket (Component *component, NiceSocket *socket);
+component_detach_socket (Component *component, NiceSocket *nsocket);
void
component_detach_all_sockets (Component *component);
void
*
* @pre (rcand == NULL || nice_address_equal(rcand->addr, toaddr) == TRUE)
*/
-static void priv_reply_to_conn_check (NiceAgent *agent, Stream *stream, Component *component, NiceCandidate *rcand, const NiceAddress *toaddr, NiceSocket *socket, size_t rbuf_len, uint8_t *rbuf, gboolean use_candidate)
+static void priv_reply_to_conn_check (NiceAgent *agent, Stream *stream, Component *component, NiceCandidate *rcand, const NiceAddress *toaddr, NiceSocket *sockptr, size_t rbuf_len, uint8_t *rbuf, gboolean use_candidate)
{
g_assert (rcand == NULL || nice_address_equal(&rcand->addr, toaddr) == TRUE);
nice_debug ("Agent %p : STUN-CC RESP to '%s:%u', socket=%u, len=%u, cand=%p (c-id:%u), use-cand=%d.", agent,
tmpbuf,
nice_address_get_port (toaddr),
- g_socket_get_fd(socket->fileno),
+ g_socket_get_fd(sockptr->fileno),
(unsigned)rbuf_len,
rcand, component->id,
(int)use_candidate);
}
- nice_socket_send (socket, toaddr, rbuf_len, (const gchar*)rbuf);
+ nice_socket_send (sockptr, toaddr, rbuf_len, (const gchar*)rbuf);
if (rcand) {
/* note: upon successful check, make the reserve check immediately */
- priv_schedule_triggered_check (agent, stream, component, socket, rcand, use_candidate);
+ priv_schedule_triggered_check (agent, stream, component, sockptr, rcand, use_candidate);
if (use_candidate)
priv_mark_pair_nominated (agent, stream, component, rcand);
* @return non-zero on error, zero on success
*/
static int priv_store_pending_check (NiceAgent *agent, Component *component,
- const NiceAddress *from, NiceSocket *socket, uint8_t *username,
+ const NiceAddress *from, NiceSocket *sockptr, uint8_t *username,
uint16_t username_len, uint32_t priority, gboolean use_candidate)
{
IncomingCheck *icheck;
icheck = g_slice_new0 (IncomingCheck);
component->incoming_checks = g_slist_append (component->incoming_checks, icheck);
icheck->from = *from;
- icheck->local_socket = socket;
+ icheck->local_socket = sockptr;
icheck->priority = priority;
icheck->use_candidate = use_candidate;
icheck->username_len = username_len;
* @param agent self pointer
* @param stream stream the packet is related to
* @param component component the packet is related to
- * @param socket socket from which the packet was received
+ * @param nicesock socket from which the packet was received
* @param from address of the sender
* @param buf message contents
* @param buf message length
* @return XXX (what FALSE means exactly?)
*/
gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream,
- Component *component, NiceSocket *socket, const NiceAddress *from,
+ Component *component, NiceSocket *nicesock, const NiceAddress *from,
gchar *buf, guint len)
{
union {
for (i = agent->discovery_list; i; i = i->next) {
CandidateDiscovery *d = i->data;
if (d->stream == stream && d->component == component &&
- d->nicesock == socket) {
+ d->nicesock == nicesock) {
valid = stun_agent_validate (&d->stun_agent, &req,
(uint8_t *) buf, len, conncheck_stun_validater, &validater_data);
for (i = agent->refresh_list; i; i = i->next) {
CandidateRefresh *r = i->data;
nice_debug ("Comparing %p to %p, %p to %p and %p and %p to %p", r->stream,
- stream, r->component, component, r->nicesock, r->relay_socket, socket);
+ stream, r->component, component, r->nicesock, r->relay_socket, nicesock);
if (r->stream == stream && r->component == component &&
- (r->nicesock == socket || r->relay_socket == socket)) {
+ (r->nicesock == nicesock || r->relay_socket == nicesock)) {
valid = stun_agent_validate (&r->stun_agent, &req,
(uint8_t *) buf, len, conncheck_stun_validater, &validater_data);
nice_debug ("Validating gave %d", valid);
rbuf_len = stun_agent_build_unknown_attributes_error (&agent->stun_agent,
&msg, rbuf, rbuf_len, &req);
if (rbuf_len != 0)
- nice_socket_send (socket, from, rbuf_len, (const gchar*)rbuf);
+ nice_socket_send (nicesock, from, rbuf_len, (const gchar*)rbuf);
}
return TRUE;
}
rbuf_len = stun_agent_finish_message (&agent->stun_agent, &msg, NULL, 0);
if (rbuf_len > 0 && agent->compatibility != NICE_COMPATIBILITY_MSN &&
agent->compatibility != NICE_COMPATIBILITY_OC2007)
- nice_socket_send (socket, from, rbuf_len, (const gchar*)rbuf);
+ nice_socket_send (nicesock, from, rbuf_len, (const gchar*)rbuf);
}
return TRUE;
}
rbuf_len = stun_agent_finish_message (&agent->stun_agent, &msg, NULL, 0);
if (rbuf_len > 0 && agent->compatibility != NICE_COMPATIBILITY_MSN &&
agent->compatibility != NICE_COMPATIBILITY_OC2007)
- nice_socket_send (socket, from, rbuf_len, (const gchar*)rbuf);
+ nice_socket_send (nicesock, from, rbuf_len, (const gchar*)rbuf);
}
return TRUE;
}
nice_debug ("Agent %p : No matching remote candidate for incoming check ->"
"peer-reflexive candidate.", agent);
remote_candidate = discovery_learn_remote_peer_reflexive_candidate (
- agent, stream, component, priority, from, socket,
+ agent, stream, component, priority, from, nicesock,
local_candidate,
remote_candidate2 ? remote_candidate2 : remote_candidate);
if(remote_candidate)
}
priv_reply_to_conn_check (agent, stream, component, remote_candidate,
- from, socket, rbuf_len, rbuf, use_candidate);
+ from, nicesock, rbuf_len, rbuf, use_candidate);
if (component->remote_candidates == NULL) {
/* case: We've got a valid binding request to a local candidate
* we get information about the remote candidates */
/* step: send a reply immediately but postpone other processing */
- priv_store_pending_check (agent, component, from, socket,
+ priv_store_pending_check (agent, component, from, nicesock,
username, username_len, priority, use_candidate);
}
} else {
/* step: let's try to match the response to an existing check context */
if (trans_found != TRUE)
trans_found = priv_map_reply_to_conn_check_request (agent, stream,
- component, socket, from, local_candidate, remote_candidate, &req);
+ component, nicesock, from, local_candidate, remote_candidate, &req);
/* step: let's try to match the response to an existing discovery */
if (trans_found != TRUE)
/* Check whether any of the component’s FDs are pollable. */
for (i = component->socket_sources; i != NULL; i = i->next) {
SocketSource *socket_source = i->data;
- NiceSocket *socket = socket_source->socket;
+ NiceSocket *nicesock = socket_source->socket;
- if (g_socket_condition_check (socket->fileno, G_IO_IN) != 0) {
+ if (g_socket_condition_check (nicesock->fileno, G_IO_IN) != 0) {
retval = TRUE;
break;
}
/* Check whether any of the component’s FDs are pollable. */
for (i = component->socket_sources; i != NULL; i = i->next) {
SocketSource *socket_source = i->data;
- NiceSocket *socket = socket_source->socket;
+ NiceSocket *nicesock = socket_source->socket;
- if (g_socket_condition_check (socket->fileno, G_IO_OUT) != 0) {
+ if (g_socket_condition_check (nicesock->fileno, G_IO_OUT) != 0) {
retval = TRUE;
break;
}
pseudo_tcp_socket_recv(PseudoTcpSocket *self, char * buffer, size_t len)
{
PseudoTcpSocketPrivate *priv = self->priv;
- gsize read;
+ gsize bytesread;
gsize available_space;
if (priv->state != TCP_ESTABLISHED) {
if (len == 0)
return 0;
- read = pseudo_tcp_fifo_read (&priv->rbuf, (guint8 *) buffer, len);
+ bytesread = pseudo_tcp_fifo_read (&priv->rbuf, (guint8 *) buffer, len);
// If there's no data in |m_rbuf|.
- if (read == 0) {
+ if (bytesread == 0) {
priv->bReadEnable = TRUE;
priv->error = EWOULDBLOCK;
return -1;
}
}
- return read;
+ return bytesread;
}
gint
}
static gint
-socket_recv_messages (NiceSocket *socket,
+socket_recv_messages (NiceSocket *nicesock,
NiceInputMessage *recv_messages, guint n_recv_messages)
{
guint i;
for (i = 0; i < n_recv_messages; i++) {
gssize len;
- len = socket_recv_message (socket, &recv_messages[i]);
+ len = socket_recv_message (nicesock, &recv_messages[i]);
recv_messages[i].length = MAX (len, 0);
if (len < 0)
* Guaranteed to be in the interval [1, 1 << 16). ((1 << 16) is the maximum
* message size.) */
static gsize
-generate_buffer_size (BufferSizeStrategy strategy, GRand *rand,
+generate_buffer_size (BufferSizeStrategy strategy, GRand *grand,
gsize buffer_offset)
{
switch (strategy) {
return CLAMP (1L << buffer_offset, 1, (1 << 16) - 1);
case BUFFER_SIZE_RANDOM:
- return g_rand_int_range (rand, 1, 1 << 16);
+ return g_rand_int_range (grand, 1, 1 << 16);
default:
g_assert_not_reached ();
* byte. Guaranteed to be in the interval [1, 100], where 100 was chosen
* arbitrarily.*/
static guint
-generate_buffer_count (BufferCountStrategy strategy, GRand *rand,
+generate_buffer_count (BufferCountStrategy strategy, GRand *grand,
gsize buffer_offset)
{
switch (strategy) {
return 2;
case BUFFER_COUNT_RANDOM:
- return g_rand_int_range (rand, 1, 100 + 1);
+ return g_rand_int_range (grand, 1, 100 + 1);
default:
g_assert_not_reached ();
* @buffer_offset-th byte. Guaranteed to be in the interval [1, 100], where 100
* was chosen arbitrarily.*/
static guint
-generate_message_count (MessageCountStrategy strategy, GRand *rand,
+generate_message_count (MessageCountStrategy strategy, GRand *grand,
guint buffer_index)
{
switch (strategy) {
return 2;
case MESSAGE_COUNT_RANDOM:
- return g_rand_int_range (rand, 1, 100 + 1);
+ return g_rand_int_range (grand, 1, 100 + 1);
default:
g_assert_not_reached ();