GNUnet  0.10.x
gnunet-service-dht.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2009, 2010, 2011, 2016 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your 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  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
27 #include "platform.h"
28 #include "gnunet_block_lib.h"
29 #include "gnunet_util_lib.h"
32 #include "gnunet_hello_lib.h"
33 #include "gnunet_dht_service.h"
35 #include "gnunet-service-dht.h"
39 #include "gnunet-service-dht_nse.h"
41 
46 
51 
56 
57 
59 
60 
68 static void
69 process_hello(void *cls,
70  const struct GNUNET_MessageHeader *message)
71 {
72  GNUNET_free_non_null(GDS_my_hello);
73  GDS_my_hello = GNUNET_malloc(ntohs(message->size));
74  GNUNET_memcpy(GDS_my_hello,
75  message,
76  ntohs(message->size));
77 }
78 
79 
85 static void
86 shutdown_task(void *cls)
87 {
88  if (NULL != ghh)
89  {
91  ghh = NULL;
92  }
97  GDS_NSE_done();
98  if (NULL != GDS_block_context)
99  {
101  GDS_block_context = NULL;
102  }
103  if (NULL != GDS_stats)
104  {
106  GNUNET_YES);
107  GDS_stats = NULL;
108  }
109  GNUNET_free_non_null(GDS_my_hello);
110  GDS_my_hello = NULL;
112 }
113 
114 
122 static void
123 run(void *cls,
124  const struct GNUNET_CONFIGURATION_Handle *c,
126 {
127  GDS_cfg = c;
129  if (GNUNET_OK !=
131  "transport",
132  "HELLO_EXPIRATION",
134  {
136  }
139  GDS_cfg);
143  GDS_NSE_init();
145  GDS_HELLO_init();
147  {
148  shutdown_task(NULL);
149  return;
150  }
152  NULL);
155  &process_hello,
156  NULL);
157 }
158 
159 
160 /* Finally, define the main method */
161 GDS_DHT_SERVICE_INIT("dht", &run);
162 
163 
164 
165 
166 /* end of gnunet-service-dht.c */
struct GNUNET_BLOCK_Context * GNUNET_BLOCK_context_create(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create a block context.
Definition: block.c:130
struct GNUNET_MessageHeader * GDS_my_hello
Our HELLO.
GNUnet DHT globals.
struct GNUNET_STATISTICS_Handle * GDS_stats
Handle for the statistics service.
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
int GNUNET_CONFIGURATION_get_value_time(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, struct GNUNET_TIME_Relative *time)
Get a configuration value that should be a relative time.
void GDS_NEIGHBOURS_done()
Shutdown neighbours subsystem.
Handle to a service.
Definition: service.c:114
void GDS_DATACACHE_init()
Initialize datacache subsystem.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1284
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
void GDS_DATACACHE_done()
Shutdown datacache subsystem.
struct GNUNET_SERVICE_Handle * GDS_service
Handle for the service.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION
After how long do we expire an address in a HELLO that we just validated? This value is also used for...
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
void GDS_NSE_init()
Initialize NSE subsystem.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
static void run(void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_SERVICE_Handle *service)
Process dht requests.
GNUnet DHT integration with peerinfo.
struct GNUNET_BLOCK_Context * GDS_block_context
Our handle to the BLOCK library.
void GDS_NSE_done()
Shutdown NSE subsystem.
GNUnet DHT tracking of requests for routing replies.
void GDS_ROUTING_init()
Initialize routing subsystem.
void GNUNET_BLOCK_context_destroy(struct GNUNET_BLOCK_Context *ctx)
Destroy the block context.
Definition: block.c:150
#define GDS_DHT_SERVICE_INIT(name, run)
Define "main" method using service macro.
static void shutdown_task(void *cls)
Task run during shutdown.
struct GNUNET_TIME_Relative hello_expiration
Hello address expiration.
static void GDS_CLIENTS_stop()
Shutdown client subsystem.
Addresses that are global and are insensitive (i.e.
GNUnet DHT routing code.
static struct GNUNET_TRANSPORT_HelloGetHandle * ghh
Handle to get our current HELLO.
GNUnet DHT service&#39;s datacache integration.
configuration data
Definition: configuration.c:83
static void process_hello(void *cls, const struct GNUNET_MessageHeader *message)
Receive the HELLO from transport service, free current and replace if necessary.
void GDS_HELLO_done()
Shutdown HELLO subsystem.
struct GNUNET_TRANSPORT_HelloGetHandle * GNUNET_TRANSPORT_hello_get(const struct GNUNET_CONFIGURATION_Handle *cfg, enum GNUNET_TRANSPORT_AddressClass ac, GNUNET_TRANSPORT_HelloUpdateCallback rec, void *rec_cls)
Obtain updates on changes to the HELLO message for this peer.
static void GDS_CLIENTS_init()
Initialize client subsystem.
Functions to call with this peer&#39;s HELLO.
Header for all communications.
#define GNUNET_YES
Definition: gnunet_common.h:77
int GDS_NEIGHBOURS_init()
Initialize neighbours subsystem.
void GDS_ROUTING_done()
Shutdown routing subsystem.
void GNUNET_SERVICE_suspend(struct GNUNET_SERVICE_Handle *sh)
Suspend accepting connections from the listen socket temporarily.
Definition: service.c:2173
const struct GNUNET_CONFIGURATION_Handle * GDS_cfg
Configuration we use.
void GNUNET_TRANSPORT_hello_get_cancel(struct GNUNET_TRANSPORT_HelloGetHandle *ghh)
Stop receiving updates about changes to our HELLO message.
#define GNUNET_malloc(size)
Wrapper around malloc.
GNUnet DHT integration with NSE.
void GDS_HELLO_init()
Initialize HELLO subsystem.
GNUnet DHT service&#39;s client management code.
Time for relative time used by GNUnet, in microseconds.