diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-09-27 14:26:23 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-09-27 14:26:23 +0000 |
commit | 963d7c77e46be059519468348be37d923136037d (patch) | |
tree | a490099530c05dbbc0fecc7704655448c51e4b60 | |
parent | fb6d4c04a9db33e63a2ce238732c7cfc6df4c798 (diff) | |
download | gnunet-963d7c77e46be059519468348be37d923136037d.tar.gz gnunet-963d7c77e46be059519468348be37d923136037d.zip |
track HELLOs from peerinfo
-rw-r--r-- | src/dht/Makefile.am | 1 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht-new.c | 3 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_hello.c | 139 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_hello.h | 55 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_neighbours.c | 52 |
5 files changed, 204 insertions, 46 deletions
diff --git a/src/dht/Makefile.am b/src/dht/Makefile.am index 70fa5ca28..5cad82062 100644 --- a/src/dht/Makefile.am +++ b/src/dht/Makefile.am | |||
@@ -122,6 +122,7 @@ gnunet_service_dht_new_SOURCES = \ | |||
122 | gnunet-service-dht-new.c gnunet-service-dht.h \ | 122 | gnunet-service-dht-new.c gnunet-service-dht.h \ |
123 | gnunet-service-dht_clients.c gnunet-service-dht_clients.h \ | 123 | gnunet-service-dht_clients.c gnunet-service-dht_clients.h \ |
124 | gnunet-service-dht_datacache.c gnunet-service-dht_datacache.h \ | 124 | gnunet-service-dht_datacache.c gnunet-service-dht_datacache.h \ |
125 | gnunet-service-dht_hello.c gnunet-service-dht_hello.h \ | ||
125 | gnunet-service-dht_nse.c gnunet-service-dht_nse.h \ | 126 | gnunet-service-dht_nse.c gnunet-service-dht_nse.h \ |
126 | gnunet-service-dht_neighbours.c gnunet-service-dht_neighbours.h \ | 127 | gnunet-service-dht_neighbours.c gnunet-service-dht_neighbours.h \ |
127 | gnunet-service-dht_routing.c gnunet-service-dht_routing.h | 128 | gnunet-service-dht_routing.c gnunet-service-dht_routing.h |
diff --git a/src/dht/gnunet-service-dht-new.c b/src/dht/gnunet-service-dht-new.c index 1469385d2..0d377450a 100644 --- a/src/dht/gnunet-service-dht-new.c +++ b/src/dht/gnunet-service-dht-new.c | |||
@@ -34,6 +34,7 @@ | |||
34 | #include "gnunet-service-dht.h" | 34 | #include "gnunet-service-dht.h" |
35 | #include "gnunet-service-dht_clients.h" | 35 | #include "gnunet-service-dht_clients.h" |
36 | #include "gnunet-service-dht_datacache.h" | 36 | #include "gnunet-service-dht_datacache.h" |
37 | #include "gnunet-service-dht_hello.h" | ||
37 | #include "gnunet-service-dht_neighbours.h" | 38 | #include "gnunet-service-dht_neighbours.h" |
38 | #include "gnunet-service-dht_nse.h" | 39 | #include "gnunet-service-dht_nse.h" |
39 | #include "gnunet-service-dht_routing.h" | 40 | #include "gnunet-service-dht_routing.h" |
@@ -114,6 +115,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
114 | GDS_DATACACHE_done (); | 115 | GDS_DATACACHE_done (); |
115 | GDS_ROUTING_done (); | 116 | GDS_ROUTING_done (); |
116 | GDS_CLIENTS_done (); | 117 | GDS_CLIENTS_done (); |
118 | GDS_HELLO_done (); | ||
117 | GDS_NSE_done (); | 119 | GDS_NSE_done (); |
118 | if (GDS_block_context != NULL) | 120 | if (GDS_block_context != NULL) |
119 | { | 121 | { |
@@ -147,6 +149,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
147 | GDS_ROUTING_init (); | 149 | GDS_ROUTING_init (); |
148 | GDS_NSE_init (); | 150 | GDS_NSE_init (); |
149 | GDS_DATACACHE_init (); | 151 | GDS_DATACACHE_init (); |
152 | GDS_HELLO_init (); | ||
150 | GDS_CLIENTS_init (server); | 153 | GDS_CLIENTS_init (server); |
151 | if (GNUNET_OK != | 154 | if (GNUNET_OK != |
152 | GDS_NEIGHBOURS_init ()) | 155 | GDS_NEIGHBOURS_init ()) |
diff --git a/src/dht/gnunet-service-dht_hello.c b/src/dht/gnunet-service-dht_hello.c new file mode 100644 index 000000000..2ee60c91f --- /dev/null +++ b/src/dht/gnunet-service-dht_hello.c | |||
@@ -0,0 +1,139 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 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 dht/gnunet-service-dht_hello.c | ||
23 | * @brief GNUnet DHT integration with peerinfo | ||
24 | * @author Christian Grothoff | ||
25 | * | ||
26 | * TODO: | ||
27 | * - consider adding mechanism to remove expired HELLOs | ||
28 | */ | ||
29 | #include "platform.h" | ||
30 | #include "gnunet-service-dht.h" | ||
31 | #include "gnunet-service-dht_hello.h" | ||
32 | #include "gnunet_peerinfo_service.h" | ||
33 | |||
34 | |||
35 | /** | ||
36 | * Handle for peerinfo notifications. | ||
37 | */ | ||
38 | static struct GNUNET_PEERINFO_NotifyContext *pnc; | ||
39 | |||
40 | /** | ||
41 | * Hash map of peers to HELLOs. | ||
42 | */ | ||
43 | static struct GNUNET_CONTAINER_MultiHashMap *peer_to_hello; | ||
44 | |||
45 | |||
46 | /** | ||
47 | * Obtain a peer's HELLO if available | ||
48 | * | ||
49 | * @param peer peer to look for a HELLO from | ||
50 | * @return HELLO for the given peer | ||
51 | */ | ||
52 | const struct GNUNET_HELLO_Message * | ||
53 | GDS_HELLO_get (const struct GNUNET_PeerIdentity *peer) | ||
54 | { | ||
55 | return GNUNET_CONTAINER_multihashmap_get (peer_to_hello, | ||
56 | &peer->hashPubKey); | ||
57 | } | ||
58 | |||
59 | |||
60 | /** | ||
61 | * Function called for each HELLO known to PEERINFO. | ||
62 | * | ||
63 | * @param cls closure | ||
64 | * @param peer id of the peer, NULL for last call | ||
65 | * @param hello hello message for the peer (can be NULL) | ||
66 | * @param error message | ||
67 | */ | ||
68 | static void | ||
69 | process_hello (void *cls, | ||
70 | const struct GNUNET_PeerIdentity * | ||
71 | peer, | ||
72 | const struct GNUNET_HELLO_Message * | ||
73 | hello, const char *err_msg) | ||
74 | { | ||
75 | struct GNUNET_TIME_Absolute ex; | ||
76 | struct GNUNET_HELLO_Message *hm; | ||
77 | |||
78 | if (hello == NULL) | ||
79 | return; | ||
80 | ex = GNUNET_HELLO_get_last_expiration (hello); | ||
81 | if (GNUNET_TIME_absolute_get_remaining (ex).rel_value == 0) | ||
82 | return; | ||
83 | hm = GNUNET_CONTAINER_multihashmap_get (peer_to_hello, | ||
84 | &peer->hashPubKey); | ||
85 | GNUNET_free_non_null (hm); | ||
86 | hm = GNUNET_malloc (GNUNET_HELLO_size (hello)); | ||
87 | memcpy (hm, hello, GNUNET_HELLO_size (hello)); | ||
88 | GNUNET_assert (GNUNET_SYSERR != | ||
89 | GNUNET_CONTAINER_multihashmap_put (peer_to_hello, | ||
90 | &peer->hashPubKey, | ||
91 | hm, | ||
92 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE)); | ||
93 | } | ||
94 | |||
95 | |||
96 | /** | ||
97 | * Initialize HELLO subsystem. | ||
98 | */ | ||
99 | void | ||
100 | GDS_HELLO_init () | ||
101 | { | ||
102 | pnc = GNUNET_PEERINFO_notify (GDS_cfg, | ||
103 | &process_hello, | ||
104 | NULL); | ||
105 | peer_to_hello = GNUNET_CONTAINER_multihashmap_create (256); | ||
106 | } | ||
107 | |||
108 | |||
109 | /** | ||
110 | * Free memory occopied by the HELLO. | ||
111 | */ | ||
112 | static int | ||
113 | free_hello (void *cls, | ||
114 | const GNUNET_HashCode *key, | ||
115 | void *hello) | ||
116 | { | ||
117 | GNUNET_free (hello); | ||
118 | return GNUNET_OK; | ||
119 | } | ||
120 | |||
121 | |||
122 | /** | ||
123 | * Shutdown HELLO subsystem. | ||
124 | */ | ||
125 | void | ||
126 | GDS_HELLO_done () | ||
127 | { | ||
128 | if (NULL != pnc) | ||
129 | { | ||
130 | GNUNET_PEERINFO_notify_cancel (pnc); | ||
131 | pnc = NULL; | ||
132 | } | ||
133 | GNUNET_CONTAINER_multihashmap_iterate (peer_to_hello, | ||
134 | &free_hello, | ||
135 | NULL); | ||
136 | GNUNET_CONTAINER_multihashmap_destroy (peer_to_hello); | ||
137 | } | ||
138 | |||
139 | /* end of gnunet-service-dht_hello.c */ | ||
diff --git a/src/dht/gnunet-service-dht_hello.h b/src/dht/gnunet-service-dht_hello.h new file mode 100644 index 000000000..04a6a497e --- /dev/null +++ b/src/dht/gnunet-service-dht_hello.h | |||
@@ -0,0 +1,55 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 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 dht/gnunet-service-dht_hello.h | ||
23 | * @brief GNUnet DHT integration with peerinfo | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #ifndef GNUNET_SERVICE_DHT_HELLO_H | ||
27 | #define GNUNET_SERVICE_DHT_HELLO_H | ||
28 | |||
29 | #include "gnunet_util_lib.h" | ||
30 | #include "gnunet_hello_lib.h" | ||
31 | |||
32 | /** | ||
33 | * Obtain a peer's HELLO if available | ||
34 | * | ||
35 | * @param peer peer to look for a HELLO from | ||
36 | * @return HELLO for the given peer | ||
37 | */ | ||
38 | const struct GNUNET_HELLO_Message * | ||
39 | GDS_HELLO_get (const struct GNUNET_PeerIdentity *peer); | ||
40 | |||
41 | |||
42 | /** | ||
43 | * Initialize HELLO subsystem. | ||
44 | */ | ||
45 | void | ||
46 | GDS_HELLO_init (void); | ||
47 | |||
48 | |||
49 | /** | ||
50 | * Shutdown HELLO subsystem. | ||
51 | */ | ||
52 | void | ||
53 | GDS_HELLO_done (void); | ||
54 | |||
55 | #endif | ||
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c index a9ecbe4af..8cbf918d2 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c | |||
@@ -38,11 +38,11 @@ | |||
38 | #include "gnunet_hello_lib.h" | 38 | #include "gnunet_hello_lib.h" |
39 | #include "gnunet_dht_service.h" | 39 | #include "gnunet_dht_service.h" |
40 | #include "gnunet_statistics_service.h" | 40 | #include "gnunet_statistics_service.h" |
41 | #include "gnunet_peerinfo_service.h" | ||
42 | #include "dht.h" | 41 | #include "dht.h" |
43 | #include "gnunet-service-dht.h" | 42 | #include "gnunet-service-dht.h" |
44 | #include "gnunet-service-dht_clients.h" | 43 | #include "gnunet-service-dht_clients.h" |
45 | #include "gnunet-service-dht_datacache.h" | 44 | #include "gnunet-service-dht_datacache.h" |
45 | #include "gnunet-service-dht_hello.h" | ||
46 | #include "gnunet-service-dht_neighbours.h" | 46 | #include "gnunet-service-dht_neighbours.h" |
47 | #include "gnunet-service-dht_nse.h" | 47 | #include "gnunet-service-dht_nse.h" |
48 | #include "gnunet-service-dht_routing.h" | 48 | #include "gnunet-service-dht_routing.h" |
@@ -329,12 +329,6 @@ struct PeerInfo | |||
329 | struct GNUNET_CORE_InformationRequestContext *info_ctx; | 329 | struct GNUNET_CORE_InformationRequestContext *info_ctx; |
330 | 330 | ||
331 | /** | 331 | /** |
332 | * HELLO message for the peer, NULL if not known. FIXME: track | ||
333 | * separately? FIXME: free!? | ||
334 | */ | ||
335 | struct GNUNET_HELLO_Message *hello; | ||
336 | |||
337 | /** | ||
338 | * Task for scheduling preference updates | 332 | * Task for scheduling preference updates |
339 | */ | 333 | */ |
340 | GNUNET_SCHEDULER_TaskIdentifier preference_task; | 334 | GNUNET_SCHEDULER_TaskIdentifier preference_task; |
@@ -422,11 +416,6 @@ static struct GNUNET_PeerIdentity my_identity; | |||
422 | */ | 416 | */ |
423 | static struct GNUNET_CORE_Handle *coreAPI; | 417 | static struct GNUNET_CORE_Handle *coreAPI; |
424 | 418 | ||
425 | /** | ||
426 | * Handle for peerinfo notifications. | ||
427 | */ | ||
428 | static struct GNUNET_PEERINFO_NotifyContext *pnc; | ||
429 | |||
430 | 419 | ||
431 | /** | 420 | /** |
432 | * Find the optimal bucket for this key. | 421 | * Find the optimal bucket for this key. |
@@ -1533,6 +1522,7 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender, | |||
1533 | struct PeerInfo *peer; | 1522 | struct PeerInfo *peer; |
1534 | unsigned int choice; | 1523 | unsigned int choice; |
1535 | GNUNET_HashCode mhash; | 1524 | GNUNET_HashCode mhash; |
1525 | const struct GNUNET_HELLO_Message *hello; | ||
1536 | 1526 | ||
1537 | /* first, check about our own HELLO */ | 1527 | /* first, check about our own HELLO */ |
1538 | if (NULL != GDS_my_hello) | 1528 | if (NULL != GDS_my_hello) |
@@ -1574,8 +1564,9 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender, | |||
1574 | if (peer == NULL) | 1564 | if (peer == NULL) |
1575 | peer = bucket->head; | 1565 | peer = bucket->head; |
1576 | GNUNET_BLOCK_mingle_hash (&peer->id.hashPubKey, bf_mutator, &mhash); | 1566 | GNUNET_BLOCK_mingle_hash (&peer->id.hashPubKey, bf_mutator, &mhash); |
1567 | hello = GDS_HELLO_get (&peer->id); | ||
1577 | } | 1568 | } |
1578 | while ( (peer->hello == NULL) || | 1569 | while ( (hello == NULL) || |
1579 | (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bf, &mhash)) ); | 1570 | (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bf, &mhash)) ); |
1580 | GDS_NEIGHBOURS_handle_reply (sender, | 1571 | GDS_NEIGHBOURS_handle_reply (sender, |
1581 | GNUNET_BLOCK_TYPE_DHT_HELLO, | 1572 | GNUNET_BLOCK_TYPE_DHT_HELLO, |
@@ -1583,8 +1574,8 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender, | |||
1583 | key, | 1574 | key, |
1584 | 0, NULL, | 1575 | 0, NULL, |
1585 | 0, NULL, | 1576 | 0, NULL, |
1586 | peer->hello, | 1577 | hello, |
1587 | GNUNET_HELLO_size (peer->hello)); | 1578 | GNUNET_HELLO_size (hello)); |
1588 | } | 1579 | } |
1589 | 1580 | ||
1590 | 1581 | ||
@@ -1832,29 +1823,6 @@ handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1832 | 1823 | ||
1833 | 1824 | ||
1834 | /** | 1825 | /** |
1835 | * Function called for each HELLO known to PEERINFO. | ||
1836 | * | ||
1837 | * @param cls closure | ||
1838 | * @param peer id of the peer, NULL for last call | ||
1839 | * @param hello hello message for the peer (can be NULL) | ||
1840 | * @param error message | ||
1841 | */ | ||
1842 | static void | ||
1843 | process_hello (void *cls, | ||
1844 | const struct GNUNET_PeerIdentity * | ||
1845 | peer, | ||
1846 | const struct GNUNET_HELLO_Message * | ||
1847 | hello, const char *err_msg) | ||
1848 | { | ||
1849 | // FIXME: consider moving HELLO processing to another file! | ||
1850 | // FIXME: first, filter HELLOs without addresses (!) | ||
1851 | // FIXME: track HELLOs (for responding to FIND PEER requests) | ||
1852 | // FIXME: add code to possibly ask core to establish connections | ||
1853 | // (using our own peerinfo is better than using FIND PEER!) | ||
1854 | } | ||
1855 | |||
1856 | |||
1857 | /** | ||
1858 | * Initialize neighbours subsystem. | 1826 | * Initialize neighbours subsystem. |
1859 | * | 1827 | * |
1860 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 1828 | * @return GNUNET_OK on success, GNUNET_SYSERR on error |
@@ -1887,9 +1855,6 @@ GDS_NEIGHBOURS_init () | |||
1887 | if (coreAPI == NULL) | 1855 | if (coreAPI == NULL) |
1888 | return GNUNET_SYSERR; | 1856 | return GNUNET_SYSERR; |
1889 | all_known_peers = GNUNET_CONTAINER_multihashmap_create (256); | 1857 | all_known_peers = GNUNET_CONTAINER_multihashmap_create (256); |
1890 | pnc = GNUNET_PEERINFO_notify (GDS_cfg, | ||
1891 | &process_hello, | ||
1892 | NULL); | ||
1893 | return GNUNET_OK; | 1858 | return GNUNET_OK; |
1894 | } | 1859 | } |
1895 | 1860 | ||
@@ -1902,11 +1867,6 @@ GDS_NEIGHBOURS_done () | |||
1902 | { | 1867 | { |
1903 | if (coreAPI == NULL) | 1868 | if (coreAPI == NULL) |
1904 | return; | 1869 | return; |
1905 | if (NULL != pnc) | ||
1906 | { | ||
1907 | GNUNET_PEERINFO_notify_cancel (pnc); | ||
1908 | pnc = NULL; | ||
1909 | } | ||
1910 | GNUNET_CORE_disconnect (coreAPI); | 1870 | GNUNET_CORE_disconnect (coreAPI); |
1911 | coreAPI = NULL; | 1871 | coreAPI = NULL; |
1912 | GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (all_known_peers)); | 1872 | GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (all_known_peers)); |