/**
* Port number, in network byte order.
*/
- uint16_t u_port GNUNET_PACKED;
+ uint16_t port GNUNET_PACKED;
};
/**
/**
* Port number, in network byte order.
*/
- uint16_t u6_port GNUNET_PACKED;
+ uint16_t port GNUNET_PACKED;
};
#endif
};
+/**
+ * Context for address to string conversion.
+ */
+struct PrettyPrinterContext
+{
+ /**
+ * Function to call with the result.
+ */
+ GNUNET_TRANSPORT_AddressStringCallback asc;
+
+ /**
+ * Clsoure for 'asc'.
+ */
+ void *asc_cls;
+
+ /**
+ * Port to add after the IP address.
+ */
+ uint16_t port;
+};
+
/**
* Function called for a quick conversion of the binary address to
"Freeing context for peer `%s'\n",
GNUNET_i2s(&pc->identity));
#endif
- GNUNET_CONTAINER_multihashmap_remove (plugin->peers, &pc->identity.hashPubKey, pc);
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_remove (plugin->peers,
+ &pc->identity.hashPubKey,
+ pc));
while (ps!=NULL)
{
plugin->env->session_end(plugin, &pc->identity, ps);
t4->ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr;
- t4->u_port = htons (plugin->port_inbound);
+ t4->port = htons (plugin->port_inbound);
if (plugin->bind4_address != NULL) {
if (0 == memcmp(&plugin->bind4_address->sin_addr, &bnd_cmp, sizeof (struct in_addr)))
{
memcpy (&t6->ipv6_addr,
&((struct sockaddr_in6 *) addr)->sin6_addr,
sizeof (struct in6_addr));
- t6->u6_port = htons (plugin->port_inbound);
+ t6->port = htons (plugin->port_inbound);
plugin->env->notify_address(plugin->env->cls,
GNUNET_YES,
t6, sizeof (struct IPv6HttpAddress));
memcpy (&t6->ipv6_addr,
&((struct sockaddr_in6 *) addr)->sin6_addr,
sizeof (struct in6_addr));
- t6->u6_port = htons (plugin->port_inbound);
+ t6->port = htons (plugin->port_inbound);
GNUNET_CONTAINER_DLL_insert(plugin->ipv6_addr_head,plugin->ipv6_addr_tail,t6);
plugin->env->notify_address(plugin->env->cls,
const struct GNUNET_MessageHeader *message)
{
struct Session *ps = cls;
- struct HTTP_PeerContext *pc = ps->peercontext;
+ struct HTTP_PeerContext *pc;
struct GNUNET_TIME_Relative delay;
GNUNET_assert(ps != NULL);
+ pc = ps->peercontext;
GNUNET_assert(pc != NULL);
#if DEBUG_HTTP
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
addrin = (const struct sockaddr_in*) client_addr;
inet_ntop(addrin->sin_family, &(addrin->sin_addr),address,INET_ADDRSTRLEN);
memcpy(&ipv4addr.ipv4_addr,&(addrin->sin_addr),sizeof(struct in_addr));
- ipv4addr.u_port = addrin->sin_port;
+ ipv4addr.port = addrin->sin_port;
addr = &ipv4addr;
addr_len = sizeof(struct IPv4HttpAddress);
}
addrin6 = (const struct sockaddr_in6 *) client_addr;
inet_ntop(addrin6->sin6_family, &(addrin6->sin6_addr),address,INET6_ADDRSTRLEN);
memcpy(&ipv6addr.ipv6_addr,&(addrin6->sin6_addr),sizeof(struct in6_addr));
- ipv6addr.u6_port = addrin6->sin6_port;
+ ipv6addr.port = addrin6->sin6_port;
addr = &ipv6addr;
addr_len = sizeof(struct IPv6HttpAddress);
}
ps->send_force_disconnect = GNUNET_NO;
ps->pending_msgs_head = NULL;
ps->pending_msgs_tail = NULL;
- ps->peercontext=pc;
+ ps->peercontext = pc;
ps->session_id = pc->session_id_counter;
ps->queue_length_cur = 0;
ps->queue_length_max = GNUNET_SERVER_MAX_MESSAGE_SIZE;
}
+/**
+ * Append our port and forward the result.
+ *
+ * @param cls the 'struct PrettyPrinterContext*'
+ * @param hostname hostname part of the address
+ */
+static void
+append_port (void *cls, const char *hostname)
+{
+ struct PrettyPrinterContext *ppc = cls;
+ char *ret;
+
+ if (hostname == NULL)
+ {
+ ppc->asc (ppc->asc_cls, NULL);
+ GNUNET_free (ppc);
+ return;
+ }
+ GNUNET_asprintf (&ret, "%s://%s:%d", PROTOCOL_PREFIX, hostname, ppc->port);
+
+ ppc->asc (ppc->asc_cls, ret);
+ GNUNET_free (ret);
+}
+
+
+
/**
* Convert the transports address to a nice, human-readable
* format.
GNUNET_TRANSPORT_AddressStringCallback
asc, void *asc_cls)
{
+ struct PrettyPrinterContext *ppc;
+ const void *sb;
+ size_t sbs;
+ struct sockaddr_in a4;
+ struct sockaddr_in6 a6;
const struct IPv4HttpAddress *t4;
const struct IPv6HttpAddress *t6;
- struct sockaddr_in a4;
- struct sockaddr_in6 a6;
- char * address;
- char * ret;
- unsigned int port;
- unsigned int res;
+ uint16_t port;
- GNUNET_assert(cls !=NULL);
if (addrlen == sizeof (struct IPv6HttpAddress))
{
- address = GNUNET_malloc (INET6_ADDRSTRLEN);
t6 = addr;
- a6.sin6_addr = t6->ipv6_addr;
- inet_ntop(AF_INET6, &(a6.sin6_addr),address,INET6_ADDRSTRLEN);
- port = ntohs(t6->u6_port);
+ memset (&a6, 0, sizeof (a6));
+ a6.sin6_family = AF_INET6;
+ a6.sin6_port = t6->port;
+ memcpy (&a6.sin6_addr,
+ &t6->ipv6_addr,
+ sizeof (struct in6_addr));
+ port = ntohs (t6->port);
+ sb = &a6;
+ sbs = sizeof (a6);
}
else if (addrlen == sizeof (struct IPv4HttpAddress))
{
- address = GNUNET_malloc (INET_ADDRSTRLEN);
t4 = addr;
- a4.sin_addr.s_addr = t4->ipv4_addr;
- inet_ntop(AF_INET, &(a4.sin_addr),address,INET_ADDRSTRLEN);
- port = ntohs(t4->u_port);
+ memset (&a4, 0, sizeof (a4));
+ a4.sin_family = AF_INET;
+ a4.sin_port = t4->port;
+ a4.sin_addr.s_addr = t4->ipv4_addr;
+ port = ntohs (t4->ipv4_addr);
+ sb = &a4;
+ sbs = sizeof (a4);
}
else
{
asc (asc_cls, NULL);
return;
}
- res = GNUNET_asprintf(&ret,"%s://%s:%u/", PROTOCOL_PREFIX, address, port);
- GNUNET_free (address);
- GNUNET_assert(res != 0);
- asc (asc_cls, ret);
- GNUNET_free_non_null (ret);
+ ppc = GNUNET_malloc (sizeof (struct PrettyPrinterContext));
+ ppc->asc = asc;
+ ppc->asc_cls = asc_cls;
+ ppc->port = port;
+ GNUNET_RESOLVER_hostname_get (sb,
+ sbs,
+ !numeric, timeout, &append_port, ppc);
}
t6 = addr;
a6.sin6_addr = t6->ipv6_addr;
inet_ntop(AF_INET6, &(a6.sin6_addr),address,INET6_ADDRSTRLEN);
- port = ntohs(t6->u6_port);
+ port = ntohs(t6->port);
}
else if (addrlen == sizeof (struct IPv4HttpAddress))
{
t4 = addr;
a4.sin_addr.s_addr = t4->ipv4_addr;
inet_ntop(AF_INET, &(a4.sin_addr),address,INET_ADDRSTRLEN);
- port = ntohs(t4->u_port);
+ port = ntohs(t4->port);
}
else
{
memcpy (&t4->ipv4_addr,
&((struct sockaddr_in *) addr)->sin_addr,
sizeof (struct in_addr));
- t4->u_port = htons (plugin->port_inbound);
+ t4->port = htons (plugin->port_inbound);
w_t4->addr = t4;
memcpy (&t6->ipv6_addr,
&((struct sockaddr_in6 *) addr)->sin6_addr,
sizeof (struct in6_addr));
- t6->u6_port = htons (plugin->port_inbound);
+ t6->port = htons (plugin->port_inbound);
w_t6->addr = t6;
}
}
-#if 0
-/**
- * Notify transport service about address
- *
- * @param cls the plugin
- * @param tc unused
- */
-static void
-address_notification (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- struct Plugin *plugin = cls;
-
- GNUNET_OS_network_interfaces_list (&process_interfaces, plugin);
-}
-#endif
-
/**
* Exit point from the plugin.
*/
GNUNET_free_non_null (plugin->bind4_address);
GNUNET_free_non_null (plugin->bind6_address);
- GNUNET_free_non_null(plugin->bind_hostname);
+ GNUNET_free_non_null (plugin->bind_hostname);
#if BUILD_HTTPS
GNUNET_free_non_null (plugin->crypto_init);
GNUNET_free_non_null (plugin->cert);
struct stat fstat;
char * text = NULL;
- if (0!=STAT(file, &fstat))
- return NULL;
+ if (0 != STAT(file, &fstat))
+ return NULL;
text = GNUNET_malloc (fstat.st_size+1);
gn_file = GNUNET_DISK_file_open(file, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_USER_READ);
if (gn_file==NULL)
GNUNET_free(text);
return NULL;
}
- if (GNUNET_SYSERR == GNUNET_DISK_file_read(gn_file, text, fstat.st_size))
+ if (GNUNET_SYSERR == GNUNET_DISK_file_read (gn_file, text, fstat.st_size))
{
- GNUNET_free(text);
- GNUNET_DISK_file_close(gn_file);
+ GNUNET_free (text);
+ GNUNET_DISK_file_close (gn_file);
return NULL;
}
text[fstat.st_size] = '\0';
- GNUNET_DISK_file_close(gn_file);
+ GNUNET_DISK_file_close (gn_file);
return text;
}
#endif
&plugin->my_ascii_hash_ident);
- if (GNUNET_CONFIGURATION_have_value (env->cfg, "TRANSPORT", "NEIGHBOUR_LIMIT"))
- {
- GNUNET_CONFIGURATION_get_value_number (env->cfg,
- "TRANSPORT",
- "NEIGHBOUR_LIMIT",
- &tneigh);
- }
- else
- {
- tneigh = -1;
- }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_number (env->cfg,
+ component_name,
+ "MAX_CONNECTIONS",
+ &tneigh))
+ tneigh = 128;
plugin->max_connect_per_transport = tneigh;
#if BUILD_HTTPS
/* Reading HTTPS crypto related configuration */
- /* Get crypto init string from config */
- if (GNUNET_CONFIGURATION_have_value (env->cfg,
- "transport-https", "CRYPTO_INIT"))
- {
- GNUNET_CONFIGURATION_get_value_string (env->cfg,
- "transport-https",
- "CRYPTO_INIT",
- &plugin->crypto_init);
- }
- else
+ /* Get crypto init string from config */
+ if ( (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (env->cfg,
+ "transport-https",
+ "CRYPTO_INIT",
+ &plugin->crypto_init)) ||
+ (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (env->cfg,
+ "transport-https",
+ "KEY_FILE",
+ &key_file)) ||
+ (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (env->cfg,
+ "transport-https",
+ "CERT_FILE",
+ &cert_file)) )
{
- GNUNET_asprintf(&plugin->crypto_init,"NORMAL");
- }
-
- /* Get private key file from config */
- if (GNUNET_CONFIGURATION_have_value (env->cfg,
- "transport-https", "KEY_FILE"))
- {
- GNUNET_CONFIGURATION_get_value_filename (env->cfg,
- "transport-https",
- "KEY_FILE",
- &key_file);
- }
- if (key_file==NULL)
- GNUNET_asprintf(&key_file,"https.key");
-
- /* Get private key file from config */
- if (GNUNET_CONFIGURATION_have_value (env->cfg,"transport-https", "CERT_FILE"))
- {
- GNUNET_CONFIGURATION_get_value_filename (env->cfg,
- "transport-https",
- "CERT_FILE",
- &cert_file);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "https",
+ _("Required configuration options missing in section `%s'\n"),
+ "transport-https");
+ GNUNET_free (component_name);
+ GNUNET_free_non_null (key_file);
+ GNUNET_free_non_null (cert_file);
+ LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
+ return NULL;
}
- if (cert_file==NULL)
- GNUNET_asprintf(&cert_file,"https.cert");
-
+
/* read key & certificates from file */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Loading TLS certificate `%s' `%s'\n",
key_file, cert_file);
- plugin->key = load_certificate( key_file );
- plugin->cert = load_certificate( cert_file );
+ plugin->key = load_certificate (key_file);
+ plugin->cert = load_certificate (cert_file);
- if ((plugin->key==NULL) || (plugin->cert==NULL))
+ if ( (plugin->key==NULL) || (plugin->cert==NULL) )
{
- char * cmd;
- int ret = 0;
- GNUNET_asprintf(&cmd,
- "gnunet-transport-certificate-creation %s %s",
- key_file, cert_file);
+ struct GNUNET_OS_Process *certcreation;
+
+ GNUNET_free_non_null (plugin->key);
+ plugin->key = NULL;
+ GNUNET_free_non_null (plugin->cert);
+ plugin->cert = NULL;
+#if DEBUG_HTTP
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No usable TLS certificate found, creating certificate \n");
- ret = system(cmd);
- if (ret != 0)
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- "https",
- _("Could not create a new TLS certificate, shell script `%s' failed!\n"),cmd,
- "transport-https");
- GNUNET_free (key_file);
- GNUNET_free (cert_file);
- GNUNET_free (component_name);
- LIBGNUNET_PLUGIN_TRANSPORT_DONE(api);
- GNUNET_free (cmd);
- return NULL;
- }
- GNUNET_free (cmd);
- plugin->key = load_certificate( key_file );
- plugin->cert = load_certificate( cert_file );
- if ((plugin->key==NULL) || (plugin->cert==NULL))
+ "No usable TLS certificate found, creating certificate\n");
+#endif
+ errno = 0;
+ certcreation = GNUNET_OS_start_process (NULL, NULL,
+ "gnunet-transport-certificate-creation",
+ "gnunet-transport-certificate-creation",
+ key_file, cert_file,
+ NULL);
+ if (certcreation == NULL)
{
GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
"https",
- _("No usable TLS certificate found and creating one failed! \n"),
- "transport-https");
+ _("Could not create a new TLS certificate, program `gnunet-transport-certificate-creation' could not be started!\n"));
GNUNET_free (key_file);
GNUNET_free (cert_file);
GNUNET_free (component_name);
-
- LIBGNUNET_PLUGIN_TRANSPORT_DONE(api);
+ LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
return NULL;
}
+ GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (certcreation));
+ GNUNET_OS_process_close (certcreation);
+ plugin->key = load_certificate (key_file);
+ plugin->cert = load_certificate (cert_file);
}
+ if ( (plugin->key==NULL) || (plugin->cert==NULL) )
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "https",
+ _("No usable TLS certificate found and creating one failed!\n"),
+ "transport-https");
+ GNUNET_free (key_file);
+ GNUNET_free (cert_file);
+ GNUNET_free (component_name);
+ LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
+ return NULL;
+ }
GNUNET_free (key_file);
GNUNET_free (cert_file);
-
- GNUNET_assert((plugin->key!=NULL) && (plugin->cert!=NULL));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "TLS certificate loaded\n");
+#if DEBUG_HTTP
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "TLS certificate loaded\n");
+#endif
#endif
GNUNET_assert ((port > 0) && (port <= 65535));