aboutsummaryrefslogtreecommitdiff
path: root/src/core/gnunet-core.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/gnunet-core.c')
-rw-r--r--src/core/gnunet-core.c100
1 files changed, 53 insertions, 47 deletions
diff --git a/src/core/gnunet-core.c b/src/core/gnunet-core.c
index 36dc5fc6f..25127da66 100644
--- a/src/core/gnunet-core.c
+++ b/src/core/gnunet-core.c
@@ -20,7 +20,7 @@
20 20
21/** 21/**
22 * @file core/gnunet-core.c 22 * @file core/gnunet-core.c
23 * @brief Print information about other known _connected_ peers. 23 * @brief Print information about other peers known to CORE.
24 * @author Nathan Evans 24 * @author Nathan Evans
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
@@ -34,11 +34,6 @@
34static int monitor_connections; 34static int monitor_connections;
35 35
36/** 36/**
37 * Current number of connections in monitor mode
38 */
39// static unsigned int monitor_connections_counter;
40
41/**
42 * Handle to the CORE monitor. 37 * Handle to the CORE monitor.
43 */ 38 */
44static struct GNUNET_CORE_MonitorHandle *mh; 39static struct GNUNET_CORE_MonitorHandle *mh;
@@ -48,7 +43,7 @@ static struct GNUNET_CORE_MonitorHandle *mh;
48 * Task run in monitor mode when the user presses CTRL-C to abort. 43 * Task run in monitor mode when the user presses CTRL-C to abort.
49 * Stops monitoring activity. 44 * Stops monitoring activity.
50 * 45 *
51 * @param cls the 'struct GNUNET_TRANSPORT_PeerIterateContext *' 46 * @param cls NULL
52 * @param tc scheduler context 47 * @param tc scheduler context
53 */ 48 */
54static void 49static void
@@ -80,53 +75,54 @@ monitor_cb (void *cls,
80{ 75{
81 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); 76 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get();
82 const char *now_str; 77 const char *now_str;
78 const char *state_str;
83 79
84 if ( (NULL == peer) && 80 if ( ( (NULL == peer) ||
81 (GNUNET_CORE_KX_ITERATION_FINISHED == state) ) &&
85 (GNUNET_NO == monitor_connections) ) 82 (GNUNET_NO == monitor_connections) )
86 { 83 {
87 GNUNET_SCHEDULER_shutdown (); 84 GNUNET_SCHEDULER_shutdown ();
88 return; 85 return;
89 } 86 }
90 now_str = GNUNET_STRINGS_absolute_time_to_string (now);
91 FPRINTF (stdout,
92 _("%24s: %-17s %d %4s\n"),
93 now_str,
94 "FIXME",
95 state,
96 GNUNET_i2s (peer));
97}
98
99
100/**
101 * Function called with the result of the check if the CORE
102 * service is running.
103 *
104 * @param cls closure with our configuration
105 * @param result #GNUNET_YES if CORE is running
106 */
107static void
108testservice_task (void *cls,
109 int result)
110{
111 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
112 87
113 if (GNUNET_OK != result) 88 switch (state)
114 { 89 {
115 FPRINTF (stderr, _("Service `%s' is not running\n"), "core"); 90 case GNUNET_CORE_KX_STATE_DOWN:
91 /* should never happen, as we immediately send the key */
92 state_str = _("fresh connection");
93 break;
94 case GNUNET_CORE_KX_STATE_KEY_SENT:
95 state_str = _("key sent");
96 break;
97 case GNUNET_CORE_KX_STATE_KEY_RECEIVED:
98 state_str = _("key received");
99 break;
100 case GNUNET_CORE_KX_STATE_UP:
101 state_str = _("connection established");
102 break;
103 case GNUNET_CORE_KX_STATE_REKEY_SENT:
104 state_str = _("rekeying");
105 break;
106 case GNUNET_CORE_KX_PEER_DISCONNECT:
107 state_str = _("disconnected");
108 break;
109 case GNUNET_CORE_KX_ITERATION_FINISHED:
116 return; 110 return;
117 } 111 case GNUNET_CORE_KX_CORE_DISCONNECT:
118 112 FPRINTF (stderr,
119 mh = GNUNET_CORE_monitor_start (cfg, 113 "%s\n",
120 &monitor_cb, 114 _("Connection to CORE service lost (reconnecting)"));
121 NULL);
122 if (NULL == mh)
123 {
124 GNUNET_SCHEDULER_add_now (shutdown_task, NULL);
125 fprintf (stderr, ("Failed to connect to CORE service!\n"));
126 return; 115 return;
116 default:
117 state_str = _("unknown state");
118 break;
127 } 119 }
128 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 120 now_str = GNUNET_STRINGS_absolute_time_to_string (now);
129 &shutdown_task, NULL); 121 FPRINTF (stdout,
122 _("%24s: %-17s %4s\n"),
123 now_str,
124 state_str,
125 GNUNET_i2s (peer));
130} 126}
131 127
132 128
@@ -149,9 +145,18 @@ run (void *cls, char *const *args, const char *cfgfile,
149 args[0]); 145 args[0]);
150 return; 146 return;
151 } 147 }
152 GNUNET_CLIENT_service_test ("core", cfg, 148 mh = GNUNET_CORE_monitor_start (cfg,
153 GNUNET_TIME_UNIT_SECONDS, 149 &monitor_cb,
154 &testservice_task, (void *) cfg); 150 NULL);
151 if (NULL == mh)
152 {
153 FPRINTF (stderr,
154 "%s",
155 _("Failed to connect to CORE service!\n"));
156 return;
157 }
158 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
159 &shutdown_task, NULL);
155} 160}
156 161
157 162
@@ -163,7 +168,8 @@ run (void *cls, char *const *args, const char *cfgfile,
163 * @return 0 ok, 1 on error 168 * @return 0 ok, 1 on error
164 */ 169 */
165int 170int
166main (int argc, char *const *argv) 171main (int argc,
172 char *const *argv)
167{ 173{
168 int res; 174 int res;
169 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 175 static const struct GNUNET_GETOPT_CommandLineOption options[] = {