aboutsummaryrefslogtreecommitdiff
path: root/src/messenger/messenger_api_peer_store.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/messenger/messenger_api_peer_store.c')
-rw-r--r--src/messenger/messenger_api_peer_store.c49
1 files changed, 33 insertions, 16 deletions
diff --git a/src/messenger/messenger_api_peer_store.c b/src/messenger/messenger_api_peer_store.c
index f0b9eb0bb..949510960 100644
--- a/src/messenger/messenger_api_peer_store.c
+++ b/src/messenger/messenger_api_peer_store.c
@@ -37,25 +37,30 @@ init_peer_store (struct GNUNET_MESSENGER_PeerStore *store)
37 store->peers = GNUNET_CONTAINER_multishortmap_create (4, GNUNET_NO); 37 store->peers = GNUNET_CONTAINER_multishortmap_create (4, GNUNET_NO);
38} 38}
39 39
40
40static enum GNUNET_GenericReturnValue 41static enum GNUNET_GenericReturnValue
41iterate_destroy_peers (void *cls, const struct GNUNET_ShortHashCode *id, void *value) 42iterate_destroy_peers (void *cls, const struct GNUNET_ShortHashCode *id,
43 void *value)
42{ 44{
43 struct GNUNET_PeerIdentity* peer = value; 45 struct GNUNET_PeerIdentity *peer = value;
44 GNUNET_free (peer); 46 GNUNET_free (peer);
45 return GNUNET_YES; 47 return GNUNET_YES;
46} 48}
47 49
50
48void 51void
49clear_peer_store (struct GNUNET_MESSENGER_PeerStore *store) 52clear_peer_store (struct GNUNET_MESSENGER_PeerStore *store)
50{ 53{
51 GNUNET_assert ((store) && (store->peers)); 54 GNUNET_assert ((store) && (store->peers));
52 55
53 GNUNET_CONTAINER_multishortmap_iterate (store->peers, iterate_destroy_peers, NULL); 56 GNUNET_CONTAINER_multishortmap_iterate (store->peers, iterate_destroy_peers,
57 NULL);
54 GNUNET_CONTAINER_multishortmap_destroy (store->peers); 58 GNUNET_CONTAINER_multishortmap_destroy (store->peers);
55 59
56 store->peers = NULL; 60 store->peers = NULL;
57} 61}
58 62
63
59struct GNUNET_MESSENGER_ClosureVerifyPeer 64struct GNUNET_MESSENGER_ClosureVerifyPeer
60{ 65{
61 const struct GNUNET_MESSENGER_Message *message; 66 const struct GNUNET_MESSENGER_Message *message;
@@ -64,12 +69,14 @@ struct GNUNET_MESSENGER_ClosureVerifyPeer
64}; 69};
65 70
66static enum GNUNET_GenericReturnValue 71static enum GNUNET_GenericReturnValue
67verify_store_peer(void *cls, const struct GNUNET_ShortHashCode *id, void *value) 72verify_store_peer (void *cls, const struct GNUNET_ShortHashCode *id,
73 void *value)
68{ 74{
69 struct GNUNET_MESSENGER_ClosureVerifyPeer *verify = cls; 75 struct GNUNET_MESSENGER_ClosureVerifyPeer *verify = cls;
70 struct GNUNET_PeerIdentity* peer = value; 76 struct GNUNET_PeerIdentity *peer = value;
71 77
72 if ((peer) && (GNUNET_OK == verify_message_by_peer (verify->message, verify->hash, peer))) 78 if ((peer) && (GNUNET_OK == verify_message_by_peer (verify->message,
79 verify->hash, peer)))
73 { 80 {
74 verify->sender = peer; 81 verify->sender = peer;
75 return GNUNET_NO; 82 return GNUNET_NO;
@@ -78,6 +85,7 @@ verify_store_peer(void *cls, const struct GNUNET_ShortHashCode *id, void *value)
78 return GNUNET_YES; 85 return GNUNET_YES;
79} 86}
80 87
88
81struct GNUNET_PeerIdentity* 89struct GNUNET_PeerIdentity*
82get_store_peer_of (struct GNUNET_MESSENGER_PeerStore *store, 90get_store_peer_of (struct GNUNET_MESSENGER_PeerStore *store,
83 const struct GNUNET_MESSENGER_Message *message, 91 const struct GNUNET_MESSENGER_Message *message,
@@ -89,7 +97,8 @@ get_store_peer_of (struct GNUNET_MESSENGER_PeerStore *store,
89 return NULL; 97 return NULL;
90 98
91 if ((GNUNET_MESSENGER_KIND_PEER == message->header.kind) && 99 if ((GNUNET_MESSENGER_KIND_PEER == message->header.kind) &&
92 (GNUNET_OK == verify_message_by_peer (message, hash, &(message->body.peer.peer)))) 100 (GNUNET_OK == verify_message_by_peer (message, hash,
101 &(message->body.peer.peer))))
93 { 102 {
94 struct GNUNET_ShortHashCode peer_id; 103 struct GNUNET_ShortHashCode peer_id;
95 convert_peer_identity_to_id (&(message->body.peer.peer), &peer_id); 104 convert_peer_identity_to_id (&(message->body.peer.peer), &peer_id);
@@ -97,7 +106,8 @@ get_store_peer_of (struct GNUNET_MESSENGER_PeerStore *store,
97 if (0 == GNUNET_memcmp (&peer_id, &(message->header.sender_id))) 106 if (0 == GNUNET_memcmp (&peer_id, &(message->header.sender_id)))
98 update_store_peer (store, &(message->body.peer.peer)); 107 update_store_peer (store, &(message->body.peer.peer));
99 else 108 else
100 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Sender id does not match peer identity\n"); 109 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
110 "Sender id does not match peer identity\n");
101 } 111 }
102 112
103 struct GNUNET_MESSENGER_ClosureVerifyPeer verify; 113 struct GNUNET_MESSENGER_ClosureVerifyPeer verify;
@@ -105,12 +115,14 @@ get_store_peer_of (struct GNUNET_MESSENGER_PeerStore *store,
105 verify.hash = hash; 115 verify.hash = hash;
106 verify.sender = NULL; 116 verify.sender = NULL;
107 117
108 GNUNET_CONTAINER_multishortmap_get_multiple (store->peers, &(message->header.sender_id), 118 GNUNET_CONTAINER_multishortmap_get_multiple (store->peers,
119 &(message->header.sender_id),
109 verify_store_peer, &verify); 120 verify_store_peer, &verify);
110 121
111 return verify.sender; 122 return verify.sender;
112} 123}
113 124
125
114struct GNUNET_MESSENGER_ClosureFindPeer 126struct GNUNET_MESSENGER_ClosureFindPeer
115{ 127{
116 const struct GNUNET_PeerIdentity *requested; 128 const struct GNUNET_PeerIdentity *requested;
@@ -118,10 +130,10 @@ struct GNUNET_MESSENGER_ClosureFindPeer
118}; 130};
119 131
120static enum GNUNET_GenericReturnValue 132static enum GNUNET_GenericReturnValue
121find_store_peer(void *cls, const struct GNUNET_ShortHashCode *id, void *value) 133find_store_peer (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
122{ 134{
123 struct GNUNET_MESSENGER_ClosureFindPeer *find = cls; 135 struct GNUNET_MESSENGER_ClosureFindPeer *find = cls;
124 struct GNUNET_PeerIdentity* peer = value; 136 struct GNUNET_PeerIdentity *peer = value;
125 137
126 if ((peer) && (0 == GNUNET_memcmp (find->requested, peer))) 138 if ((peer) && (0 == GNUNET_memcmp (find->requested, peer)))
127 { 139 {
@@ -132,9 +144,10 @@ find_store_peer(void *cls, const struct GNUNET_ShortHashCode *id, void *value)
132 return GNUNET_YES; 144 return GNUNET_YES;
133} 145}
134 146
147
135void 148void
136update_store_peer (struct GNUNET_MESSENGER_PeerStore *store, 149update_store_peer (struct GNUNET_MESSENGER_PeerStore *store,
137 const struct GNUNET_PeerIdentity* peer) 150 const struct GNUNET_PeerIdentity *peer)
138{ 151{
139 GNUNET_assert ((store) && (store->peers) && (peer)); 152 GNUNET_assert ((store) && (store->peers) && (peer));
140 153
@@ -151,11 +164,13 @@ update_store_peer (struct GNUNET_MESSENGER_PeerStore *store,
151 if (find.match) 164 if (find.match)
152 return; 165 return;
153 166
154 struct GNUNET_PeerIdentity* copy = GNUNET_memdup (peer, sizeof (struct GNUNET_PeerIdentity)); 167 struct GNUNET_PeerIdentity *copy = GNUNET_memdup (peer, sizeof (struct
168 GNUNET_PeerIdentity));
155 GNUNET_CONTAINER_multishortmap_put (store->peers, &peer_id, copy, 169 GNUNET_CONTAINER_multishortmap_put (store->peers, &peer_id, copy,
156 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 170 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
157} 171}
158 172
173
159void 174void
160remove_store_peer (struct GNUNET_MESSENGER_PeerStore *store, 175remove_store_peer (struct GNUNET_MESSENGER_PeerStore *store,
161 const struct GNUNET_PeerIdentity *peer) 176 const struct GNUNET_PeerIdentity *peer)
@@ -172,9 +187,11 @@ remove_store_peer (struct GNUNET_MESSENGER_PeerStore *store,
172 GNUNET_CONTAINER_multishortmap_get_multiple (store->peers, &peer_id, 187 GNUNET_CONTAINER_multishortmap_get_multiple (store->peers, &peer_id,
173 find_store_peer, &find); 188 find_store_peer, &find);
174 189
175 if (!find.match) 190 if (! find.match)
176 return; 191 return;
177 192
178 if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_remove (store->peers, &peer_id, find.match)) 193 if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_remove (store->peers,
179 GNUNET_free(find.match); 194 &peer_id,
195 find.match))
196 GNUNET_free (find.match);
180} 197}