struct UnixAddress
{
- uint32_t options GNUNET_PACKED;
+ uint32_t options GNUNET_PACKED;
- uint32_t addrlen GNUNET_PACKED;
+ uint32_t addrlen GNUNET_PACKED;
};
static void
unix_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
+
static struct sockaddr_un *
unix_address_to_sockaddr (const char *unixpath,
socklen_t *sock_len)
*
* @param cls closure
* @param addr binary address
- * @param addrlen length of the address
+ * @param addrlen length of the @a addr
* @return string representing the same address
*/
static const char *
-unix_address_to_string (void *cls, const void *addr, size_t addrlen)
+unix_address_to_string (void *cls,
+ const void *addr,
+ size_t addrlen)
{
static char rbuf[1024];
struct UnixAddress *ua = (struct UnixAddress *) addr;
if ((NULL == addr) || (sizeof (struct UnixAddress) > addrlen))
{
GNUNET_break(0);
- return NULL ;
+ return NULL;
}
addrstr = (char *) &ua[1];
addr_str_len = ntohl (ua->addrlen);
if (addr_str_len != addrlen - sizeof(struct UnixAddress))
{
GNUNET_break(0);
- return NULL ;
+ return NULL;
}
if ('\0' != addrstr[addr_str_len - 1])
{
GNUNET_break(0);
- return NULL ;
+ return NULL;
}
if (strlen (addrstr) + 1 != addr_str_len)
{
GNUNET_break(0);
- return NULL ;
+ return NULL;
}
off = 0;
if ('\0' == addrstr[0])
off++;
memset (rbuf, 0, sizeof (rbuf));
- GNUNET_snprintf (rbuf, sizeof (rbuf) - 1, "%s.%u.%s%.*s",
- PLUGIN_NAME,
- ntohl (ua->options),
- (off == 1) ? "@" : "",
- (int) (addr_str_len - off),
- &addrstr[off]);
-/*
- GNUNET_snprintf (rbuf, sizeof(rbuf), "%s.%u.%s", PLUGIN_NAME,
- ntohl (ua->options), addrstr);*/
+ GNUNET_snprintf (rbuf,
+ sizeof (rbuf) - 1,
+ "%s.%u.%s%.*s",
+ PLUGIN_NAME,
+ ntohl (ua->options),
+ (off == 1) ? "@" : "",
+ (int) (addr_str_len - off),
+ &addrstr[off]);
return rbuf;
}
-
-
/**
* Re-schedule the main 'select' callback (unix_plugin_select)
* for this plugin.
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Disconnecting session for peer `%s' `%s'\n",
GNUNET_i2s (&s->target),
- unix_address_to_string (NULL, s->address->address, s->address->address_length) );
+ unix_address_to_string (NULL,
+ s->address->address,
+ s->address->address_length));
plugin->env->session_end (plugin->env->cls, s->address, s);
removed = GNUNET_NO;
next = plugin->msg_head;
&get_session_it, &gsi);
if (NULL != gsi.res)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Found existing session %p for address `%s'\n",
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Found existing session %p for address `%s'\n",
gsi.res,
unix_address_to_string (NULL, address->address, address->address_length));
return gsi.res;
s = GNUNET_new (struct Session);
s->target = address->peer;
s->address = GNUNET_HELLO_address_copy (address);
+ s->plugin = plugin;
GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == s->timeout_task);
s->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
&session_timeout,
s);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Creating a new session %p for address `%s'\n",
- s, unix_address_to_string (NULL, address->address, address->address_length));
+ s,
+ unix_address_to_string (NULL,
+ address->address,
+ address->address_length));
(void) GNUNET_CONTAINER_multipeermap_put (plugin->session_map,
&address->peer, s,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
LOG (GNUNET_ERROR_TYPE_ERROR,
"Invalid session for peer `%s' `%s'\n",
GNUNET_i2s (&session->target),
- unix_address_to_string(NULL, session->address->address,
- session->address->address_length));
+ unix_address_to_string(NULL,
+ session->address->address,
+ session->address->address_length));
GNUNET_break (0);
return GNUNET_SYSERR;
}
"Sending %u bytes with session for peer `%s' `%s'\n",
msgbuf_size,
GNUNET_i2s (&session->target),
- unix_address_to_string(NULL, session->address->address,
- session->address->address_length));
+ unix_address_to_string (NULL,
+ session->address->address,
+ session->address->address_length));
ssize = sizeof (struct UNIXMessage) + msgbuf_size;
message = GNUNET_malloc (sizeof (struct UNIXMessage) + msgbuf_size);
message->header.size = htons (ssize);
GNUNET_assert (ua_len >= sizeof (struct UnixAddress));
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Received message from %s\n",
- unix_address_to_string(NULL, ua, ua_len));
+ unix_address_to_string (NULL, ua, ua_len));
GNUNET_STATISTICS_update (plugin->env->stats,
"# bytes received via UNIX",
ntohs (currhdr->size),
return GNUNET_SYSERR;
}
if ('\0' != un->sun_path[0])
- GNUNET_DISK_directory_create_for_file (un->sun_path);
+ {
+ if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (un->sun_path))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR, _("Cannot create path to `%s'\n"),
+ un->sun_path);
+ GNUNET_NETWORK_socket_close (plugin->unix_sock.desc);
+ plugin->unix_sock.desc = NULL;
+ GNUNET_free (un);
+ return GNUNET_SYSERR;
+ }
+ }
if (GNUNET_OK !=
GNUNET_NETWORK_socket_bind (plugin->unix_sock.desc, (const struct sockaddr *) un, un_len))
{
GNUNET_TRANSPORT_AddressStringCallback asc,
void *asc_cls)
{
- if ((NULL != addr) && (addrlen > 0))
- {
- asc (asc_cls, unix_address_to_string (NULL, addr, addrlen));
- }
- else if (0 == addrlen)
- {
- asc (asc_cls, TRANSPORT_SESSION_INBOUND_STRING);
- }
+ const char *ret;
+
+ if ( (NULL != addr) && (addrlen > 0))
+ ret = unix_address_to_string (NULL,
+ addr,
+ addrlen);
else
- {
- GNUNET_break (0);
- asc (asc_cls, "<invalid UNIX address>");
- }
- asc (asc_cls, NULL);
+ ret = NULL;
+ asc (asc_cls,
+ ret,
+ (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK);
+ asc (asc_cls, NULL, GNUNET_OK);
}
* Function called to convert a string address to
* a binary address.
*
- * @param cls closure ('struct Plugin*')
+ * @param cls closure (`struct Plugin *`)
* @param addr string address
* @param addrlen length of the @a addr (strlen(addr) + '\0')
* @param buf location to store the buffer
*
* @param cls the plugin
* @param key peer identity (unused)
- * @param value the 'struct Session' to disconnect
+ * @param value the `struct Session *` to disconnect
* @return #GNUNET_YES (always, continue to iterate)
*/
static int
api->get_network = &unix_get_network;
api->update_session_timeout = &unix_plugin_update_session_timeout;
sockets_created = unix_transport_server_start (plugin);
- if (0 == sockets_created)
+ if ((0 == sockets_created) || (GNUNET_SYSERR == sockets_created))
+ {
LOG (GNUNET_ERROR_TYPE_WARNING,
_("Failed to open UNIX listen socket\n"));
+ GNUNET_free (api);
+ GNUNET_free (plugin->unix_socket_path);
+ GNUNET_free (plugin);
+ return NULL;
+ }
plugin->session_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
plugin->address_update_task = GNUNET_SCHEDULER_add_now (&address_notification, plugin);
return api;