diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2023-10-18 20:02:10 +0200 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2023-10-18 20:02:10 +0200 |
commit | 11949e419fd7230431646703ac0cf8e34f615673 (patch) | |
tree | 94892053dd1734a41effa1fd2a5b7e9f650b0f31 /src/service/cadet/gnunet-service-cadet_hello.c | |
parent | 2d76608872f25220ef85c56af403392f6842dc19 (diff) | |
download | gnunet-11949e419fd7230431646703ac0cf8e34f615673.tar.gz gnunet-11949e419fd7230431646703ac0cf8e34f615673.zip |
BUILD: Move cadet to service/cli
Diffstat (limited to 'src/service/cadet/gnunet-service-cadet_hello.c')
-rw-r--r-- | src/service/cadet/gnunet-service-cadet_hello.c | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/src/service/cadet/gnunet-service-cadet_hello.c b/src/service/cadet/gnunet-service-cadet_hello.c new file mode 100644 index 000000000..135fde25a --- /dev/null +++ b/src/service/cadet/gnunet-service-cadet_hello.c | |||
@@ -0,0 +1,149 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2014, 2017 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 | /** | ||
21 | * @file cadet/gnunet-service-cadet_hello.c | ||
22 | * @brief spread knowledge about how to contact us (get HELLO from peerinfo), | ||
23 | * and remember HELLOs of other peers we have an interest in | ||
24 | * @author Bartlomiej Polot | ||
25 | * @author Christian Grothoff | ||
26 | */ | ||
27 | #include "platform.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_statistics_service.h" | ||
30 | #include "gnunet_peerstore_service.h" | ||
31 | #include "cadet_protocol.h" | ||
32 | #include "gnunet-service-cadet.h" | ||
33 | #include "gnunet-service-cadet_dht.h" | ||
34 | #include "gnunet-service-cadet_hello.h" | ||
35 | #include "gnunet-service-cadet_peer.h" | ||
36 | |||
37 | #define LOG(level, ...) GNUNET_log_from (level, "cadet-hll", __VA_ARGS__) | ||
38 | |||
39 | /** | ||
40 | * Hello message of local peer. | ||
41 | */ | ||
42 | static struct GNUNET_MessageHeader *mine; | ||
43 | |||
44 | /** | ||
45 | * Handle to the PEERSTORE service. | ||
46 | */ | ||
47 | static struct GNUNET_PEERSTORE_Handle *peerstore; | ||
48 | |||
49 | /** | ||
50 | * Our peerstore notification context. We use notification | ||
51 | * to instantly learn about new peers as they are discovered. | ||
52 | */ | ||
53 | static struct GNUNET_PEERSTORE_NotifyContext *peerstore_notify; | ||
54 | |||
55 | |||
56 | /** | ||
57 | * Process each hello message received from peerinfo. | ||
58 | * | ||
59 | * @param cls Closure (unused). | ||
60 | * @param id Identity of the peer. | ||
61 | * @param hello Hello of the peer. | ||
62 | * @param err_msg Error message. | ||
63 | */ | ||
64 | static void | ||
65 | got_hello (void *cls, | ||
66 | const struct GNUNET_PeerIdentity *id, | ||
67 | const struct GNUNET_MessageHeader *hello, | ||
68 | const char *err_msg) | ||
69 | { | ||
70 | struct CadetPeer *peer; | ||
71 | |||
72 | if ((NULL == id) || | ||
73 | (NULL == hello)) | ||
74 | return; | ||
75 | if (0 == GNUNET_memcmp (id, | ||
76 | &my_full_id)) | ||
77 | { | ||
78 | GNUNET_free (mine); | ||
79 | mine = GNUNET_copy_message (hello); | ||
80 | GCD_hello_update (); | ||
81 | return; | ||
82 | } | ||
83 | |||
84 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
85 | "Hello for %s (%d bytes), expires on %s\n", | ||
86 | GNUNET_i2s (id), | ||
87 | ntohs (hello->size), | ||
88 | GNUNET_STRINGS_absolute_time_to_string ( | ||
89 | GNUNET_HELLO_builder_get_expiration_time (hello))); | ||
90 | peer = GCP_get (id, | ||
91 | GNUNET_YES); | ||
92 | GCP_set_hello (peer, | ||
93 | hello); | ||
94 | } | ||
95 | |||
96 | |||
97 | /** | ||
98 | * Initialize the hello subsystem. | ||
99 | * | ||
100 | * @param c Configuration. | ||
101 | */ | ||
102 | void | ||
103 | GCH_init (const struct GNUNET_CONFIGURATION_Handle *c) | ||
104 | { | ||
105 | GNUNET_assert (NULL == peerstore_notify); | ||
106 | peerstore = GNUNET_PEERSTORE_connect (c); | ||
107 | peerstore_notify = | ||
108 | GNUNET_PEERSTORE_hello_changed_notify (peerstore, GNUNET_NO, &got_hello, | ||
109 | NULL); | ||
110 | } | ||
111 | |||
112 | |||
113 | /** | ||
114 | * Shut down the hello subsystem. | ||
115 | */ | ||
116 | void | ||
117 | GCH_shutdown () | ||
118 | { | ||
119 | if (NULL != peerstore_notify) | ||
120 | { | ||
121 | GNUNET_PEERSTORE_hello_changed_notify_cancel (peerstore_notify); | ||
122 | peerstore_notify = NULL; | ||
123 | } | ||
124 | if (NULL != peerstore) | ||
125 | { | ||
126 | GNUNET_PEERSTORE_disconnect (peerstore, GNUNET_YES); | ||
127 | peerstore = NULL; | ||
128 | } | ||
129 | if (NULL != mine) | ||
130 | { | ||
131 | GNUNET_free (mine); | ||
132 | mine = NULL; | ||
133 | } | ||
134 | } | ||
135 | |||
136 | |||
137 | /** | ||
138 | * Get own hello message. | ||
139 | * | ||
140 | * @return Own hello message. | ||
141 | */ | ||
142 | const struct GNUNET_MessageHeader * | ||
143 | GCH_get_mine (void) | ||
144 | { | ||
145 | return mine; | ||
146 | } | ||
147 | |||
148 | |||
149 | /* end of gnunet-service-cadet-new_hello.c */ | ||