/** * Process regex requests. * * @param cls closure * @param server the initialized server * @param cfg configuration to use */ static void run (void *cls, struct GNUNET_SERVER_Handle *server, const struct GNUNET_CONFIGURATION_Handle *cfg) { static const struct GNUNET_SERVER_MessageHandler handlers[] = { {&handle_announce, NULL, GNUNET_MESSAGE_TYPE_REGEX_ANNOUNCE, 0}, {&handle_search, NULL, GNUNET_MESSAGE_TYPE_REGEX_SEARCH, 0}, {NULL, NULL, 0, 0} }; my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg); if (NULL == my_private_key) { GNUNET_SCHEDULER_shutdown (); return; } dht = GNUNET_DHT_connect (cfg, 1024); if (NULL == dht) { GNUNET_free (my_private_key); my_private_key = NULL; GNUNET_SCHEDULER_shutdown (); return; } GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL); nc = GNUNET_SERVER_notification_context_create (server, 1); stats = GNUNET_STATISTICS_create ("regex", cfg); GNUNET_SERVER_add_handlers (server, handlers); GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); }
/** * Start handling requests from clients. * * @param server server used to accept clients from. */ void GST_clients_start (struct GNUNET_SERVER_Handle *server) { static const struct GNUNET_SERVER_MessageHandler handlers[] = { {&clients_handle_start, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_START, sizeof (struct StartMessage)}, {&clients_handle_hello, NULL, GNUNET_MESSAGE_TYPE_HELLO, 0}, {&clients_handle_send, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, 0}, {&clients_handle_request_connect, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT, sizeof (struct TransportRequestConnectMessage)}, {&clients_handle_address_to_string, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING, 0}, {&clients_handle_monitor_peers, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST, sizeof (struct PeerMonitorMessage)}, {&clients_handle_monitor_validation, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST, sizeof (struct ValidationMonitorMessage)}, {&GST_blacklist_handle_init, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT, sizeof (struct GNUNET_MessageHeader)}, {&GST_blacklist_handle_reply, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY, sizeof (struct BlacklistMessage)}, {&GST_manipulation_set_metric, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC, 0}, {NULL, NULL, 0, 0} }; peer_nc = GNUNET_SERVER_notification_context_create (server, 0); val_nc = GNUNET_SERVER_notification_context_create (server, 0); GNUNET_SERVER_add_handlers (server, handlers); GNUNET_SERVER_disconnect_notify (server, &client_disconnect_notification, NULL); }
/** * Start up peerinfo service. * * @param cls closure * @param server the initialized server * @param cfg configuration to use */ static void run (void *cls, struct GNUNET_SERVER_Handle *server, const struct GNUNET_CONFIGURATION_Handle *cfg) { static const struct GNUNET_SERVER_MessageHandler handlers[] = { {&handle_hello, NULL, GNUNET_MESSAGE_TYPE_HELLO, 0}, {&handle_get, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_GET, sizeof (struct ListPeerMessage)}, {&handle_get_all, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL, sizeof (struct GNUNET_MessageHeader)}, {&handle_notify, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY, sizeof (struct GNUNET_MessageHeader)}, {NULL, NULL, 0, 0} }; char *peerdir; char *ip; hostmap = GNUNET_CONTAINER_multihashmap_create (1024); stats = GNUNET_STATISTICS_create ("peerinfo", cfg); notify_list = GNUNET_SERVER_notification_context_create (server, 0); GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg, "peerinfo", "HOSTS", &networkIdDirectory)); GNUNET_DISK_directory_create (networkIdDirectory); GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, &cron_scan_directory_data_hosts, NULL); GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, &cron_clean_data_hosts, NULL); GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, NULL); GNUNET_SERVER_add_handlers (server, handlers); ip = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR); GNUNET_asprintf (&peerdir, "%shellos", ip); GNUNET_free (ip); GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Importing HELLOs from `%s'\n"), peerdir); GNUNET_DISK_directory_scan (peerdir, &hosts_directory_scan_callback, NULL); GNUNET_free (peerdir); }
/** * Process GNS requests. * * @param cls closure) * @param server the initialized server * @param c configuration to use */ static void run (void *cls, struct GNUNET_SERVER_Handle *server, const struct GNUNET_CONFIGURATION_Handle *c) { GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Initializing GNS\n"); char* keyfile; struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey; unsigned long long max_parallel_bg_queries = 0; unsigned long long default_lookup_timeout_secs = 0; int ignore_pending = GNUNET_NO; static const struct GNUNET_SERVER_MessageHandler handlers[] = { {&handle_shorten, NULL, GNUNET_MESSAGE_TYPE_GNS_SHORTEN, 0}, {&handle_lookup, NULL, GNUNET_MESSAGE_TYPE_GNS_LOOKUP, 0}, {&handle_get_authority, NULL, GNUNET_MESSAGE_TYPE_GNS_GET_AUTH, 0} }; GNS_cfg = c; if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c, "gns", "ZONEKEY", &keyfile)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No private key for root zone specified!\n"); GNUNET_SCHEDULER_shutdown (); return; } GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Using keyfile %s for root zone.\n", keyfile); zone_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); GNUNET_CRYPTO_rsa_key_get_public (zone_key, &pkey); GNUNET_CRYPTO_short_hash(&pkey, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone_hash); GNUNET_free(keyfile); /** * handle to our local namestore */ namestore_handle = GNUNET_NAMESTORE_connect(c); if (NULL == namestore_handle) { //FIXME do error handling; GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to the namestore!\n"); GNUNET_SCHEDULER_shutdown (); return; } auto_import_pkey = GNUNET_NO; if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (c, "gns", "AUTO_IMPORT_PKEY")) { GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Automatic PKEY import is enabled.\n"); auto_import_pkey = GNUNET_YES; } dht_max_update_interval = GNUNET_GNS_DHT_MAX_UPDATE_INTERVAL; if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (c, "gns", "ZONE_PUT_INTERVAL", &dht_max_update_interval)) { GNUNET_log(GNUNET_ERROR_TYPE_INFO, "DHT zone update interval: %d\n", dht_max_update_interval); } max_record_put_interval = 1; if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (c, "gns", "RECORD_PUT_INTERVAL", &max_record_put_interval)) { GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Record put interval: %d\n", max_record_put_interval); } if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (c, "gns", "MAX_PARALLEL_BACKGROUND_QUERIES", &max_parallel_bg_queries)) { GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Number of allowed parallel background queries: %d\n", max_parallel_bg_queries); } if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (c, "gns", "AUTO_IMPORT_CONFIRMATION_REQ")) { GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Auto import requires user confirmation\n"); ignore_pending = GNUNET_YES; } if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(c, "gns", "DEFAULT_LOOKUP_TIMEOUT", &default_lookup_timeout_secs)) { GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Default lookup timeout: %ds\n", default_lookup_timeout_secs); default_lookup_timeout = GNUNET_TIME_relative_multiply( GNUNET_TIME_UNIT_SECONDS, default_lookup_timeout_secs); } /** * handle to the dht */ dht_handle = GNUNET_DHT_connect(c, //max_parallel_bg_queries); //FIXME get ht_len from cfg 1024); if (NULL == dht_handle) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not connect to DHT!\n"); } if (gns_resolver_init(namestore_handle, dht_handle, zone_hash, max_parallel_bg_queries, ignore_pending) == GNUNET_SYSERR) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Unable to initialize resolver!\n"); GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); return; } if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (c, "gns", "HIJACK_DNS")) { GNUNET_log(GNUNET_ERROR_TYPE_INFO, "DNS hijacking enabled... connecting to service.\n"); if (gns_interceptor_init(zone_hash, zone_key, c) == GNUNET_SYSERR) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to enable the dns interceptor!\n"); } } /** * Schedule periodic put * for our records * We have roughly an hour for all records; */ record_put_interval = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1); zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_start, NULL); GNUNET_SERVER_add_handlers (server, handlers); //FIXME //GNUNET_SERVER_disconnect_notify (server, // &client_disconnect_notification, // NULL); nc = GNUNET_SERVER_notification_context_create (server, 1); GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, NULL); }
/** * Handle network size estimate clients. * * @param cls closure * @param server the initialized server * @param c configuration to use */ static void run (void *cls, struct GNUNET_SERVER_Handle *server, const struct GNUNET_CONFIGURATION_Handle *c) { static const struct GNUNET_SERVER_MessageHandler handlers[] = { {&handle_start_message, NULL, GNUNET_MESSAGE_TYPE_IDENTITY_START, sizeof (struct GNUNET_MessageHeader)}, {&handle_get_default_message, NULL, GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT, 0}, {&handle_set_default_message, NULL, GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT, 0}, {&handle_create_message, NULL, GNUNET_MESSAGE_TYPE_IDENTITY_CREATE, 0}, {&handle_rename_message, NULL, GNUNET_MESSAGE_TYPE_IDENTITY_RENAME, 0}, {&handle_delete_message, NULL, GNUNET_MESSAGE_TYPE_IDENTITY_DELETE, 0}, {NULL, NULL, 0, 0} }; cfg = c; if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "identity", "EGODIR", &ego_directory)) { GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "identity", "EGODIR"); GNUNET_SCHEDULER_shutdown (); return; } if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "identity", "SUBSYSTEM_CFG", &subsystem_cfg_file)) { GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "identity", "SUBSYSTEM_CFG"); GNUNET_SCHEDULER_shutdown (); return; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loading subsystem configuration `%s'\n", subsystem_cfg_file); subsystem_cfg = GNUNET_CONFIGURATION_create (); if ( (GNUNET_YES == GNUNET_DISK_file_test (subsystem_cfg_file)) && (GNUNET_OK != GNUNET_CONFIGURATION_parse (subsystem_cfg, subsystem_cfg_file)) ) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to parse subsystem identity configuration file `%s'\n"), subsystem_cfg_file); GNUNET_SCHEDULER_shutdown (); return; } stats = GNUNET_STATISTICS_create ("identity", cfg); GNUNET_SERVER_add_handlers (server, handlers); nc = GNUNET_SERVER_notification_context_create (server, 1); if (GNUNET_OK != GNUNET_DISK_directory_create (ego_directory)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to create directory `%s' for storing egos\n"), ego_directory); } GNUNET_DISK_directory_scan (ego_directory, &process_ego_file, NULL); GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, NULL); }