diff options
Diffstat (limited to 'src/transport/gnunet-service-transport-new.c')
-rw-r--r-- | src/transport/gnunet-service-transport-new.c | 157 |
1 files changed, 157 insertions, 0 deletions
diff --git a/src/transport/gnunet-service-transport-new.c b/src/transport/gnunet-service-transport-new.c new file mode 100644 index 000000000..c039d5963 --- /dev/null +++ b/src/transport/gnunet-service-transport-new.c | |||
@@ -0,0 +1,157 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2010,2011 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file transport/gnunet-service-transport-new.c | ||
23 | * @brief | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | #include "gnunet_statistics_service.h" | ||
29 | #include "gnunet_transport_service.h" | ||
30 | #include "gnunet-service-transport.h" | ||
31 | #include "gnunet-service-transport_blacklist.h" | ||
32 | #include "gnunet-service-transport_clients.h" | ||
33 | #include "gnunet-service-transport_hello.h" | ||
34 | #include "gnunet-service-transport_neighbours.h" | ||
35 | #include "gnunet-service-transport_plugins.h" | ||
36 | #include "gnunet-service-transport_validation.h" | ||
37 | |||
38 | /* globals */ | ||
39 | |||
40 | /** | ||
41 | * Statistics handle. | ||
42 | */ | ||
43 | struct GNUNET_STATISTICS_Handle *GST_stats; | ||
44 | |||
45 | /** | ||
46 | * Configuration handle. | ||
47 | */ | ||
48 | const struct GNUNET_CONFIGURATION_Handle *GST_cfg; | ||
49 | |||
50 | /** | ||
51 | * Configuration handle. | ||
52 | */ | ||
53 | struct GNUNET_PeerIdentity GST_my_identity; | ||
54 | |||
55 | /** | ||
56 | * Our private key. | ||
57 | */ | ||
58 | static struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key; | ||
59 | |||
60 | /** | ||
61 | * Our public key. | ||
62 | */ | ||
63 | static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key; | ||
64 | |||
65 | /** | ||
66 | * Function called when the service shuts down. Unloads our plugins | ||
67 | * and cancels pending validations. | ||
68 | * | ||
69 | * @param cls closure, unused | ||
70 | * @param tc task context (unused) | ||
71 | */ | ||
72 | static void | ||
73 | shutdown_task (void *cls, | ||
74 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
75 | { | ||
76 | if (GST_stats != NULL) | ||
77 | { | ||
78 | GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO); | ||
79 | GST_stats = NULL; | ||
80 | } | ||
81 | if (my_private_key != NULL) | ||
82 | { | ||
83 | GNUNET_CRYPTO_rsa_key_free (my_private_key); | ||
84 | my_private_key = NULL; | ||
85 | } | ||
86 | } | ||
87 | |||
88 | |||
89 | /** | ||
90 | * Initiate transport service. | ||
91 | * | ||
92 | * @param cls closure | ||
93 | * @param server the initialized server | ||
94 | * @param c configuration to use | ||
95 | */ | ||
96 | static void | ||
97 | run (void *cls, | ||
98 | struct GNUNET_SERVER_Handle *server, | ||
99 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
100 | { | ||
101 | #if 0 | ||
102 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | ||
103 | {NULL, NULL, 0, 0} | ||
104 | }; | ||
105 | #endif | ||
106 | char *keyfile; | ||
107 | |||
108 | /* setup globals */ | ||
109 | GST_cfg = c; | ||
110 | if (GNUNET_OK != | ||
111 | GNUNET_CONFIGURATION_get_value_filename (c, | ||
112 | "GNUNETD", | ||
113 | "HOSTKEY", &keyfile)) | ||
114 | { | ||
115 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
116 | _ | ||
117 | ("Transport service is lacking key configuration settings. Exiting.\n")); | ||
118 | GNUNET_SCHEDULER_shutdown (); | ||
119 | return; | ||
120 | } | ||
121 | my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); | ||
122 | GNUNET_free (keyfile); | ||
123 | if (my_private_key == NULL) | ||
124 | { | ||
125 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
126 | _("Transport service could not access hostkey. Exiting.\n")); | ||
127 | GNUNET_SCHEDULER_shutdown (); | ||
128 | return; | ||
129 | } | ||
130 | GST_stats = GNUNET_STATISTICS_create ("transport", c); | ||
131 | GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key); | ||
132 | GNUNET_CRYPTO_hash (&my_public_key, | ||
133 | sizeof (my_public_key), &GST_my_identity.hashPubKey); | ||
134 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | ||
135 | &shutdown_task, NULL); | ||
136 | } | ||
137 | |||
138 | |||
139 | /** | ||
140 | * The main function for the transport service. | ||
141 | * | ||
142 | * @param argc number of arguments from the command line | ||
143 | * @param argv command line arguments | ||
144 | * @return 0 ok, 1 on error | ||
145 | */ | ||
146 | int | ||
147 | main (int argc, char *const *argv) | ||
148 | { | ||
149 | return (GNUNET_OK == | ||
150 | GNUNET_SERVICE_run (argc, | ||
151 | argv, | ||
152 | "transport", | ||
153 | GNUNET_SERVICE_OPTION_NONE, | ||
154 | &run, NULL)) ? 0 : 1; | ||
155 | } | ||
156 | |||
157 | /* end of file gnunet-service-transport-new.c */ | ||