aboutsummaryrefslogtreecommitdiff
path: root/src/core/gnunet-service-core_kx.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-09-20 15:14:05 +0000
committerChristian Grothoff <christian@grothoff.org>2016-09-20 15:14:05 +0000
commit5663ca18885242fca4dd209898ffda9cbe675c58 (patch)
treeeba7a80df59830aefd927a5a5383e47b353d5a09 /src/core/gnunet-service-core_kx.c
parent7e835e78aa82869715c9aee96a73ba40aad3f39f (diff)
downloadgnunet-5663ca18885242fca4dd209898ffda9cbe675c58.tar.gz
gnunet-5663ca18885242fca4dd209898ffda9cbe675c58.zip
converting core service to new service API
Diffstat (limited to 'src/core/gnunet-service-core_kx.c')
-rw-r--r--src/core/gnunet-service-core_kx.c94
1 files changed, 34 insertions, 60 deletions
diff --git a/src/core/gnunet-service-core_kx.c b/src/core/gnunet-service-core_kx.c
index 6f6786d89..6743ce215 100644
--- a/src/core/gnunet-service-core_kx.c
+++ b/src/core/gnunet-service-core_kx.c
@@ -26,7 +26,6 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet-service-core_kx.h" 27#include "gnunet-service-core_kx.h"
28#include "gnunet-service-core.h" 28#include "gnunet-service-core.h"
29#include "gnunet-service-core_clients.h"
30#include "gnunet-service-core_sessions.h" 29#include "gnunet-service-core_sessions.h"
31#include "gnunet_statistics_service.h" 30#include "gnunet_statistics_service.h"
32#include "gnunet_transport_core_service.h" 31#include "gnunet_transport_core_service.h"
@@ -392,34 +391,9 @@ static struct GSC_KeyExchangeInfo *kx_tail;
392static struct GNUNET_SCHEDULER_Task *rekey_task; 391static struct GNUNET_SCHEDULER_Task *rekey_task;
393 392
394/** 393/**
395 * Notification context for all monitors. 394 * Notification context for broadcasting to monitors.
396 */ 395 */
397static struct GNUNET_SERVER_NotificationContext *nc; 396static struct GNUNET_NotificationContext *nc;
398
399
400/**
401 * Inform the given monitor about the KX state of
402 * the given peer.
403 *
404 * @param client client to inform
405 * @param kx key exchange state to inform about
406 */
407static void
408monitor_notify (struct GNUNET_SERVER_Client *client,
409 struct GSC_KeyExchangeInfo *kx)
410{
411 struct MonitorNotifyMessage msg;
412
413 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY);
414 msg.header.size = htons (sizeof (msg));
415 msg.state = htonl ((uint32_t) kx->status);
416 msg.peer = *kx->peer;
417 msg.timeout = GNUNET_TIME_absolute_hton (kx->timeout);
418 GNUNET_SERVER_notification_context_unicast (nc,
419 client,
420 &msg.header,
421 GNUNET_NO);
422}
423 397
424 398
425/** 399/**
@@ -453,9 +427,9 @@ monitor_notify_all (struct GSC_KeyExchangeInfo *kx)
453 msg.state = htonl ((uint32_t) kx->status); 427 msg.state = htonl ((uint32_t) kx->status);
454 msg.peer = *kx->peer; 428 msg.peer = *kx->peer;
455 msg.timeout = GNUNET_TIME_absolute_hton (kx->timeout); 429 msg.timeout = GNUNET_TIME_absolute_hton (kx->timeout);
456 GNUNET_SERVER_notification_context_broadcast (nc, 430 GNUNET_notification_context_broadcast (nc,
457 &msg.header, 431 &msg.header,
458 GNUNET_NO); 432 GNUNET_NO);
459 kx->last_notify_timeout = kx->timeout; 433 kx->last_notify_timeout = kx->timeout;
460} 434}
461 435
@@ -1807,12 +1781,10 @@ do_rekey (void *cls)
1807 * Initialize KX subsystem. 1781 * Initialize KX subsystem.
1808 * 1782 *
1809 * @param pk private key to use for the peer 1783 * @param pk private key to use for the peer
1810 * @param server the server of the CORE service
1811 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 1784 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
1812 */ 1785 */
1813int 1786int
1814GSC_KX_init (struct GNUNET_CRYPTO_EddsaPrivateKey *pk, 1787GSC_KX_init (struct GNUNET_CRYPTO_EddsaPrivateKey *pk)
1815 struct GNUNET_SERVER_Handle *server)
1816{ 1788{
1817 struct GNUNET_MQ_MessageHandler handlers[] = { 1789 struct GNUNET_MQ_MessageHandler handlers[] = {
1818 GNUNET_MQ_hd_fixed_size (ephemeral_key, 1790 GNUNET_MQ_hd_fixed_size (ephemeral_key,
@@ -1834,8 +1806,6 @@ GSC_KX_init (struct GNUNET_CRYPTO_EddsaPrivateKey *pk,
1834 GNUNET_MQ_handler_end() 1806 GNUNET_MQ_handler_end()
1835 }; 1807 };
1836 1808
1837 nc = GNUNET_SERVER_notification_context_create (server,
1838 1);
1839 my_private_key = pk; 1809 my_private_key = pk;
1840 GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, 1810 GNUNET_CRYPTO_eddsa_key_get_public (my_private_key,
1841 &GSC_my_identity.public_key); 1811 &GSC_my_identity.public_key);
@@ -1848,10 +1818,12 @@ GSC_KX_init (struct GNUNET_CRYPTO_EddsaPrivateKey *pk,
1848 return GNUNET_SYSERR; 1818 return GNUNET_SYSERR;
1849 } 1819 }
1850 sign_ephemeral_key (); 1820 sign_ephemeral_key ();
1821 nc = GNUNET_notification_context_create (1);
1851 rekey_task = GNUNET_SCHEDULER_add_delayed (REKEY_FREQUENCY, 1822 rekey_task = GNUNET_SCHEDULER_add_delayed (REKEY_FREQUENCY,
1852 &do_rekey, 1823 &do_rekey,
1853 NULL); 1824 NULL);
1854 mst = GNUNET_SERVER_mst_create (&deliver_message, NULL); 1825 mst = GNUNET_SERVER_mst_create (&deliver_message,
1826 NULL);
1855 transport 1827 transport
1856 = GNUNET_TRANSPORT_core_connect (GSC_cfg, 1828 = GNUNET_TRANSPORT_core_connect (GSC_cfg,
1857 &GSC_my_identity, 1829 &GSC_my_identity,
@@ -1902,7 +1874,7 @@ GSC_KX_done ()
1902 } 1874 }
1903 if (NULL != nc) 1875 if (NULL != nc)
1904 { 1876 {
1905 GNUNET_SERVER_notification_context_destroy (nc); 1877 GNUNET_notification_context_destroy (nc);
1906 nc = NULL; 1878 nc = NULL;
1907 } 1879 }
1908} 1880}
@@ -1940,34 +1912,36 @@ GSC_NEIGHBOURS_check_excess_bandwidth (const struct GSC_KeyExchangeInfo *kxinfo)
1940 * request. All current peers are returned, regardless of which 1912 * request. All current peers are returned, regardless of which
1941 * message types they accept. 1913 * message types they accept.
1942 * 1914 *
1943 * @param cls unused 1915 * @param mq message queue to add for monitoring
1944 * @param client client sending the iteration request
1945 * @param message iteration request message
1946 */ 1916 */
1947void 1917void
1948GSC_KX_handle_client_monitor_peers (void *cls, 1918GSC_KX_handle_client_monitor_peers (struct GNUNET_MQ_Handle *mq)
1949 struct GNUNET_SERVER_Client *client,
1950 const struct GNUNET_MessageHeader *message)
1951{ 1919{
1952 struct MonitorNotifyMessage done_msg; 1920 struct GNUNET_MQ_Envelope *env;
1921 struct MonitorNotifyMessage *done_msg;
1953 struct GSC_KeyExchangeInfo *kx; 1922 struct GSC_KeyExchangeInfo *kx;
1954 1923
1955 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1924 GNUNET_notification_context_add (nc,
1956 GNUNET_SERVER_notification_context_add (nc, 1925 mq);
1957 client);
1958 for (kx = kx_head; NULL != kx; kx = kx->next) 1926 for (kx = kx_head; NULL != kx; kx = kx->next)
1959 monitor_notify (client, kx); 1927 {
1960 done_msg.header.size = htons (sizeof (struct MonitorNotifyMessage)); 1928 struct GNUNET_MQ_Envelope *env;
1961 done_msg.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY); 1929 struct MonitorNotifyMessage *msg;
1962 done_msg.state = htonl ((uint32_t) GNUNET_CORE_KX_ITERATION_FINISHED); 1930
1963 memset (&done_msg.peer, 1931 env = GNUNET_MQ_msg (msg,
1964 0, 1932 GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY);
1965 sizeof (struct GNUNET_PeerIdentity)); 1933 msg->state = htonl ((uint32_t) kx->status);
1966 done_msg.timeout = GNUNET_TIME_absolute_hton (GNUNET_TIME_UNIT_FOREVER_ABS); 1934 msg->peer = *kx->peer;
1967 GNUNET_SERVER_notification_context_unicast (nc, 1935 msg->timeout = GNUNET_TIME_absolute_hton (kx->timeout);
1968 client, 1936 GNUNET_MQ_send (mq,
1969 &done_msg.header, 1937 env);
1970 GNUNET_NO); 1938 }
1939 env = GNUNET_MQ_msg (done_msg,
1940 GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY);
1941 done_msg->state = htonl ((uint32_t) GNUNET_CORE_KX_ITERATION_FINISHED);
1942 done_msg->timeout = GNUNET_TIME_absolute_hton (GNUNET_TIME_UNIT_FOREVER_ABS);
1943 GNUNET_MQ_send (mq,
1944 env);
1971} 1945}
1972 1946
1973 1947