diff options
author | Bart Polot <bart@net.in.tum.de> | 2014-02-04 12:36:31 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2014-02-04 12:36:31 +0000 |
commit | 0066f847206caa73b90b01a49d88e408934530dd (patch) | |
tree | c9a228498b9000dae84821427d3c47a1058ea669 | |
parent | d8ec84381eb2a365ef40af64d8c88f039ddd1095 (diff) | |
download | gnunet-0066f847206caa73b90b01a49d88e408934530dd.tar.gz gnunet-0066f847206caa73b90b01a49d88e408934530dd.zip |
- add hello subsystem to get hellos for known peers
-rw-r--r-- | src/mesh/Makefile.am | 3 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 3 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh_hello.c | 159 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh_hello.h | 61 |
4 files changed, 226 insertions, 0 deletions
diff --git a/src/mesh/Makefile.am b/src/mesh/Makefile.am index 1ca4c5a49..5c2dc84dc 100644 --- a/src/mesh/Makefile.am +++ b/src/mesh/Makefile.am | |||
@@ -69,6 +69,7 @@ gnunet_service_mesh_SOURCES = \ | |||
69 | gnunet-service-mesh_local.c gnunet-service-mesh_local.h \ | 69 | gnunet-service-mesh_local.c gnunet-service-mesh_local.h \ |
70 | gnunet-service-mesh_peer.c gnunet-service-mesh_peer.h \ | 70 | gnunet-service-mesh_peer.c gnunet-service-mesh_peer.h \ |
71 | gnunet-service-mesh_dht.c gnunet-service-mesh_dht.h \ | 71 | gnunet-service-mesh_dht.c gnunet-service-mesh_dht.h \ |
72 | gnunet-service-mesh_hello.c gnunet-service-mesh_hello.h \ | ||
72 | mesh_path.c mesh_path.h \ | 73 | mesh_path.c mesh_path.h \ |
73 | mesh_common.c \ | 74 | mesh_common.c \ |
74 | gnunet-service-mesh.c | 75 | gnunet-service-mesh.c |
@@ -78,12 +79,14 @@ gnunet_service_mesh_LDADD = \ | |||
78 | $(top_builddir)/src/core/libgnunetcore.la \ | 79 | $(top_builddir)/src/core/libgnunetcore.la \ |
79 | $(top_builddir)/src/dht/libgnunetdht.la \ | 80 | $(top_builddir)/src/dht/libgnunetdht.la \ |
80 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 81 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
82 | $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ | ||
81 | $(top_builddir)/src/block/libgnunetblock.la | 83 | $(top_builddir)/src/block/libgnunetblock.la |
82 | gnunet_service_mesh_DEPENDENCIES = \ | 84 | gnunet_service_mesh_DEPENDENCIES = \ |
83 | $(top_builddir)/src/util/libgnunetutil.la \ | 85 | $(top_builddir)/src/util/libgnunetutil.la \ |
84 | $(top_builddir)/src/core/libgnunetcore.la \ | 86 | $(top_builddir)/src/core/libgnunetcore.la \ |
85 | $(top_builddir)/src/dht/libgnunetdht.la \ | 87 | $(top_builddir)/src/dht/libgnunetdht.la \ |
86 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 88 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
89 | $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ | ||
87 | $(top_builddir)/src/block/libgnunetblock.la | 90 | $(top_builddir)/src/block/libgnunetblock.la |
88 | if LINUX | 91 | if LINUX |
89 | gnunet_service_mesh_LDFLAGS = -lrt | 92 | gnunet_service_mesh_LDFLAGS = -lrt |
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index b4df7cb48..ec402f43b 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -52,6 +52,7 @@ | |||
52 | #include "gnunet-service-mesh_tunnel.h" | 52 | #include "gnunet-service-mesh_tunnel.h" |
53 | #include "gnunet-service-mesh_dht.h" | 53 | #include "gnunet-service-mesh_dht.h" |
54 | #include "gnunet-service-mesh_peer.h" | 54 | #include "gnunet-service-mesh_peer.h" |
55 | #include "gnunet-service-mesh_hello.h" | ||
55 | 56 | ||
56 | 57 | ||
57 | /******************************************************************************/ | 58 | /******************************************************************************/ |
@@ -107,6 +108,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
107 | shutting_down = GNUNET_YES; | 108 | shutting_down = GNUNET_YES; |
108 | 109 | ||
109 | GML_shutdown (); | 110 | GML_shutdown (); |
111 | GMH_shutdown (); | ||
110 | GMD_shutdown (); | 112 | GMD_shutdown (); |
111 | GMC_shutdown (); | 113 | GMC_shutdown (); |
112 | GMT_shutdown (); | 114 | GMT_shutdown (); |
@@ -146,6 +148,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
146 | GNUNET_i2s (&my_full_id)); | 148 | GNUNET_i2s (&my_full_id)); |
147 | 149 | ||
148 | GML_init (server); /* Local clients */ | 150 | GML_init (server); /* Local clients */ |
151 | GMH_shutdown (c); /* Hellos */ | ||
149 | GMC_init (c); /* Connections */ | 152 | GMC_init (c); /* Connections */ |
150 | GMP_init (c); /* Peers */ | 153 | GMP_init (c); /* Peers */ |
151 | GMD_init (c); /* DHT */ | 154 | GMD_init (c); /* DHT */ |
diff --git a/src/mesh/gnunet-service-mesh_hello.c b/src/mesh/gnunet-service-mesh_hello.c new file mode 100644 index 000000000..5ebf030f5 --- /dev/null +++ b/src/mesh/gnunet-service-mesh_hello.c | |||
@@ -0,0 +1,159 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2014 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 | #include "platform.h" | ||
22 | #include "gnunet_util_lib.h" | ||
23 | |||
24 | #include "gnunet_statistics_service.h" | ||
25 | #include "gnunet_peerinfo_service.h" | ||
26 | |||
27 | #include "mesh_protocol.h" | ||
28 | #include "mesh_path.h" | ||
29 | |||
30 | #include "gnunet-service-mesh_hello.h" | ||
31 | #include "gnunet-service-mesh_peer.h" | ||
32 | |||
33 | #define LOG(level, ...) GNUNET_log_from(level,"mesh-hll",__VA_ARGS__) | ||
34 | |||
35 | |||
36 | /******************************************************************************/ | ||
37 | /******************************** STRUCTS **********************************/ | ||
38 | /******************************************************************************/ | ||
39 | |||
40 | |||
41 | |||
42 | /******************************************************************************/ | ||
43 | /******************************* GLOBALS ***********************************/ | ||
44 | /******************************************************************************/ | ||
45 | |||
46 | /** | ||
47 | * Global handle to the statistics service. | ||
48 | */ | ||
49 | extern struct GNUNET_STATISTICS_Handle *stats; | ||
50 | |||
51 | /** | ||
52 | * Local peer own ID (memory efficient handle). | ||
53 | */ | ||
54 | extern GNUNET_PEER_Id myid; | ||
55 | |||
56 | /** | ||
57 | * Local peer own ID (full value). | ||
58 | */ | ||
59 | extern struct GNUNET_PeerIdentity my_full_id; | ||
60 | |||
61 | |||
62 | /** | ||
63 | * Don't try to recover tunnels if shutting down. | ||
64 | */ | ||
65 | extern int shutting_down; | ||
66 | |||
67 | |||
68 | /** | ||
69 | * Hello message of local peer. | ||
70 | */ | ||
71 | const struct GNUNET_HELLO_Message *mine; | ||
72 | |||
73 | /** | ||
74 | * Handle to peerinfo service. | ||
75 | */ | ||
76 | static struct GNUNET_PEERINFO_Handle *peerinfo; | ||
77 | |||
78 | /** | ||
79 | * Iterator context. | ||
80 | */ | ||
81 | struct GNUNET_PEERINFO_NotifyContext* nc; | ||
82 | |||
83 | |||
84 | /******************************************************************************/ | ||
85 | /******************************** STATIC ***********************************/ | ||
86 | /******************************************************************************/ | ||
87 | |||
88 | /** | ||
89 | * Process each hello message received from peerinfo. | ||
90 | * | ||
91 | * @param cls the 'struct GetUriContext' | ||
92 | * @param peer identity of the peer | ||
93 | * @param hello addresses of the peer | ||
94 | * @param err_msg error message | ||
95 | */ | ||
96 | static void | ||
97 | got_hello (void *cls, const struct GNUNET_PeerIdentity *id, | ||
98 | const struct GNUNET_HELLO_Message *hello, | ||
99 | const char *err_msg) | ||
100 | { | ||
101 | struct MeshPeer *peer; | ||
102 | |||
103 | if (NULL == id) | ||
104 | LOG (GNUNET_ERROR_TYPE_ERROR, "not a valid id\n"); | ||
105 | |||
106 | peer = GMP_get (id); | ||
107 | GMP_set_hello (peer, hello); | ||
108 | } | ||
109 | |||
110 | |||
111 | /******************************************************************************/ | ||
112 | /******************************** API ***********************************/ | ||
113 | /******************************************************************************/ | ||
114 | |||
115 | |||
116 | void | ||
117 | GMH_init (const struct GNUNET_CONFIGURATION_Handle *c) | ||
118 | { | ||
119 | GNUNET_assert (NULL != nc); | ||
120 | peerinfo = GNUNET_PEERINFO_connect (c); | ||
121 | nc = GNUNET_PEERINFO_notify (c, GNUNET_NO, &got_hello, NULL); | ||
122 | } | ||
123 | |||
124 | |||
125 | void | ||
126 | GMH_shutdown () | ||
127 | { | ||
128 | if (NULL != nc) | ||
129 | { | ||
130 | GNUNET_PEERINFO_notify_cancel (nc); | ||
131 | nc = NULL; | ||
132 | } | ||
133 | if (NULL != peerinfo) | ||
134 | { | ||
135 | GNUNET_PEERINFO_disconnect (peerinfo); | ||
136 | peerinfo = NULL; | ||
137 | } | ||
138 | } | ||
139 | |||
140 | |||
141 | const struct GNUNET_HELLO_Message * | ||
142 | GMH_get_mine (void) | ||
143 | { | ||
144 | return mine; | ||
145 | } | ||
146 | |||
147 | |||
148 | const struct GNUNET_HELLO_Message * | ||
149 | GMH_get (const struct GNUNET_PeerIdentity *id) | ||
150 | { | ||
151 | return GMP_get_hello (GMP_get (id)); | ||
152 | } | ||
153 | |||
154 | void | ||
155 | GMH_2s () | ||
156 | { | ||
157 | } | ||
158 | |||
159 | |||
diff --git a/src/mesh/gnunet-service-mesh_hello.h b/src/mesh/gnunet-service-mesh_hello.h new file mode 100644 index 000000000..866d7abb6 --- /dev/null +++ b/src/mesh/gnunet-service-mesh_hello.h | |||
@@ -0,0 +1,61 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2014 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 mesh/gnunet-service-mesh_hello.h | ||
23 | * @brief mesh service; dealing with hello messages | ||
24 | * @author Bartlomiej Polot | ||
25 | * | ||
26 | * All functions in this file should use the prefix GMH (Gnunet Mesh Hello) | ||
27 | */ | ||
28 | |||
29 | #ifndef GNUNET_SERVICE_MESH_HELLO_H | ||
30 | #define GNUNET_SERVICE_MESH_HELLO_H | ||
31 | |||
32 | #ifdef __cplusplus | ||
33 | extern "C" | ||
34 | { | ||
35 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
36 | } | ||
37 | #endif | ||
38 | #endif | ||
39 | |||
40 | #include "platform.h" | ||
41 | #include "gnunet_util_lib.h" | ||
42 | |||
43 | |||
44 | void | ||
45 | GMH_init (const struct GNUNET_CONFIGURATION_Handle *c); | ||
46 | |||
47 | void | ||
48 | GMH_shutdown (); | ||
49 | |||
50 | |||
51 | |||
52 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
53 | { | ||
54 | #endif | ||
55 | #ifdef __cplusplus | ||
56 | } | ||
57 | #endif | ||
58 | |||
59 | /* ifndef GNUNET_MESH_SERVICE_HELLO_H */ | ||
60 | #endif | ||
61 | /* end of gnunet-mesh-service_hello.h */ | ||