diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.c | 1712 |
1 files changed, 868 insertions, 844 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c index 5234129a4..d0c37efb1 100644 --- a/src/dht/gnunet-service-xdht_neighbours.c +++ b/src/dht/gnunet-service-xdht_neighbours.c | |||
@@ -45,7 +45,7 @@ | |||
45 | #include "dht.h" | 45 | #include "dht.h" |
46 | 46 | ||
47 | /** | 47 | /** |
48 | * TODO: | 48 | * TODO: |
49 | * 1. In X-Vine paper, there is no policy defined for replicating the data to | 49 | * 1. In X-Vine paper, there is no policy defined for replicating the data to |
50 | * recover in case of peer failure. We can do it in Chord way. In R5N, the key | 50 | * recover in case of peer failure. We can do it in Chord way. In R5N, the key |
51 | * is hashed and then data is stored according to the key value generated after | 51 | * is hashed and then data is stored according to the key value generated after |
@@ -54,7 +54,7 @@ | |||
54 | 54 | ||
55 | 55 | ||
56 | /** | 56 | /** |
57 | * Maximum possible fingers (including predecessor) of a peer | 57 | * Maximum possible fingers (including predecessor) of a peer |
58 | */ | 58 | */ |
59 | #define MAX_FINGERS 65 | 59 | #define MAX_FINGERS 65 |
60 | 60 | ||
@@ -69,7 +69,7 @@ | |||
69 | #define DHT_FIND_FINGER_TRAIL_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2) | 69 | #define DHT_FIND_FINGER_TRAIL_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2) |
70 | 70 | ||
71 | /** | 71 | /** |
72 | * How long to wait before sending another verify successor message. | 72 | * How long to wait before sending another verify successor message. |
73 | */ | 73 | */ |
74 | #define DHT_SEND_VERIFY_SUCCESSOR_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) | 74 | #define DHT_SEND_VERIFY_SUCCESSOR_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) |
75 | 75 | ||
@@ -79,9 +79,9 @@ | |||
79 | #define GET_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2) | 79 | #define GET_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2) |
80 | 80 | ||
81 | /** | 81 | /** |
82 | * Duration for which I may remain congested. | 82 | * Duration for which I may remain congested. |
83 | * Note: Its a static value. In future, a peer may do some analysis and calculate | 83 | * Note: Its a static value. In future, a peer may do some analysis and calculate |
84 | * congestion_timeout based on 'some' parameters. | 84 | * congestion_timeout based on 'some' parameters. |
85 | */ | 85 | */ |
86 | #define CONGESTION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2) | 86 | #define CONGESTION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2) |
87 | 87 | ||
@@ -101,13 +101,13 @@ | |||
101 | #define PREDECESSOR_FINGER_ID 64 | 101 | #define PREDECESSOR_FINGER_ID 64 |
102 | 102 | ||
103 | /** | 103 | /** |
104 | * Wrap around in peer identity circle. | 104 | * Wrap around in peer identity circle. |
105 | */ | 105 | */ |
106 | #define PEER_IDENTITES_WRAP_AROUND pow(2, 64) - 1 | 106 | #define PEER_IDENTITES_WRAP_AROUND pow(2, 64) - 1 |
107 | 107 | ||
108 | /** | 108 | /** |
109 | * FIXME: Its use only at 3 places check if you can remove it. | 109 | * FIXME: Its use only at 3 places check if you can remove it. |
110 | * To check if a finger is predecessor or not. | 110 | * To check if a finger is predecessor or not. |
111 | */ | 111 | */ |
112 | enum GDS_NEIGHBOURS_finger_type | 112 | enum GDS_NEIGHBOURS_finger_type |
113 | { | 113 | { |
@@ -144,7 +144,7 @@ struct PeerPutMessage | |||
144 | 144 | ||
145 | /** | 145 | /** |
146 | * Replication level for this message | 146 | * Replication level for this message |
147 | * In the current implementation, this value is not used. | 147 | * In the current implementation, this value is not used. |
148 | */ | 148 | */ |
149 | uint32_t desired_replication_level GNUNET_PACKED; | 149 | uint32_t desired_replication_level GNUNET_PACKED; |
150 | 150 | ||
@@ -152,24 +152,24 @@ struct PeerPutMessage | |||
152 | * Length of the PUT path that follows (if tracked). | 152 | * Length of the PUT path that follows (if tracked). |
153 | */ | 153 | */ |
154 | uint32_t put_path_length GNUNET_PACKED; | 154 | uint32_t put_path_length GNUNET_PACKED; |
155 | 155 | ||
156 | /** | 156 | /** |
157 | * Best known destination (could be my friend or finger) which should | 157 | * Best known destination (could be my friend or finger) which should |
158 | * get this message next. | 158 | * get this message next. |
159 | */ | 159 | */ |
160 | struct GNUNET_PeerIdentity best_known_destination; | 160 | struct GNUNET_PeerIdentity best_known_destination; |
161 | 161 | ||
162 | /** | 162 | /** |
163 | * In case best_known_destination is a finger, then trail to reach | 163 | * In case best_known_destination is a finger, then trail to reach |
164 | * to that finger. Else its default value is 0. | 164 | * to that finger. Else its default value is 0. |
165 | */ | 165 | */ |
166 | struct GNUNET_HashCode intermediate_trail_id; | 166 | struct GNUNET_HashCode intermediate_trail_id; |
167 | 167 | ||
168 | /** | 168 | /** |
169 | * When does the content expire? | 169 | * When does the content expire? |
170 | */ | 170 | */ |
171 | struct GNUNET_TIME_AbsoluteNBO expiration_time; | 171 | struct GNUNET_TIME_AbsoluteNBO expiration_time; |
172 | 172 | ||
173 | /** | 173 | /** |
174 | * The key to store the value under. | 174 | * The key to store the value under. |
175 | */ | 175 | */ |
@@ -178,7 +178,7 @@ struct PeerPutMessage | |||
178 | /* put path (if tracked) */ | 178 | /* put path (if tracked) */ |
179 | 179 | ||
180 | /* Payload */ | 180 | /* Payload */ |
181 | 181 | ||
182 | }; | 182 | }; |
183 | 183 | ||
184 | /** | 184 | /** |
@@ -190,7 +190,7 @@ struct PeerGetMessage | |||
190 | * Type: #GNUNET_MESSAGE_TYPE_XDHT_P2P_GET | 190 | * Type: #GNUNET_MESSAGE_TYPE_XDHT_P2P_GET |
191 | */ | 191 | */ |
192 | struct GNUNET_MessageHeader header; | 192 | struct GNUNET_MessageHeader header; |
193 | 193 | ||
194 | /** | 194 | /** |
195 | * Processing options | 195 | * Processing options |
196 | */ | 196 | */ |
@@ -200,40 +200,40 @@ struct PeerGetMessage | |||
200 | * Desired content type. | 200 | * Desired content type. |
201 | */ | 201 | */ |
202 | uint32_t block_type GNUNET_PACKED; | 202 | uint32_t block_type GNUNET_PACKED; |
203 | 203 | ||
204 | /** | 204 | /** |
205 | * Hop count | 205 | * Hop count |
206 | */ | 206 | */ |
207 | uint32_t hop_count GNUNET_PACKED; | 207 | uint32_t hop_count GNUNET_PACKED; |
208 | 208 | ||
209 | /** | 209 | /** |
210 | * Desired replication level for this request. | 210 | * Desired replication level for this request. |
211 | * In the current implementation, this value is not used. | 211 | * In the current implementation, this value is not used. |
212 | */ | 212 | */ |
213 | uint32_t desired_replication_level GNUNET_PACKED; | 213 | uint32_t desired_replication_level GNUNET_PACKED; |
214 | 214 | ||
215 | /** | 215 | /** |
216 | * Total number of peers in get path. | 216 | * Total number of peers in get path. |
217 | */ | 217 | */ |
218 | unsigned int get_path_length; | 218 | unsigned int get_path_length; |
219 | 219 | ||
220 | /** | 220 | /** |
221 | * Best known destination (could be my friend or finger) which should | 221 | * Best known destination (could be my friend or finger) which should |
222 | * get this message next. | 222 | * get this message next. |
223 | */ | 223 | */ |
224 | struct GNUNET_PeerIdentity best_known_destination; | 224 | struct GNUNET_PeerIdentity best_known_destination; |
225 | 225 | ||
226 | /** | 226 | /** |
227 | * In case best_known_destination is a finger, then trail to reach | 227 | * In case best_known_destination is a finger, then trail to reach |
228 | * to that finger. Else its default value is 0. | 228 | * to that finger. Else its default value is 0. |
229 | */ | 229 | */ |
230 | struct GNUNET_HashCode intermediate_trail_id; | 230 | struct GNUNET_HashCode intermediate_trail_id; |
231 | 231 | ||
232 | /** | 232 | /** |
233 | * The key we are looking for. | 233 | * The key we are looking for. |
234 | */ | 234 | */ |
235 | struct GNUNET_HashCode key; | 235 | struct GNUNET_HashCode key; |
236 | 236 | ||
237 | /* Get path. */ | 237 | /* Get path. */ |
238 | /* struct GNUNET_PeerIdentity[]*/ | 238 | /* struct GNUNET_PeerIdentity[]*/ |
239 | }; | 239 | }; |
@@ -252,23 +252,23 @@ struct PeerGetResultMessage | |||
252 | * The type for the data. | 252 | * The type for the data. |
253 | */ | 253 | */ |
254 | uint32_t type GNUNET_PACKED; | 254 | uint32_t type GNUNET_PACKED; |
255 | 255 | ||
256 | /** | 256 | /** |
257 | * Number of peers recorded in the outgoing path from source to the | 257 | * Number of peers recorded in the outgoing path from source to the |
258 | * stored location of this message. | 258 | * stored location of this message. |
259 | */ | 259 | */ |
260 | uint32_t put_path_length GNUNET_PACKED; | 260 | uint32_t put_path_length GNUNET_PACKED; |
261 | 261 | ||
262 | /** | 262 | /** |
263 | * Length of the GET path that follows (if tracked). | 263 | * Length of the GET path that follows (if tracked). |
264 | */ | 264 | */ |
265 | uint32_t get_path_length GNUNET_PACKED; | 265 | uint32_t get_path_length GNUNET_PACKED; |
266 | 266 | ||
267 | /** | 267 | /** |
268 | * Peer which queried for get and should get the result. | 268 | * Peer which queried for get and should get the result. |
269 | */ | 269 | */ |
270 | struct GNUNET_PeerIdentity querying_peer; | 270 | struct GNUNET_PeerIdentity querying_peer; |
271 | 271 | ||
272 | /** | 272 | /** |
273 | * When does the content expire? | 273 | * When does the content expire? |
274 | */ | 274 | */ |
@@ -278,7 +278,7 @@ struct PeerGetResultMessage | |||
278 | * The key of the corresponding GET request. | 278 | * The key of the corresponding GET request. |
279 | */ | 279 | */ |
280 | struct GNUNET_HashCode key; | 280 | struct GNUNET_HashCode key; |
281 | 281 | ||
282 | /* put path (if tracked) */ | 282 | /* put path (if tracked) */ |
283 | 283 | ||
284 | /* get path (if tracked) */ | 284 | /* get path (if tracked) */ |
@@ -296,12 +296,12 @@ struct PeerTrailSetupMessage | |||
296 | * Type: #GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_SETUP | 296 | * Type: #GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_SETUP |
297 | */ | 297 | */ |
298 | struct GNUNET_MessageHeader header; | 298 | struct GNUNET_MessageHeader header; |
299 | 299 | ||
300 | /** | 300 | /** |
301 | * Is source_peer trying to setup the trail to a predecessor or any finger. | 301 | * Is source_peer trying to setup the trail to a predecessor or any finger. |
302 | */ | 302 | */ |
303 | uint32_t is_predecessor; | 303 | uint32_t is_predecessor; |
304 | 304 | ||
305 | /** | 305 | /** |
306 | * Peer closest to this value will be our finger. | 306 | * Peer closest to this value will be our finger. |
307 | */ | 307 | */ |
@@ -314,20 +314,24 @@ struct PeerTrailSetupMessage | |||
314 | 314 | ||
315 | /** | 315 | /** |
316 | * Best known destination (could be my friend or finger) which should | 316 | * Best known destination (could be my friend or finger) which should |
317 | * get this message next. | 317 | * get this message next. |
318 | * | ||
319 | * FIXME: this could be removed if we include trail_source / trail_dest | ||
320 | * in the routing table. This way we save 32 bytes of bandwidth by using | ||
321 | * extra 8 bytes of memory (2 * sizeof (GNUNET_PEER_ID)) | ||
318 | */ | 322 | */ |
319 | struct GNUNET_PeerIdentity best_known_destination; | 323 | struct GNUNET_PeerIdentity best_known_destination; |
320 | 324 | ||
321 | /** | 325 | /** |
322 | * In case best_known_destination is a finger, then trail id of trail to | 326 | * In case best_known_destination is a finger, then trail id of trail to |
323 | * reach to this finger. | 327 | * reach to this finger. |
324 | */ | 328 | */ |
325 | struct GNUNET_HashCode intermediate_trail_id; | 329 | struct GNUNET_HashCode intermediate_trail_id; |
326 | 330 | ||
327 | /** | 331 | /** |
328 | * Trail id for trail which we are trying to setup. | 332 | * Trail id for trail which we are trying to setup. |
329 | */ | 333 | */ |
330 | struct GNUNET_HashCode trail_id; | 334 | struct GNUNET_HashCode trail_id; |
331 | 335 | ||
332 | /* List of peers which are part of trail setup so far. | 336 | /* List of peers which are part of trail setup so far. |
333 | * Trail does NOT include source_peer and peer which will be closest to | 337 | * Trail does NOT include source_peer and peer which will be closest to |
@@ -355,27 +359,27 @@ struct PeerTrailSetupResultMessage | |||
355 | /** | 359 | /** |
356 | * Peer which started trail_setup to find trail to finger_identity | 360 | * Peer which started trail_setup to find trail to finger_identity |
357 | */ | 361 | */ |
358 | struct GNUNET_PeerIdentity querying_peer; | 362 | struct GNUNET_PeerIdentity querying_peer; |
359 | 363 | ||
360 | /** | 364 | /** |
361 | * Is the trail setup to querying_peer's predecessor or finger? | 365 | * Is the trail setup to querying_peer's predecessor or finger? |
362 | */ | 366 | */ |
363 | uint32_t is_predecessor; | 367 | uint32_t is_predecessor; |
364 | 368 | ||
365 | /** | 369 | /** |
366 | * Value to which finger_identity is the closest peer. | 370 | * Value to which finger_identity is the closest peer. |
367 | */ | 371 | */ |
368 | uint64_t ulitmate_destination_finger_value; | 372 | uint64_t ulitmate_destination_finger_value; |
369 | 373 | ||
370 | /** | 374 | /** |
371 | * Identifier of the trail from querying peer to finger_identity, NOT | 375 | * Identifier of the trail from querying peer to finger_identity, NOT |
372 | * including both endpoints. | 376 | * including both endpoints. |
373 | */ | 377 | */ |
374 | struct GNUNET_HashCode trail_id; | 378 | struct GNUNET_HashCode trail_id; |
375 | 379 | ||
376 | /* List of peers which are part of the trail from querying peer to | 380 | /* List of peers which are part of the trail from querying peer to |
377 | * finger_identity, NOT including both endpoints. | 381 | * finger_identity, NOT including both endpoints. |
378 | * struct GNUNET_PeerIdentity trail[] | 382 | * struct GNUNET_PeerIdentity trail[] |
379 | */ | 383 | */ |
380 | }; | 384 | }; |
381 | 385 | ||
@@ -404,9 +408,9 @@ struct PeerVerifySuccessorMessage | |||
404 | */ | 408 | */ |
405 | struct GNUNET_HashCode trail_id; | 409 | struct GNUNET_HashCode trail_id; |
406 | 410 | ||
407 | /* List of the peers which are part of trail to reach from source_peer | 411 | /* List of the peers which are part of trail to reach from source_peer |
408 | * to successor, NOT including them | 412 | * to successor, NOT including them |
409 | * struct GNUNET_PeerIdentity trail[] | 413 | * struct GNUNET_PeerIdentity trail[] |
410 | */ | 414 | */ |
411 | }; | 415 | }; |
412 | 416 | ||
@@ -433,7 +437,7 @@ struct PeerVerifySuccessorResultMessage | |||
433 | /** | 437 | /** |
434 | * Current Predecessor of source_successor. It can be same as querying peer | 438 | * Current Predecessor of source_successor. It can be same as querying peer |
435 | * or different. In case it is different then it can be querying_peer's | 439 | * or different. In case it is different then it can be querying_peer's |
436 | * probable successor. | 440 | * probable successor. |
437 | */ | 441 | */ |
438 | struct GNUNET_PeerIdentity probable_successor; | 442 | struct GNUNET_PeerIdentity probable_successor; |
439 | 443 | ||
@@ -479,8 +483,8 @@ struct PeerNotifyNewSuccessorMessage | |||
479 | */ | 483 | */ |
480 | struct GNUNET_HashCode trail_id; | 484 | struct GNUNET_HashCode trail_id; |
481 | 485 | ||
482 | /* List of peers in trail from source_peer to new_successor, | 486 | /* List of peers in trail from source_peer to new_successor, |
483 | * NOT including the endpoints. | 487 | * NOT including the endpoints. |
484 | * struct GNUNET_PeerIdentity trail[] | 488 | * struct GNUNET_PeerIdentity trail[] |
485 | */ | 489 | */ |
486 | }; | 490 | }; |
@@ -552,7 +556,7 @@ struct PeerTrailRejectionMessage | |||
552 | struct GNUNET_PeerIdentity source_peer; | 556 | struct GNUNET_PeerIdentity source_peer; |
553 | 557 | ||
554 | /** | 558 | /** |
555 | * Peer which sent trail rejection message as it it congested. | 559 | * Peer which sent trail rejection message as it it congested. |
556 | */ | 560 | */ |
557 | struct GNUNET_PeerIdentity congested_peer; | 561 | struct GNUNET_PeerIdentity congested_peer; |
558 | 562 | ||
@@ -571,7 +575,7 @@ struct PeerTrailRejectionMessage | |||
571 | * Identifier for the trail that source peer is trying to setup. | 575 | * Identifier for the trail that source peer is trying to setup. |
572 | */ | 576 | */ |
573 | struct GNUNET_HashCode trail_id; | 577 | struct GNUNET_HashCode trail_id; |
574 | 578 | ||
575 | /** | 579 | /** |
576 | * Relative time for which congested_peer will remain congested. | 580 | * Relative time for which congested_peer will remain congested. |
577 | */ | 581 | */ |
@@ -661,7 +665,7 @@ struct FriendInfo | |||
661 | 665 | ||
662 | /** | 666 | /** |
663 | * Number of trails for which this friend is the first hop or if the friend | 667 | * Number of trails for which this friend is the first hop or if the friend |
664 | * is finger. | 668 | * is finger. |
665 | */ | 669 | */ |
666 | unsigned int trails_count; | 670 | unsigned int trails_count; |
667 | 671 | ||
@@ -695,7 +699,7 @@ struct FriendInfo | |||
695 | /** | 699 | /** |
696 | * An individual element of the trail to reach to a finger. | 700 | * An individual element of the trail to reach to a finger. |
697 | */ | 701 | */ |
698 | struct Trail_Element | 702 | struct Trail_Element |
699 | { | 703 | { |
700 | /** | 704 | /** |
701 | * Pointer to next item in the list | 705 | * Pointer to next item in the list |
@@ -714,9 +718,9 @@ struct Trail_Element | |||
714 | }; | 718 | }; |
715 | 719 | ||
716 | /** | 720 | /** |
717 | * Information about an individual trail. | 721 | * Information about an individual trail. |
718 | */ | 722 | */ |
719 | struct Trail | 723 | struct Trail |
720 | { | 724 | { |
721 | /** | 725 | /** |
722 | * Head of trail. | 726 | * Head of trail. |
@@ -737,9 +741,9 @@ struct Trail | |||
737 | * Length of trail pointed | 741 | * Length of trail pointed |
738 | */ | 742 | */ |
739 | unsigned int trail_length; | 743 | unsigned int trail_length; |
740 | 744 | ||
741 | /** | 745 | /** |
742 | * Is there a valid trail entry. | 746 | * Is there a valid trail entry. |
743 | */ | 747 | */ |
744 | unsigned int is_present; | 748 | unsigned int is_present; |
745 | }; | 749 | }; |
@@ -755,10 +759,10 @@ struct FingerInfo | |||
755 | struct GNUNET_PeerIdentity finger_identity; | 759 | struct GNUNET_PeerIdentity finger_identity; |
756 | 760 | ||
757 | /** | 761 | /** |
758 | * Is any finger stored at this finger index. | 762 | * Is any finger stored at this finger index. |
759 | */ | 763 | */ |
760 | unsigned int is_present; | 764 | unsigned int is_present; |
761 | 765 | ||
762 | /** | 766 | /** |
763 | * Index in finger peer map | 767 | * Index in finger peer map |
764 | */ | 768 | */ |
@@ -773,7 +777,7 @@ struct FingerInfo | |||
773 | /** | 777 | /** |
774 | * Array of trails to reach to this finger. | 778 | * Array of trails to reach to this finger. |
775 | */ | 779 | */ |
776 | struct Trail trail_list[MAXIMUM_TRAILS_PER_FINGER]; | 780 | struct Trail trail_list[MAXIMUM_TRAILS_PER_FINGER]; |
777 | }; | 781 | }; |
778 | 782 | ||
779 | 783 | ||
@@ -785,15 +789,15 @@ struct FingerInfo | |||
785 | struct Closest_Peer | 789 | struct Closest_Peer |
786 | { | 790 | { |
787 | /** | 791 | /** |
788 | * Destination finger value. | 792 | * Destination finger value. |
789 | */ | 793 | */ |
790 | uint64_t destination_finger_value; | 794 | uint64_t destination_finger_value; |
791 | 795 | ||
792 | /** | 796 | /** |
793 | * Is finger_value a predecessor or any other finger. | 797 | * Is finger_value a predecessor or any other finger. |
794 | */ | 798 | */ |
795 | unsigned int is_predecessor; | 799 | unsigned int is_predecessor; |
796 | 800 | ||
797 | /** | 801 | /** |
798 | * Trail id to reach to peer. | 802 | * Trail id to reach to peer. |
799 | * In case peer is my identity or friend, it is set to 0. | 803 | * In case peer is my identity or friend, it is set to 0. |
@@ -805,7 +809,7 @@ struct Closest_Peer | |||
805 | * In case of finger it is finger identity. | 809 | * In case of finger it is finger identity. |
806 | */ | 810 | */ |
807 | struct GNUNET_PeerIdentity best_known_destination; | 811 | struct GNUNET_PeerIdentity best_known_destination; |
808 | 812 | ||
809 | /** | 813 | /** |
810 | * In case best_known_destination is a finger, then first friend in the trail | 814 | * In case best_known_destination is a finger, then first friend in the trail |
811 | * to reach to it. In other case, same as best_known_destination. | 815 | * to reach to it. In other case, same as best_known_destination. |
@@ -842,8 +846,8 @@ struct Selected_Finger_Trail | |||
842 | static GNUNET_SCHEDULER_TaskIdentifier find_finger_trail_task; | 846 | static GNUNET_SCHEDULER_TaskIdentifier find_finger_trail_task; |
843 | 847 | ||
844 | /** | 848 | /** |
845 | * Task that sends verify successor message. This task is started when we get | 849 | * Task that sends verify successor message. This task is started when we get |
846 | * our successor for the first time. | 850 | * our successor for the first time. |
847 | */ | 851 | */ |
848 | static GNUNET_SCHEDULER_TaskIdentifier send_verify_successor_task; | 852 | static GNUNET_SCHEDULER_TaskIdentifier send_verify_successor_task; |
849 | 853 | ||
@@ -858,7 +862,7 @@ static struct GNUNET_PeerIdentity my_identity; | |||
858 | static struct GNUNET_CONTAINER_MultiPeerMap *friend_peermap; | 862 | static struct GNUNET_CONTAINER_MultiPeerMap *friend_peermap; |
859 | 863 | ||
860 | /** | 864 | /** |
861 | * Array of all the fingers. | 865 | * Array of all the fingers. |
862 | */ | 866 | */ |
863 | static struct FingerInfo finger_table [MAX_FINGERS]; | 867 | static struct FingerInfo finger_table [MAX_FINGERS]; |
864 | 868 | ||
@@ -902,7 +906,7 @@ core_transmit_notify (void *cls, size_t size, void *buf) | |||
902 | struct P2PPendingMessage *pending; | 906 | struct P2PPendingMessage *pending; |
903 | size_t off; | 907 | size_t off; |
904 | size_t msize; | 908 | size_t msize; |
905 | 909 | ||
906 | peer->th = NULL; | 910 | peer->th = NULL; |
907 | while ((NULL != (pending = peer->head)) && | 911 | while ((NULL != (pending = peer->head)) && |
908 | (0 == GNUNET_TIME_absolute_get_remaining (pending->timeout).rel_value_us)) | 912 | (0 == GNUNET_TIME_absolute_get_remaining (pending->timeout).rel_value_us)) |
@@ -970,7 +974,7 @@ process_friend_queue (struct FriendInfo *peer) | |||
970 | return; | 974 | return; |
971 | if (NULL != peer->th) | 975 | if (NULL != peer->th) |
972 | return; | 976 | return; |
973 | 977 | ||
974 | GNUNET_STATISTICS_update (GDS_stats, | 978 | GNUNET_STATISTICS_update (GDS_stats, |
975 | gettext_noop | 979 | gettext_noop |
976 | ("# Bytes of bandwidth requested from core"), | 980 | ("# Bytes of bandwidth requested from core"), |
@@ -990,18 +994,18 @@ process_friend_queue (struct FriendInfo *peer) | |||
990 | /** | 994 | /** |
991 | * Construct a trail setup message and forward it to target_friend | 995 | * Construct a trail setup message and forward it to target_friend |
992 | * @param source_peer Peer which wants to setup the trail | 996 | * @param source_peer Peer which wants to setup the trail |
993 | * @param ultimate_destination_finger_value Peer identity closest to this value | 997 | * @param ultimate_destination_finger_value Peer identity closest to this value |
994 | * will be finger to @a source_peer | 998 | * will be finger to @a source_peer |
995 | * @param best_known_destination Best known destination (could be finger or friend) | 999 | * @param best_known_destination Best known destination (could be finger or friend) |
996 | * which should get this message. In case it is | 1000 | * which should get this message. In case it is |
997 | * friend, then it is same as target_friend | 1001 | * friend, then it is same as target_friend |
998 | * @param target_friend Friend to which message is forwarded now. | 1002 | * @param target_friend Friend to which message is forwarded now. |
999 | * @param trail_length Total number of peers in trail setup so far. | 1003 | * @param trail_length Total number of peers in trail setup so far. |
1000 | * @param trail_peer_list Trail setup so far | 1004 | * @param trail_peer_list Trail setup so far |
1001 | * @param is_predecessor Is @a source_peer looking for trail to a predecessor or not. | 1005 | * @param is_predecessor Is @a source_peer looking for trail to a predecessor or not. |
1002 | * @param trail_id Unique identifier for the trail we are trying to setup. | 1006 | * @param trail_id Unique identifier for the trail we are trying to setup. |
1003 | * @param intermediate_trail_id Trail id of intermediate trail to reach to | 1007 | * @param intermediate_trail_id Trail id of intermediate trail to reach to |
1004 | * best_known_destination when its a finger. If not | 1008 | * best_known_destination when its a finger. If not |
1005 | * used then set to 0. | 1009 | * used then set to 0. |
1006 | */ | 1010 | */ |
1007 | void | 1011 | void |
@@ -1034,7 +1038,7 @@ GDS_NEIGHBOURS_send_trail_setup (struct GNUNET_PeerIdentity source_peer, | |||
1034 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), | 1038 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), |
1035 | 1, GNUNET_NO); | 1039 | 1, GNUNET_NO); |
1036 | } | 1040 | } |
1037 | 1041 | ||
1038 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 1042 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); |
1039 | pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); | 1043 | pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); |
1040 | tsm = (struct PeerTrailSetupMessage *) &pending[1]; | 1044 | tsm = (struct PeerTrailSetupMessage *) &pending[1]; |
@@ -1053,7 +1057,7 @@ GDS_NEIGHBOURS_send_trail_setup (struct GNUNET_PeerIdentity source_peer, | |||
1053 | peer_list = (struct GNUNET_PeerIdentity *) &tsm[1]; | 1057 | peer_list = (struct GNUNET_PeerIdentity *) &tsm[1]; |
1054 | memcpy (peer_list, trail_peer_list, trail_length * sizeof(struct GNUNET_PeerIdentity)); | 1058 | memcpy (peer_list, trail_peer_list, trail_length * sizeof(struct GNUNET_PeerIdentity)); |
1055 | } | 1059 | } |
1056 | 1060 | ||
1057 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); | 1061 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); |
1058 | target_friend->pending_count++; | 1062 | target_friend->pending_count++; |
1059 | process_friend_queue (target_friend); | 1063 | process_friend_queue (target_friend); |
@@ -1063,15 +1067,15 @@ GDS_NEIGHBOURS_send_trail_setup (struct GNUNET_PeerIdentity source_peer, | |||
1063 | /** | 1067 | /** |
1064 | * Construct a trail setup result message and forward it to target friend. | 1068 | * Construct a trail setup result message and forward it to target friend. |
1065 | * @param querying_peer Peer which sent the trail setup request and should get | 1069 | * @param querying_peer Peer which sent the trail setup request and should get |
1066 | * the result back. | 1070 | * the result back. |
1067 | * @param Finger Peer to which the trail has been setup to. | 1071 | * @param Finger Peer to which the trail has been setup to. |
1068 | * @param target_friend Friend to which this message should be forwarded. | 1072 | * @param target_friend Friend to which this message should be forwarded. |
1069 | * @param trail_length Numbers of peers in the trail. | 1073 | * @param trail_length Numbers of peers in the trail. |
1070 | * @param trail_peer_list Peers which are part of the trail from | 1074 | * @param trail_peer_list Peers which are part of the trail from |
1071 | * querying_peer to Finger, NOT including them. | 1075 | * querying_peer to Finger, NOT including them. |
1072 | * @param is_predecessor Is @a Finger predecessor to @a querying_peer ? | 1076 | * @param is_predecessor Is @a Finger predecessor to @a querying_peer ? |
1073 | * @param ultimate_destination_finger_value Value to which @a finger is the closest | 1077 | * @param ultimate_destination_finger_value Value to which @a finger is the closest |
1074 | * peer. | 1078 | * peer. |
1075 | * @param trail_id Unique identifier of the trail. | 1079 | * @param trail_id Unique identifier of the trail. |
1076 | */ | 1080 | */ |
1077 | void | 1081 | void |
@@ -1100,8 +1104,9 @@ GDS_NEIGHBOURS_send_trail_setup_result (struct GNUNET_PeerIdentity querying_peer | |||
1100 | 1104 | ||
1101 | if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND) | 1105 | if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND) |
1102 | { | 1106 | { |
1103 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), | 1107 | GNUNET_STATISTICS_update (GDS_stats, |
1104 | 1, GNUNET_NO); | 1108 | gettext_noop ("# P2P messages dropped due to full queue"), |
1109 | 1, GNUNET_NO); | ||
1105 | } | 1110 | } |
1106 | 1111 | ||
1107 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 1112 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); |
@@ -1115,14 +1120,12 @@ GDS_NEIGHBOURS_send_trail_setup_result (struct GNUNET_PeerIdentity querying_peer | |||
1115 | tsrm->finger_identity = finger; | 1120 | tsrm->finger_identity = finger; |
1116 | tsrm->is_predecessor = htonl (is_predecessor); | 1121 | tsrm->is_predecessor = htonl (is_predecessor); |
1117 | tsrm->trail_id = trail_id; | 1122 | tsrm->trail_id = trail_id; |
1118 | tsrm->ulitmate_destination_finger_value = | 1123 | tsrm->ulitmate_destination_finger_value = |
1119 | GNUNET_htonll (ultimate_destination_finger_value); | 1124 | GNUNET_htonll (ultimate_destination_finger_value); |
1120 | peer_list = (struct GNUNET_PeerIdentity *) &tsrm[1]; | 1125 | peer_list = (struct GNUNET_PeerIdentity *) &tsrm[1]; |
1121 | 1126 | ||
1122 | if (trail_length > 0) | 1127 | memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); |
1123 | { | 1128 | |
1124 | memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); | ||
1125 | } | ||
1126 | /* Send the message to chosen friend. */ | 1129 | /* Send the message to chosen friend. */ |
1127 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); | 1130 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); |
1128 | target_friend->pending_count++; | 1131 | target_friend->pending_count++; |
@@ -1133,7 +1136,7 @@ GDS_NEIGHBOURS_send_trail_setup_result (struct GNUNET_PeerIdentity querying_peer | |||
1133 | /** | 1136 | /** |
1134 | * Send trail rejection message to target friend | 1137 | * Send trail rejection message to target friend |
1135 | * @param source_peer Peer which is trying to setup the trail. | 1138 | * @param source_peer Peer which is trying to setup the trail. |
1136 | * @param ultimate_destination_finger_value Peer closest to this value will be | 1139 | * @param ultimate_destination_finger_value Peer closest to this value will be |
1137 | * @a source_peer's finger | 1140 | * @a source_peer's finger |
1138 | * @param congested_peer Peer which sent this message as it is congested. | 1141 | * @param congested_peer Peer which sent this message as it is congested. |
1139 | * @param is_predecessor Is source_peer looking for trail to a predecessor or not. | 1142 | * @param is_predecessor Is source_peer looking for trail to a predecessor or not. |
@@ -1161,7 +1164,7 @@ GDS_NEIGHBOURS_send_trail_rejection (struct GNUNET_PeerIdentity source_peer, | |||
1161 | struct P2PPendingMessage *pending; | 1164 | struct P2PPendingMessage *pending; |
1162 | struct GNUNET_PeerIdentity *peer_list; | 1165 | struct GNUNET_PeerIdentity *peer_list; |
1163 | size_t msize; | 1166 | size_t msize; |
1164 | 1167 | ||
1165 | msize = sizeof (struct PeerTrailRejectionMessage) + | 1168 | msize = sizeof (struct PeerTrailRejectionMessage) + |
1166 | (trail_length * sizeof (struct GNUNET_PeerIdentity)); | 1169 | (trail_length * sizeof (struct GNUNET_PeerIdentity)); |
1167 | 1170 | ||
@@ -1176,7 +1179,7 @@ GDS_NEIGHBOURS_send_trail_rejection (struct GNUNET_PeerIdentity source_peer, | |||
1176 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), | 1179 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), |
1177 | 1, GNUNET_NO); | 1180 | 1, GNUNET_NO); |
1178 | } | 1181 | } |
1179 | 1182 | ||
1180 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 1183 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); |
1181 | pending->importance = 0; | 1184 | pending->importance = 0; |
1182 | pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); | 1185 | pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); |
@@ -1189,7 +1192,7 @@ GDS_NEIGHBOURS_send_trail_rejection (struct GNUNET_PeerIdentity source_peer, | |||
1189 | trm->congestion_time = congestion_timeout; | 1192 | trm->congestion_time = congestion_timeout; |
1190 | trm->is_predecessor = htonl (is_predecessor); | 1193 | trm->is_predecessor = htonl (is_predecessor); |
1191 | trm->trail_id = trail_id; | 1194 | trm->trail_id = trail_id; |
1192 | trm->ultimate_destination_finger_value = | 1195 | trm->ultimate_destination_finger_value = |
1193 | GNUNET_htonll (ultimate_destination_finger_value); | 1196 | GNUNET_htonll (ultimate_destination_finger_value); |
1194 | 1197 | ||
1195 | peer_list = (struct GNUNET_PeerIdentity *) &trm[1]; | 1198 | peer_list = (struct GNUNET_PeerIdentity *) &trm[1]; |
@@ -1197,7 +1200,7 @@ GDS_NEIGHBOURS_send_trail_rejection (struct GNUNET_PeerIdentity source_peer, | |||
1197 | { | 1200 | { |
1198 | memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); | 1201 | memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); |
1199 | } | 1202 | } |
1200 | 1203 | ||
1201 | /* Send the message to chosen friend. */ | 1204 | /* Send the message to chosen friend. */ |
1202 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); | 1205 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); |
1203 | target_friend->pending_count++; | 1206 | target_friend->pending_count++; |
@@ -1210,11 +1213,11 @@ GDS_NEIGHBOURS_send_trail_rejection (struct GNUNET_PeerIdentity source_peer, | |||
1210 | * @param source_peer Peer which wants to verify its successor. | 1213 | * @param source_peer Peer which wants to verify its successor. |
1211 | * @param successor Peer which is @a source_peer's current successor. | 1214 | * @param successor Peer which is @a source_peer's current successor. |
1212 | * @param trail_id Unique Identifier of trail from @a source_peer to @a successor, | 1215 | * @param trail_id Unique Identifier of trail from @a source_peer to @a successor, |
1213 | * NOT including them. | 1216 | * NOT including them. |
1214 | * @param trail List of peers which are part of trail to reach from @a source_peer | 1217 | * @param trail List of peers which are part of trail to reach from @a source_peer |
1215 | * to @a successor, NOT including them. | 1218 | * to @a successor, NOT including them. |
1216 | * @param trail_length Total number of peers in @a trail. | 1219 | * @param trail_length Total number of peers in @a trail. |
1217 | * @param target_friend Next friend to get this message. | 1220 | * @param target_friend Next friend to get this message. |
1218 | */ | 1221 | */ |
1219 | void | 1222 | void |
1220 | GDS_NEIGHBOURS_send_verify_successor_message (struct GNUNET_PeerIdentity source_peer, | 1223 | GDS_NEIGHBOURS_send_verify_successor_message (struct GNUNET_PeerIdentity source_peer, |
@@ -1242,7 +1245,7 @@ GDS_NEIGHBOURS_send_verify_successor_message (struct GNUNET_PeerIdentity source_ | |||
1242 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), | 1245 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), |
1243 | 1, GNUNET_NO); | 1246 | 1, GNUNET_NO); |
1244 | } | 1247 | } |
1245 | 1248 | ||
1246 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 1249 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); |
1247 | pending->importance = 0; /* FIXME */ | 1250 | pending->importance = 0; /* FIXME */ |
1248 | pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); | 1251 | pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); |
@@ -1253,7 +1256,7 @@ GDS_NEIGHBOURS_send_verify_successor_message (struct GNUNET_PeerIdentity source_ | |||
1253 | vsm->source_peer = source_peer; | 1256 | vsm->source_peer = source_peer; |
1254 | vsm->successor = successor; | 1257 | vsm->successor = successor; |
1255 | vsm->trail_id = trail_id; | 1258 | vsm->trail_id = trail_id; |
1256 | 1259 | ||
1257 | if (trail_length != 0) | 1260 | if (trail_length != 0) |
1258 | { | 1261 | { |
1259 | peer_list = (struct GNUNET_PeerIdentity *) &vsm[1]; | 1262 | peer_list = (struct GNUNET_PeerIdentity *) &vsm[1]; |
@@ -1271,8 +1274,8 @@ GDS_NEIGHBOURS_send_verify_successor_message (struct GNUNET_PeerIdentity source_ | |||
1271 | * FIXME: In every function we pass target friend except for this one. | 1274 | * FIXME: In every function we pass target friend except for this one. |
1272 | * so, either change everything or this one. also, should se just store | 1275 | * so, either change everything or this one. also, should se just store |
1273 | * the pointer to friend in routing table rather than gnunet_peeridentity. | 1276 | * the pointer to friend in routing table rather than gnunet_peeridentity. |
1274 | * if yes then we should keep friend info in.h andmake lot of changes. | 1277 | * if yes then we should keep friend info in.h andmake lot of changes. |
1275 | * Construct a trail teardown message and forward it to target friend. | 1278 | * Construct a trail teardown message and forward it to target friend. |
1276 | * @param trail_id Unique identifier of the trail. | 1279 | * @param trail_id Unique identifier of the trail. |
1277 | * @param trail_direction Direction of trail. | 1280 | * @param trail_direction Direction of trail. |
1278 | * @param target_friend Friend to get this message. | 1281 | * @param target_friend Friend to get this message. |
@@ -1294,12 +1297,12 @@ GDS_NEIGHBOURS_send_trail_teardown (struct GNUNET_HashCode trail_id, | |||
1294 | GNUNET_break (0); | 1297 | GNUNET_break (0); |
1295 | return; | 1298 | return; |
1296 | } | 1299 | } |
1297 | 1300 | ||
1298 | /*FIXME:In what case friend can be null. ?*/ | 1301 | /*FIXME:In what case friend can be null. ?*/ |
1299 | if (NULL == (target_friend = | 1302 | if (NULL == (target_friend = |
1300 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, &peer))); | 1303 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, &peer))); |
1301 | return; | 1304 | return; |
1302 | 1305 | ||
1303 | if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND) | 1306 | if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND) |
1304 | { | 1307 | { |
1305 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), | 1308 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), |
@@ -1325,18 +1328,18 @@ GDS_NEIGHBOURS_send_trail_teardown (struct GNUNET_HashCode trail_id, | |||
1325 | 1328 | ||
1326 | /** | 1329 | /** |
1327 | * Construct a verify successor result message and send it to target_friend | 1330 | * Construct a verify successor result message and send it to target_friend |
1328 | * @param querying_peer Peer which sent the verify successor message. | 1331 | * @param querying_peer Peer which sent the verify successor message. |
1329 | * @param source_successor Current_successor of @a querying_peer. | 1332 | * @param source_successor Current_successor of @a querying_peer. |
1330 | * @param current_predecessor Current predecessor of @a successor. Could be same | 1333 | * @param current_predecessor Current predecessor of @a successor. Could be same |
1331 | * or different from @a querying_peer. | 1334 | * or different from @a querying_peer. |
1332 | * @param trail_id Unique identifier of the trail from @a querying_peer to | 1335 | * @param trail_id Unique identifier of the trail from @a querying_peer to |
1333 | * @a successor, NOT including them. | 1336 | * @a successor, NOT including them. |
1334 | * @param trail List of peers which are part of trail from @a querying_peer to | 1337 | * @param trail List of peers which are part of trail from @a querying_peer to |
1335 | * @a successor, NOT including them. | 1338 | * @a successor, NOT including them. |
1336 | * @param trail_length Total number of peers in @a trail | 1339 | * @param trail_length Total number of peers in @a trail |
1337 | * @param trail_direction Direction in which we are sending the message. In this | 1340 | * @param trail_direction Direction in which we are sending the message. In this |
1338 | * case we are sending result from @a successor to @a querying_peer. | 1341 | * case we are sending result from @a successor to @a querying_peer. |
1339 | * @param target_friend Next friend to get this message. | 1342 | * @param target_friend Next friend to get this message. |
1340 | */ | 1343 | */ |
1341 | void | 1344 | void |
1342 | GDS_NEIGHBOURS_send_verify_successor_result (struct GNUNET_PeerIdentity querying_peer, | 1345 | GDS_NEIGHBOURS_send_verify_successor_result (struct GNUNET_PeerIdentity querying_peer, |
@@ -1380,7 +1383,7 @@ GDS_NEIGHBOURS_send_verify_successor_result (struct GNUNET_PeerIdentity querying | |||
1380 | vsmr->probable_successor = probable_successor; | 1383 | vsmr->probable_successor = probable_successor; |
1381 | vsmr->trail_direction = htonl (trail_direction); | 1384 | vsmr->trail_direction = htonl (trail_direction); |
1382 | vsmr->trail_id = trail_id; | 1385 | vsmr->trail_id = trail_id; |
1383 | 1386 | ||
1384 | if (trail_length > 0) | 1387 | if (trail_length > 0) |
1385 | { | 1388 | { |
1386 | peer_list = (struct GNUNET_PeerIdentity *) &vsmr[1]; | 1389 | peer_list = (struct GNUNET_PeerIdentity *) &vsmr[1]; |
@@ -1397,14 +1400,14 @@ GDS_NEIGHBOURS_send_verify_successor_result (struct GNUNET_PeerIdentity querying | |||
1397 | /** | 1400 | /** |
1398 | * Construct a notify new successor message and send it to target_friend | 1401 | * Construct a notify new successor message and send it to target_friend |
1399 | * @param source_peer Peer which wants to notify to its new successor that it | 1402 | * @param source_peer Peer which wants to notify to its new successor that it |
1400 | * could be its predecessor. | 1403 | * could be its predecessor. |
1401 | * @param successor New successor of @a source_peer | 1404 | * @param successor New successor of @a source_peer |
1402 | * @param successor_trail List of peers in Trail to reach from | 1405 | * @param successor_trail List of peers in Trail to reach from |
1403 | * @a source_peer to @a new_successor, NOT including | 1406 | * @a source_peer to @a new_successor, NOT including |
1404 | * the endpoints. | 1407 | * the endpoints. |
1405 | * @param successor_trail_length Total number of peers in @a new_successor_trail. | 1408 | * @param successor_trail_length Total number of peers in @a new_successor_trail. |
1406 | * @param successor_trail_id Unique identifier of @a new_successor_trail. | 1409 | * @param successor_trail_id Unique identifier of @a new_successor_trail. |
1407 | * @param target_friend Next friend to get this message. | 1410 | * @param target_friend Next friend to get this message. |
1408 | */ | 1411 | */ |
1409 | void | 1412 | void |
1410 | GDS_NEIGHBOURS_send_notify_new_successor (struct GNUNET_PeerIdentity source_peer, | 1413 | GDS_NEIGHBOURS_send_notify_new_successor (struct GNUNET_PeerIdentity source_peer, |
@@ -1444,7 +1447,7 @@ GDS_NEIGHBOURS_send_notify_new_successor (struct GNUNET_PeerIdentity source_peer | |||
1444 | nsm->new_successor = successor; | 1447 | nsm->new_successor = successor; |
1445 | nsm->source_peer = source_peer; | 1448 | nsm->source_peer = source_peer; |
1446 | nsm->trail_id = succesor_trail_id; | 1449 | nsm->trail_id = succesor_trail_id; |
1447 | 1450 | ||
1448 | if (successor_trail_length > 0) | 1451 | if (successor_trail_length > 0) |
1449 | { | 1452 | { |
1450 | peer_list = (struct GNUNET_PeerIdentity *) &nsm[1]; | 1453 | peer_list = (struct GNUNET_PeerIdentity *) &nsm[1]; |
@@ -1463,10 +1466,10 @@ GDS_NEIGHBOURS_send_notify_new_successor (struct GNUNET_PeerIdentity source_peer | |||
1463 | * Construct an add_trail message and send it to target_friend | 1466 | * Construct an add_trail message and send it to target_friend |
1464 | * @param source_peer Source of the trail. | 1467 | * @param source_peer Source of the trail. |
1465 | * @param destination_peer Destination of the trail. | 1468 | * @param destination_peer Destination of the trail. |
1466 | * @param trail_id Unique identifier of the trail from | 1469 | * @param trail_id Unique identifier of the trail from |
1467 | * @a source_peer to @a destination_peer, NOT including the endpoints. | 1470 | * @a source_peer to @a destination_peer, NOT including the endpoints. |
1468 | * @param trail List of peers in Trail from @a source_peer to @a destination_peer, | 1471 | * @param trail List of peers in Trail from @a source_peer to @a destination_peer, |
1469 | * NOT including the endpoints. | 1472 | * NOT including the endpoints. |
1470 | * @param trail_length Total number of peers in @a trail. | 1473 | * @param trail_length Total number of peers in @a trail. |
1471 | * @param target_friend Next friend to get this message. | 1474 | * @param target_friend Next friend to get this message. |
1472 | */ | 1475 | */ |
@@ -1508,7 +1511,7 @@ GDS_NEIGHBOURS_send_add_trail (struct GNUNET_PeerIdentity source_peer, | |||
1508 | adm->source_peer = source_peer; | 1511 | adm->source_peer = source_peer; |
1509 | adm->destination_peer = destination_peer; | 1512 | adm->destination_peer = destination_peer; |
1510 | adm->trail_id = trail_id; | 1513 | adm->trail_id = trail_id; |
1511 | 1514 | ||
1512 | if (trail_length > 0) | 1515 | if (trail_length > 0) |
1513 | { | 1516 | { |
1514 | peer_list = (struct GNUNET_PeerIdentity *)&adm[1]; | 1517 | peer_list = (struct GNUNET_PeerIdentity *)&adm[1]; |
@@ -1553,7 +1556,7 @@ GDS_NEIGHBOURS_send_trail_compression (struct GNUNET_PeerIdentity source_peer, | |||
1553 | gettext_noop ("# P2P messages dropped due to full queue"), | 1556 | gettext_noop ("# P2P messages dropped due to full queue"), |
1554 | 1, GNUNET_NO); | 1557 | 1, GNUNET_NO); |
1555 | } | 1558 | } |
1556 | 1559 | ||
1557 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 1560 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); |
1558 | pending->importance = 0; /* FIXME */ | 1561 | pending->importance = 0; /* FIXME */ |
1559 | pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); | 1562 | pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); |
@@ -1585,7 +1588,7 @@ search_my_index (const struct GNUNET_PeerIdentity *trail, | |||
1585 | { | 1588 | { |
1586 | int i; | 1589 | int i; |
1587 | int lowest_index = -1; | 1590 | int lowest_index = -1; |
1588 | 1591 | ||
1589 | for (i = 0; i < trail_length; i++) | 1592 | for (i = 0; i < trail_length; i++) |
1590 | { | 1593 | { |
1591 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &trail[i])) | 1594 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &trail[i])) |
@@ -1599,15 +1602,15 @@ search_my_index (const struct GNUNET_PeerIdentity *trail, | |||
1599 | 1602 | ||
1600 | /** | 1603 | /** |
1601 | * Check if the friend is congested or have reached maximum number of trails | 1604 | * Check if the friend is congested or have reached maximum number of trails |
1602 | * it can be part of of. | 1605 | * it can be part of of. |
1603 | * @param friend Friend to be checked. | 1606 | * @param friend Friend to be checked. |
1604 | * @return #GNUNET_NO if friend is not congested or have not crossed threshold. | 1607 | * @return #GNUNET_NO if friend is not congested or have not crossed threshold. |
1605 | * #GNUNET_YES if friend is either congested or have crossed threshold | 1608 | * #GNUNET_YES if friend is either congested or have crossed threshold |
1606 | */ | 1609 | */ |
1607 | static int | 1610 | static int |
1608 | is_friend_congested (struct FriendInfo *friend) | 1611 | is_friend_congested (struct FriendInfo *friend) |
1609 | { | 1612 | { |
1610 | if ((TRAILS_THROUGH_FRIEND_THRESHOLD > friend->trails_count) && | 1613 | if ((TRAILS_THROUGH_FRIEND_THRESHOLD > friend->trails_count) && |
1611 | ((0 == GNUNET_TIME_absolute_get_remaining | 1614 | ((0 == GNUNET_TIME_absolute_get_remaining |
1612 | (friend->congestion_timestamp).rel_value_us))) | 1615 | (friend->congestion_timestamp).rel_value_us))) |
1613 | return GNUNET_NO; | 1616 | return GNUNET_NO; |
@@ -1617,36 +1620,35 @@ is_friend_congested (struct FriendInfo *friend) | |||
1617 | 1620 | ||
1618 | 1621 | ||
1619 | /** | 1622 | /** |
1620 | * FIXME; not handling the wrap around logic correctly. | ||
1621 | * Select closest finger to value. | 1623 | * Select closest finger to value. |
1622 | * @param peer1 First peer | 1624 | * @param peer1 First peer |
1623 | * @param peer2 Second peer | 1625 | * @param peer2 Second peer |
1624 | * @param value Value to be compare | 1626 | * @param value Value to be compare |
1625 | * @return Closest peer | 1627 | * @return Closest peer |
1626 | */ | 1628 | */ |
1627 | static struct GNUNET_PeerIdentity * | 1629 | const static struct GNUNET_PeerIdentity * |
1628 | select_closest_finger (struct GNUNET_PeerIdentity *peer1, | 1630 | select_closest_finger (const struct GNUNET_PeerIdentity *peer1, |
1629 | struct GNUNET_PeerIdentity *peer2, | 1631 | const struct GNUNET_PeerIdentity *peer2, |
1630 | uint64_t value) | 1632 | uint64_t value) |
1631 | { | 1633 | { |
1632 | uint64_t peer1_value; | 1634 | uint64_t peer1_value; |
1633 | uint64_t peer2_value; | 1635 | uint64_t peer2_value; |
1634 | 1636 | ||
1635 | memcpy (&peer1_value, peer1, sizeof (uint64_t)); | 1637 | memcpy (&peer1_value, peer1, sizeof (uint64_t)); |
1636 | memcpy (&peer2_value, peer2, sizeof (uint64_t)); | 1638 | memcpy (&peer2_value, peer2, sizeof (uint64_t)); |
1637 | peer1_value = GNUNET_ntohll (peer1_value); | 1639 | peer1_value = GNUNET_ntohll (peer1_value); |
1638 | peer2_value = GNUNET_ntohll (peer2_value); | 1640 | peer2_value = GNUNET_ntohll (peer2_value); |
1639 | 1641 | ||
1640 | if (peer1_value == value) | 1642 | if (peer1_value == value) |
1641 | { | 1643 | { |
1642 | return peer1; | 1644 | return peer1; |
1643 | } | 1645 | } |
1644 | 1646 | ||
1645 | if (peer2_value == value) | 1647 | if (peer2_value == value) |
1646 | { | 1648 | { |
1647 | return peer2; | 1649 | return peer2; |
1648 | } | 1650 | } |
1649 | 1651 | ||
1650 | if (peer2_value < peer1_value) | 1652 | if (peer2_value < peer1_value) |
1651 | { | 1653 | { |
1652 | if ((peer2_value < value) && (value < peer1_value)) | 1654 | if ((peer2_value < value) && (value < peer1_value)) |
@@ -1658,8 +1660,8 @@ select_closest_finger (struct GNUNET_PeerIdentity *peer1, | |||
1658 | { | 1660 | { |
1659 | return peer2; | 1661 | return peer2; |
1660 | } | 1662 | } |
1661 | } | 1663 | } |
1662 | 1664 | ||
1663 | if (peer1_value < peer2_value) | 1665 | if (peer1_value < peer2_value) |
1664 | { | 1666 | { |
1665 | if ((peer1_value < value) && (value < peer2_value)) | 1667 | if ((peer1_value < value) && (value < peer2_value)) |
@@ -1683,25 +1685,25 @@ select_closest_finger (struct GNUNET_PeerIdentity *peer1, | |||
1683 | * @param value Value to be compare | 1685 | * @param value Value to be compare |
1684 | * @return Peer which precedes value in the network. | 1686 | * @return Peer which precedes value in the network. |
1685 | */ | 1687 | */ |
1686 | static struct GNUNET_PeerIdentity * | 1688 | const static struct GNUNET_PeerIdentity * |
1687 | select_closest_predecessor (struct GNUNET_PeerIdentity *peer1, | 1689 | select_closest_predecessor (const struct GNUNET_PeerIdentity *peer1, |
1688 | struct GNUNET_PeerIdentity *peer2, | 1690 | const struct GNUNET_PeerIdentity *peer2, |
1689 | uint64_t value) | 1691 | uint64_t value) |
1690 | { | 1692 | { |
1691 | uint64_t peer1_value; | 1693 | uint64_t peer1_value; |
1692 | uint64_t peer2_value; | 1694 | uint64_t peer2_value; |
1693 | 1695 | ||
1694 | memcpy (&peer1_value, peer1, sizeof (uint64_t)); | 1696 | memcpy (&peer1_value, peer1, sizeof (uint64_t)); |
1695 | memcpy (&peer2_value, peer2, sizeof (uint64_t)); | 1697 | memcpy (&peer2_value, peer2, sizeof (uint64_t)); |
1696 | peer1_value = GNUNET_ntohll (peer1_value); | 1698 | peer1_value = GNUNET_ntohll (peer1_value); |
1697 | peer2_value = GNUNET_ntohll (peer2_value); | 1699 | peer2_value = GNUNET_ntohll (peer2_value); |
1698 | 1700 | ||
1699 | if (peer1_value == value) | 1701 | if (peer1_value == value) |
1700 | return peer1; | 1702 | return peer1; |
1701 | 1703 | ||
1702 | if (peer2_value == value) | 1704 | if (peer2_value == value) |
1703 | return peer2; | 1705 | return peer2; |
1704 | 1706 | ||
1705 | if (peer1_value < peer2_value) | 1707 | if (peer1_value < peer2_value) |
1706 | { | 1708 | { |
1707 | if ((peer1_value < value) && (value < peer2_value)) | 1709 | if ((peer1_value < value) && (value < peer2_value)) |
@@ -1714,7 +1716,7 @@ select_closest_predecessor (struct GNUNET_PeerIdentity *peer1, | |||
1714 | return peer2; | 1716 | return peer2; |
1715 | } | 1717 | } |
1716 | } | 1718 | } |
1717 | 1719 | ||
1718 | if (peer2_value < peer1_value) | 1720 | if (peer2_value < peer1_value) |
1719 | { | 1721 | { |
1720 | if ((peer2_value < value) && (value < peer1_value)) | 1722 | if ((peer2_value < value) && (value < peer1_value)) |
@@ -1742,11 +1744,11 @@ test_friend_peermap_print () | |||
1742 | struct GNUNET_PeerIdentity print_peer; | 1744 | struct GNUNET_PeerIdentity print_peer; |
1743 | struct GNUNET_PeerIdentity key_ret; | 1745 | struct GNUNET_PeerIdentity key_ret; |
1744 | int i; | 1746 | int i; |
1745 | 1747 | ||
1746 | print_peer = my_identity; | 1748 | print_peer = my_identity; |
1747 | FPRINTF (stderr,_("\nSUPU************ FRIEND_PEERMAP of %s"),GNUNET_i2s(&print_peer)); | 1749 | FPRINTF (stderr,_("\nSUPU************ FRIEND_PEERMAP of %s"),GNUNET_i2s(&print_peer)); |
1748 | friend_iter = GNUNET_CONTAINER_multipeermap_iterator_create (friend_peermap); | 1750 | friend_iter = GNUNET_CONTAINER_multipeermap_iterator_create (friend_peermap); |
1749 | 1751 | ||
1750 | for (i = 0; i < GNUNET_CONTAINER_multipeermap_size (friend_peermap); i++) | 1752 | for (i = 0; i < GNUNET_CONTAINER_multipeermap_size (friend_peermap); i++) |
1751 | { | 1753 | { |
1752 | if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next (friend_iter, | 1754 | if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next (friend_iter, |
@@ -1777,14 +1779,14 @@ test_finger_table_print() | |||
1777 | for (i = 0; i < MAX_FINGERS; i++) | 1779 | for (i = 0; i < MAX_FINGERS; i++) |
1778 | { | 1780 | { |
1779 | finger = &finger_table[i]; | 1781 | finger = &finger_table[i]; |
1780 | 1782 | ||
1781 | if (GNUNET_NO == finger->is_present) | 1783 | if (GNUNET_NO == finger->is_present) |
1782 | continue; | 1784 | continue; |
1783 | 1785 | ||
1784 | print_peer = finger->finger_identity; | 1786 | print_peer = finger->finger_identity; |
1785 | FPRINTF (stderr,_("\nSUPU %s, %s, %d, finger_table[%d] = %s, trails_count = %d"), | 1787 | FPRINTF (stderr,_("\nSUPU %s, %s, %d, finger_table[%d] = %s, trails_count = %d"), |
1786 | __FILE__, __func__,__LINE__,i,GNUNET_i2s (&print_peer), finger->trails_count); | 1788 | __FILE__, __func__,__LINE__,i,GNUNET_i2s (&print_peer), finger->trails_count); |
1787 | 1789 | ||
1788 | #if 0 | 1790 | #if 0 |
1789 | for (j = 0; j < finger->trails_count; j++) | 1791 | for (j = 0; j < finger->trails_count; j++) |
1790 | { | 1792 | { |
@@ -1793,7 +1795,7 @@ test_finger_table_print() | |||
1793 | struct Trail_Element *element; | 1795 | struct Trail_Element *element; |
1794 | element = trail->trail_head; | 1796 | element = trail->trail_head; |
1795 | for (k = 0; k < trail->trail_length; k++) | 1797 | for (k = 0; k < trail->trail_length; k++) |
1796 | { | 1798 | { |
1797 | print_peer = element->peer; | 1799 | print_peer = element->peer; |
1798 | FPRINTF (stderr,_("\nSUPU %s, %s, %d,trail[%d] = %s "),__FILE__, __func__,__LINE__,k, GNUNET_i2s(&print_peer)); | 1800 | FPRINTF (stderr,_("\nSUPU %s, %s, %d,trail[%d] = %s "),__FILE__, __func__,__LINE__,k, GNUNET_i2s(&print_peer)); |
1799 | element = element->next; | 1801 | element = element->next; |
@@ -1811,27 +1813,19 @@ test_finger_table_print() | |||
1811 | * @param peer1 First peer | 1813 | * @param peer1 First peer |
1812 | * @param peer2 Second peer | 1814 | * @param peer2 Second peer |
1813 | * @param value Value relative to which we find the closest | 1815 | * @param value Value relative to which we find the closest |
1814 | * @param is_predecessor Is value a predecessor or any other finger. | 1816 | * @param is_predecessor Is value a predecessor or any other finger. |
1815 | * @return Closest peer among two peers. | 1817 | * @return Closest peer among two peers. |
1816 | */ | 1818 | */ |
1817 | static struct GNUNET_PeerIdentity * | 1819 | const static struct GNUNET_PeerIdentity * |
1818 | select_closest_peer (struct GNUNET_PeerIdentity *peer1, | 1820 | select_closest_peer (const struct GNUNET_PeerIdentity *peer1, |
1819 | struct GNUNET_PeerIdentity *peer2, | 1821 | const struct GNUNET_PeerIdentity *peer2, |
1820 | uint64_t value, | 1822 | uint64_t value, |
1821 | unsigned int is_predecessor) | 1823 | unsigned int is_predecessor) |
1822 | { | 1824 | { |
1823 | struct GNUNET_PeerIdentity *closest_peer; | ||
1824 | |||
1825 | if (1 == is_predecessor) | 1825 | if (1 == is_predecessor) |
1826 | { | 1826 | return select_closest_predecessor (peer1, peer2, value); |
1827 | closest_peer = select_closest_predecessor (peer1, peer2, value); | 1827 | |
1828 | 1828 | return select_closest_finger (peer1, peer2, value); | |
1829 | } | ||
1830 | else | ||
1831 | { | ||
1832 | closest_peer = select_closest_finger (peer1, peer2, value); | ||
1833 | } | ||
1834 | return closest_peer; | ||
1835 | } | 1829 | } |
1836 | 1830 | ||
1837 | 1831 | ||
@@ -1841,7 +1835,7 @@ select_closest_peer (struct GNUNET_PeerIdentity *peer1, | |||
1841 | * then don't select it. In case there multiple available good trails to reach | 1835 | * then don't select it. In case there multiple available good trails to reach |
1842 | * to Finger, choose the one with shortest trail length. | 1836 | * to Finger, choose the one with shortest trail length. |
1843 | * Note: We use length as parameter. But we can use any other suitable parameter | 1837 | * Note: We use length as parameter. But we can use any other suitable parameter |
1844 | * also. | 1838 | * also. |
1845 | * @param finger Finger | 1839 | * @param finger Finger |
1846 | * @return struct Selected_Finger_Trail which contains the first friend , trail id | 1840 | * @return struct Selected_Finger_Trail which contains the first friend , trail id |
1847 | * and trail length. NULL in case none of the trails are free. | 1841 | * and trail length. NULL in case none of the trails are free. |
@@ -1855,36 +1849,36 @@ select_finger_trail (struct FingerInfo *finger) | |||
1855 | unsigned int i; | 1849 | unsigned int i; |
1856 | unsigned int flag = 0; | 1850 | unsigned int flag = 0; |
1857 | unsigned int j = 0; | 1851 | unsigned int j = 0; |
1858 | 1852 | ||
1859 | finger_trail = GNUNET_new (struct Selected_Finger_Trail); | 1853 | finger_trail = GNUNET_new (struct Selected_Finger_Trail); |
1860 | GNUNET_assert (finger->trails_count > 0); | 1854 | GNUNET_assert (finger->trails_count > 0); |
1861 | 1855 | ||
1862 | for (i = 0; i < finger->trails_count; i++) | 1856 | for (i = 0; i < finger->trails_count; i++) |
1863 | { | 1857 | { |
1864 | iterator = &finger->trail_list[i]; | 1858 | iterator = &finger->trail_list[i]; |
1865 | 1859 | ||
1866 | /* No trail stored at this index. */ | 1860 | /* No trail stored at this index. */ |
1867 | if (GNUNET_NO == iterator->is_present) | 1861 | if (GNUNET_NO == iterator->is_present) |
1868 | continue; | 1862 | continue; |
1869 | 1863 | ||
1870 | GNUNET_assert (NULL != | 1864 | GNUNET_assert (NULL != |
1871 | (friend = | 1865 | (friend = |
1872 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 1866 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
1873 | &iterator->trail_head->peer))); | 1867 | &iterator->trail_head->peer))); |
1874 | 1868 | ||
1875 | /* First friend to reach trail is not free. */ | 1869 | /* First friend to reach trail is not free. */ |
1876 | if (GNUNET_YES == is_friend_congested (friend)) | 1870 | if (GNUNET_YES == is_friend_congested (friend)) |
1877 | { | 1871 | { |
1878 | j++; | 1872 | j++; |
1879 | continue; | 1873 | continue; |
1880 | } | 1874 | } |
1881 | 1875 | ||
1882 | if (!flag) | 1876 | if (!flag) |
1883 | { | 1877 | { |
1884 | flag = 1; | 1878 | flag = 1; |
1885 | finger_trail->trail_length = iterator->trail_length; | 1879 | finger_trail->trail_length = iterator->trail_length; |
1886 | finger_trail->friend = *friend; | 1880 | finger_trail->friend = *friend; |
1887 | finger_trail->trail_id = iterator->trail_id; | 1881 | finger_trail->trail_id = iterator->trail_id; |
1888 | } | 1882 | } |
1889 | else if (finger_trail->trail_length > iterator->trail_length) | 1883 | else if (finger_trail->trail_length > iterator->trail_length) |
1890 | { | 1884 | { |
@@ -1894,50 +1888,52 @@ select_finger_trail (struct FingerInfo *finger) | |||
1894 | } | 1888 | } |
1895 | } | 1889 | } |
1896 | 1890 | ||
1897 | /* All the first friend in all the trails to reach to finger are either | 1891 | /* All the first friend in all the trails to reach to finger are either |
1898 | congested or have crossed trail threshold. */ | 1892 | congested or have crossed trail threshold. */ |
1899 | if (j == finger->trails_count) | 1893 | if (j == finger->trails_count) |
1900 | return NULL; | 1894 | return NULL; |
1901 | 1895 | ||
1902 | return finger_trail; | 1896 | return finger_trail; |
1903 | } | 1897 | } |
1904 | 1898 | ||
1905 | 1899 | ||
1906 | /** | 1900 | /** |
1907 | * Compare FINGER entry with current successor. If finger's first friend of all | 1901 | * Compare FINGER entry with current successor. If finger's first friend of all |
1908 | * its trail is not congested and has not crossed trail threshold, then check | 1902 | * its trail is not congested and has not crossed trail threshold, then check |
1909 | * if finger peer identity is closer to final_destination_finger_value than | 1903 | * if finger peer identity is closer to final_destination_finger_value than |
1910 | * current_successor. If yes then update current_successor. | 1904 | * current_successor. If yes then update current_successor. |
1911 | * @param current_successor[in/out] | 1905 | * @param current_successor[in/out] |
1912 | * @return | 1906 | * @return |
1913 | */ | 1907 | */ |
1914 | static void | 1908 | static void |
1915 | compare_finger_and_current_successor (struct Closest_Peer *current_closest_peer) | 1909 | compare_finger_and_current_successor (struct Closest_Peer *current_closest_peer) |
1916 | { | 1910 | { |
1917 | struct FingerInfo *finger; | 1911 | struct FingerInfo *finger; |
1918 | struct GNUNET_PeerIdentity *closest_peer; | 1912 | const struct GNUNET_PeerIdentity *closest_peer; |
1919 | struct Selected_Finger_Trail *finger_trail; | 1913 | struct Selected_Finger_Trail *finger_trail; |
1920 | int i; | 1914 | int i; |
1921 | 1915 | ||
1922 | /* Iterate over finger table. */ | 1916 | /* Iterate over finger table. */ |
1923 | for (i = 0; i < MAX_FINGERS; i++) | 1917 | for (i = 0; i < MAX_FINGERS; i++) |
1924 | { | 1918 | { |
1925 | finger = &finger_table[i]; | 1919 | finger = &finger_table[i]; |
1926 | 1920 | ||
1927 | if (GNUNET_NO == finger->is_present) | 1921 | if (GNUNET_NO == finger->is_present) |
1928 | continue; | 1922 | continue; |
1929 | 1923 | ||
1930 | /* If my identity is same as current closest peer then don't consider me*/ | 1924 | /* FIXME write correct comment here */ |
1931 | if (0 == | 1925 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, |
1932 | GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, | 1926 | ¤t_closest_peer->best_known_destination)) |
1933 | ¤t_closest_peer->best_known_destination)) | ||
1934 | continue; | 1927 | continue; |
1935 | 1928 | ||
1936 | /* If I am my own finger, then ignore this finger. */ | 1929 | /* If I am my own finger, then ignore this finger. */ |
1937 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, | 1930 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, |
1938 | &my_identity)) | 1931 | &my_identity)) |
1932 | { | ||
1933 | GNUNET_break (0); | ||
1939 | continue; | 1934 | continue; |
1940 | 1935 | } | |
1936 | |||
1941 | /* If finger is a friend, then do nothing. As we have already checked | 1937 | /* If finger is a friend, then do nothing. As we have already checked |
1942 | * for each friend in compare_friend_and_current_successor(). */ | 1938 | * for each friend in compare_friend_and_current_successor(). */ |
1943 | if (NULL != (GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 1939 | if (NULL != (GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
@@ -1945,22 +1941,21 @@ compare_finger_and_current_successor (struct Closest_Peer *current_closest_peer) | |||
1945 | { | 1941 | { |
1946 | continue; | 1942 | continue; |
1947 | } | 1943 | } |
1948 | |||
1949 | /* Choose one of the trail to reach to finger. */ | ||
1950 | finger_trail = select_finger_trail (finger); | ||
1951 | |||
1952 | /* In case no trail found, ignore this finger. */ | ||
1953 | if (NULL == finger_trail) | ||
1954 | continue; | ||
1955 | 1944 | ||
1956 | closest_peer = select_closest_peer (&finger->finger_identity, | 1945 | closest_peer = select_closest_peer (&finger->finger_identity, |
1957 | ¤t_closest_peer->best_known_destination, | 1946 | ¤t_closest_peer->best_known_destination, |
1958 | current_closest_peer->destination_finger_value, | 1947 | current_closest_peer->destination_finger_value, |
1959 | current_closest_peer->is_predecessor); | 1948 | current_closest_peer->is_predecessor); |
1960 | 1949 | ||
1961 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, | 1950 | if (&finger->finger_identity == closest_peer) |
1962 | closest_peer)) | ||
1963 | { | 1951 | { |
1952 | /* Choose one of the trail to reach to finger. */ | ||
1953 | finger_trail = select_finger_trail (finger); | ||
1954 | |||
1955 | /* In case no trail found, ignore this finger. */ | ||
1956 | if (NULL == finger_trail) | ||
1957 | continue; | ||
1958 | |||
1964 | current_closest_peer->best_known_destination = finger->finger_identity; | 1959 | current_closest_peer->best_known_destination = finger->finger_identity; |
1965 | current_closest_peer->next_hop = finger_trail->friend.id; | 1960 | current_closest_peer->next_hop = finger_trail->friend.id; |
1966 | current_closest_peer->trail_id = finger_trail->trail_id; | 1961 | current_closest_peer->trail_id = finger_trail->trail_id; |
@@ -1973,10 +1968,10 @@ compare_finger_and_current_successor (struct Closest_Peer *current_closest_peer) | |||
1973 | 1968 | ||
1974 | /** | 1969 | /** |
1975 | * Compare friend entry with current successor. | 1970 | * Compare friend entry with current successor. |
1976 | * If friend identity and current_successor is same, then do nothing. | 1971 | * If friend identity and current_successor is same, then do nothing. |
1977 | * If friend is not congested and has not crossed trail threshold, then check | 1972 | * If friend is not congested and has not crossed trail threshold, then check |
1978 | * if friend peer identity is closer to final_destination_finger_value than | 1973 | * if friend peer identity is closer to final_destination_finger_value than |
1979 | * current_successor. If yes then update current_successor. | 1974 | * current_successor. If yes then update current_successor. |
1980 | * @param cls closure | 1975 | * @param cls closure |
1981 | * @param key current public key | 1976 | * @param key current public key |
1982 | * @param value struct Closest_Peer | 1977 | * @param value struct Closest_Peer |
@@ -1990,30 +1985,32 @@ compare_friend_and_current_closest_peer (void *cls, | |||
1990 | { | 1985 | { |
1991 | struct FriendInfo *friend = value; | 1986 | struct FriendInfo *friend = value; |
1992 | struct Closest_Peer *current_closest_peer = cls; | 1987 | struct Closest_Peer *current_closest_peer = cls; |
1993 | struct GNUNET_PeerIdentity *closest_peer; | 1988 | const struct GNUNET_PeerIdentity *closest_peer; |
1994 | 1989 | ||
1995 | /* Friend is either congested or has crossed threshold. */ | 1990 | /* Friend is either congested or has crossed threshold. */ |
1996 | if (GNUNET_YES == is_friend_congested (friend)) | 1991 | if (GNUNET_YES == is_friend_congested (friend)) |
1997 | return GNUNET_YES; | 1992 | return GNUNET_YES; |
1998 | 1993 | ||
1999 | /* If current_closest_peer and friend identity are same, then do nothing.*/ | 1994 | /* If current_closest_peer and friend identity are same, then do nothing.*/ |
2000 | if (0 == | 1995 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&friend->id, |
2001 | GNUNET_CRYPTO_cmp_peer_identity (&friend->id, | 1996 | ¤t_closest_peer->best_known_destination)) |
2002 | ¤t_closest_peer->best_known_destination)) | 1997 | { |
1998 | GNUNET_break (0); | ||
2003 | return GNUNET_YES; | 1999 | return GNUNET_YES; |
2000 | } | ||
2004 | 2001 | ||
2005 | closest_peer = select_closest_peer (&friend->id, | 2002 | closest_peer = select_closest_peer (&friend->id, |
2006 | ¤t_closest_peer->best_known_destination, | 2003 | ¤t_closest_peer->best_known_destination, |
2007 | current_closest_peer->destination_finger_value, | 2004 | current_closest_peer->destination_finger_value, |
2008 | current_closest_peer->is_predecessor); | 2005 | current_closest_peer->is_predecessor); |
2009 | 2006 | ||
2010 | /* Is friend the closest successor? */ | 2007 | /* Is friend the closest successor? */ |
2011 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&friend->id, closest_peer)) | 2008 | if (&friend->id == closest_peer) |
2012 | { | 2009 | { |
2013 | current_closest_peer->best_known_destination = friend->id; | 2010 | current_closest_peer->best_known_destination = friend->id; |
2014 | current_closest_peer->next_hop = friend->id; | 2011 | current_closest_peer->next_hop = friend->id; |
2015 | } | 2012 | } |
2016 | 2013 | ||
2017 | return GNUNET_YES; | 2014 | return GNUNET_YES; |
2018 | } | 2015 | } |
2019 | 2016 | ||
@@ -2023,19 +2020,19 @@ compare_friend_and_current_closest_peer (void *cls, | |||
2023 | * @param my_identity My peer identity | 2020 | * @param my_identity My peer identity |
2024 | * @return Updated closest_peer | 2021 | * @return Updated closest_peer |
2025 | */ | 2022 | */ |
2026 | static struct Closest_Peer | 2023 | static struct Closest_Peer |
2027 | init_current_successor (struct GNUNET_PeerIdentity my_identity, | 2024 | init_current_successor (struct GNUNET_PeerIdentity my_identity, |
2028 | uint64_t destination_finger_value, | 2025 | uint64_t destination_finger_value, |
2029 | unsigned int is_predecessor) | 2026 | unsigned int is_predecessor) |
2030 | { | 2027 | { |
2031 | struct Closest_Peer current_closest_peer; | 2028 | struct Closest_Peer current_closest_peer; |
2032 | 2029 | ||
2033 | memset (¤t_closest_peer.trail_id, 0, sizeof(struct GNUNET_HashCode)); | 2030 | memset (¤t_closest_peer.trail_id, 0, sizeof(struct GNUNET_HashCode)); |
2034 | current_closest_peer.destination_finger_value = destination_finger_value; | 2031 | current_closest_peer.destination_finger_value = destination_finger_value; |
2035 | current_closest_peer.is_predecessor = is_predecessor; | 2032 | current_closest_peer.is_predecessor = is_predecessor; |
2036 | current_closest_peer.next_hop = my_identity; | 2033 | current_closest_peer.next_hop = my_identity; |
2037 | current_closest_peer.best_known_destination = my_identity; | 2034 | current_closest_peer.best_known_destination = my_identity; |
2038 | 2035 | ||
2039 | return current_closest_peer; | 2036 | return current_closest_peer; |
2040 | } | 2037 | } |
2041 | 2038 | ||
@@ -2043,13 +2040,13 @@ init_current_successor (struct GNUNET_PeerIdentity my_identity, | |||
2043 | /** | 2040 | /** |
2044 | * FIXME: at the moment, there is not 100% get and put in case of non-malicious | 2041 | * FIXME: at the moment, there is not 100% get and put in case of non-malicious |
2045 | * peer. It could be because of the logic we wrote here. Verify if its correct. | 2042 | * peer. It could be because of the logic we wrote here. Verify if its correct. |
2046 | * If not then return immediate_successor. | 2043 | * If not then return immediate_successor. |
2047 | * | 2044 | * |
2048 | * Find the successor for destination_finger_value among my_identity, my | 2045 | * Find the successor for destination_finger_value among my_identity, my |
2049 | * friends and my fingers. Don't consider friends or fingers which are either | 2046 | * friends and my fingers. Don't consider friends or fingers which are either |
2050 | * congested or have crossed the threshold. | 2047 | * congested or have crossed the threshold. |
2051 | * NOTE: In case a friend is also a finger, then it is always chosen as friend | 2048 | * NOTE: In case a friend is also a finger, then it is always chosen as friend |
2052 | * not a finger. | 2049 | * not a finger. |
2053 | * @param destination_finger_value Peer closest to this value will be the next successor. | 2050 | * @param destination_finger_value Peer closest to this value will be the next successor. |
2054 | * @param is_predecessor Are we looking for predecessor or finger? | 2051 | * @param is_predecessor Are we looking for predecessor or finger? |
2055 | * @return Successor It is never NULL, in case none of friend or finger is closest, | 2052 | * @return Successor It is never NULL, in case none of friend or finger is closest, |
@@ -2060,24 +2057,24 @@ find_successor (uint64_t destination_finger_value, | |||
2060 | unsigned int is_predecessor) | 2057 | unsigned int is_predecessor) |
2061 | { | 2058 | { |
2062 | struct Closest_Peer current_closest_peer; | 2059 | struct Closest_Peer current_closest_peer; |
2063 | 2060 | ||
2064 | /* Initialize current_successor to my_identity. */ | 2061 | /* Initialize current_successor to my_identity. */ |
2065 | current_closest_peer = init_current_successor (my_identity, | 2062 | current_closest_peer = init_current_successor (my_identity, |
2066 | destination_finger_value, | 2063 | destination_finger_value, |
2067 | is_predecessor); | 2064 | is_predecessor); |
2068 | 2065 | ||
2069 | /* Compare each friend entry with current_successor and update current_successor | 2066 | /* Compare each friend entry with current_successor and update current_successor |
2070 | * with friend if its closest. */ | 2067 | * with friend if its closest. */ |
2071 | GNUNET_assert | 2068 | GNUNET_assert |
2072 | (GNUNET_SYSERR != | 2069 | (GNUNET_SYSERR != |
2073 | GNUNET_CONTAINER_multipeermap_iterate (friend_peermap, | 2070 | GNUNET_CONTAINER_multipeermap_iterate (friend_peermap, |
2074 | &compare_friend_and_current_closest_peer, | 2071 | &compare_friend_and_current_closest_peer, |
2075 | ¤t_closest_peer)); | 2072 | ¤t_closest_peer)); |
2076 | 2073 | ||
2077 | /* Compare each finger entry with current_successor and update current_successor | 2074 | /* Compare each finger entry with current_successor and update current_successor |
2078 | * with finger if its closest. */ | 2075 | * with finger if its closest. */ |
2079 | compare_finger_and_current_successor (¤t_closest_peer); | 2076 | compare_finger_and_current_successor (¤t_closest_peer); |
2080 | 2077 | ||
2081 | return current_closest_peer; | 2078 | return current_closest_peer; |
2082 | } | 2079 | } |
2083 | 2080 | ||
@@ -2089,8 +2086,8 @@ find_successor (uint64_t destination_finger_value, | |||
2089 | * @param options Routing options | 2086 | * @param options Routing options |
2090 | * @param desired_replication_level Desired replication count | 2087 | * @param desired_replication_level Desired replication count |
2091 | * @param best_known_dest Peer to which this message should reach eventually, | 2088 | * @param best_known_dest Peer to which this message should reach eventually, |
2092 | * as it is best known destination to me. | 2089 | * as it is best known destination to me. |
2093 | * @param intermediate_trail_id Trail id in case | 2090 | * @param intermediate_trail_id Trail id in case |
2094 | * @param target_peer Peer to which this message will be forwarded. | 2091 | * @param target_peer Peer to which this message will be forwarded. |
2095 | * @param hop_count Number of hops traversed so far. | 2092 | * @param hop_count Number of hops traversed so far. |
2096 | * @param put_path_length Total number of peers in @a put_path | 2093 | * @param put_path_length Total number of peers in @a put_path |
@@ -2120,10 +2117,10 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key, | |||
2120 | struct GNUNET_PeerIdentity next_hop; | 2117 | struct GNUNET_PeerIdentity next_hop; |
2121 | 2118 | ||
2122 | size_t msize; | 2119 | size_t msize; |
2123 | 2120 | ||
2124 | msize = put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size + | 2121 | msize = put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size + |
2125 | sizeof (struct PeerPutMessage); | 2122 | sizeof (struct PeerPutMessage); |
2126 | 2123 | ||
2127 | if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 2124 | if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
2128 | { | 2125 | { |
2129 | put_path_length = 0; | 2126 | put_path_length = 0; |
@@ -2135,7 +2132,7 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key, | |||
2135 | GNUNET_break (0); | 2132 | GNUNET_break (0); |
2136 | return; | 2133 | return; |
2137 | } | 2134 | } |
2138 | 2135 | ||
2139 | /* This is the first call made from clients file. So, we should search for the | 2136 | /* This is the first call made from clients file. So, we should search for the |
2140 | target_friend. */ | 2137 | target_friend. */ |
2141 | if (NULL == target_peer) | 2138 | if (NULL == target_peer) |
@@ -2143,33 +2140,33 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key, | |||
2143 | uint64_t key_value; | 2140 | uint64_t key_value; |
2144 | struct Closest_Peer successor; | 2141 | struct Closest_Peer successor; |
2145 | 2142 | ||
2146 | memcpy (&key_value, key, sizeof (uint64_t)); | 2143 | memcpy (&key_value, key, sizeof (uint64_t)); |
2147 | key_value = GNUNET_ntohll (key_value); | 2144 | key_value = GNUNET_ntohll (key_value); |
2148 | 2145 | ||
2149 | successor = find_successor (key_value, GDS_FINGER_TYPE_NON_PREDECESSOR); | 2146 | successor = find_successor (key_value, GDS_FINGER_TYPE_NON_PREDECESSOR); |
2150 | best_known_dest = successor.best_known_destination; | 2147 | best_known_dest = successor.best_known_destination; |
2151 | next_hop = successor.next_hop; | 2148 | next_hop = successor.next_hop; |
2152 | intermediate_trail_id = successor.trail_id; | 2149 | intermediate_trail_id = successor.trail_id; |
2153 | 2150 | ||
2154 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&best_known_dest, &my_identity)) | 2151 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&best_known_dest, &my_identity)) |
2155 | { | 2152 | { |
2156 | /* I am the destination. */ | 2153 | /* I am the destination. */ |
2157 | GDS_DATACACHE_handle_put (expiration_time, key, 0, NULL, | 2154 | GDS_DATACACHE_handle_put (expiration_time, key, 0, NULL, |
2158 | ntohl (block_type),data_size,data); | 2155 | ntohl (block_type),data_size,data); |
2159 | return; | 2156 | return; |
2160 | } | 2157 | } |
2161 | else | 2158 | else |
2162 | GNUNET_assert (NULL != | 2159 | GNUNET_assert (NULL != |
2163 | (target_friend = | 2160 | (target_friend = |
2164 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop))); | 2161 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop))); |
2165 | } | 2162 | } |
2166 | else | 2163 | else |
2167 | { | 2164 | { |
2168 | GNUNET_assert (NULL != | 2165 | GNUNET_assert (NULL != |
2169 | (target_friend = | 2166 | (target_friend = |
2170 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer))); | 2167 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer))); |
2171 | } | 2168 | } |
2172 | 2169 | ||
2173 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 2170 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); |
2174 | pending->timeout = expiration_time; | 2171 | pending->timeout = expiration_time; |
2175 | ppm = (struct PeerPutMessage *) &pending[1]; | 2172 | ppm = (struct PeerPutMessage *) &pending[1]; |
@@ -2184,7 +2181,7 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key, | |||
2184 | ppm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time); | 2181 | ppm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time); |
2185 | ppm->best_known_destination = best_known_dest; | 2182 | ppm->best_known_destination = best_known_dest; |
2186 | ppm->key = *key; | 2183 | ppm->key = *key; |
2187 | 2184 | ||
2188 | pp = (struct GNUNET_PeerIdentity *) &ppm[1]; | 2185 | pp = (struct GNUNET_PeerIdentity *) &ppm[1]; |
2189 | if (put_path_length != 0) | 2186 | if (put_path_length != 0) |
2190 | { | 2187 | { |
@@ -2192,7 +2189,7 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key, | |||
2192 | sizeof (struct GNUNET_PeerIdentity) * put_path_length); | 2189 | sizeof (struct GNUNET_PeerIdentity) * put_path_length); |
2193 | } | 2190 | } |
2194 | memcpy (&pp[put_path_length], data, data_size); | 2191 | memcpy (&pp[put_path_length], data, data_size); |
2195 | 2192 | ||
2196 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); | 2193 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); |
2197 | target_friend->pending_count++; | 2194 | target_friend->pending_count++; |
2198 | process_friend_queue (target_friend); | 2195 | process_friend_queue (target_friend); |
@@ -2233,10 +2230,10 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key, | |||
2233 | struct FriendInfo *target_friend; | 2230 | struct FriendInfo *target_friend; |
2234 | struct GNUNET_PeerIdentity *gp; | 2231 | struct GNUNET_PeerIdentity *gp; |
2235 | size_t msize; | 2232 | size_t msize; |
2236 | 2233 | ||
2237 | msize = sizeof (struct PeerGetMessage) + | 2234 | msize = sizeof (struct PeerGetMessage) + |
2238 | (get_path_length * sizeof (struct GNUNET_PeerIdentity)); | 2235 | (get_path_length * sizeof (struct GNUNET_PeerIdentity)); |
2239 | 2236 | ||
2240 | /* In this case we don't make get_path_length = 0, as we need get path to | 2237 | /* In this case we don't make get_path_length = 0, as we need get path to |
2241 | * return the message back to querying client. */ | 2238 | * return the message back to querying client. */ |
2242 | if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 2239 | if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
@@ -2244,45 +2241,45 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key, | |||
2244 | GNUNET_break (0); | 2241 | GNUNET_break (0); |
2245 | return; | 2242 | return; |
2246 | } | 2243 | } |
2247 | 2244 | ||
2248 | /* This is the first time we got request from our own client file. */ | 2245 | /* This is the first time we got request from our own client file. */ |
2249 | if (NULL == target_peer) | 2246 | if (NULL == target_peer) |
2250 | { | 2247 | { |
2251 | uint64_t key_value; | 2248 | uint64_t key_value; |
2252 | struct Closest_Peer successor; | 2249 | struct Closest_Peer successor; |
2253 | 2250 | ||
2254 | memcpy (&key_value, key, sizeof (uint64_t)); | 2251 | memcpy (&key_value, key, sizeof (uint64_t)); |
2255 | key_value = GNUNET_ntohll (key_value); | 2252 | key_value = GNUNET_ntohll (key_value); |
2256 | successor = find_successor (key_value, GDS_FINGER_TYPE_NON_PREDECESSOR); | 2253 | successor = find_successor (key_value, GDS_FINGER_TYPE_NON_PREDECESSOR); |
2257 | 2254 | ||
2258 | best_known_dest = successor.best_known_destination; | 2255 | best_known_dest = successor.best_known_destination; |
2259 | intermediate_trail_id = successor.trail_id; | 2256 | intermediate_trail_id = successor.trail_id; |
2260 | 2257 | ||
2261 | /* I am the destination. I have the data. */ | 2258 | /* I am the destination. I have the data. */ |
2262 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, | 2259 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, |
2263 | &best_known_dest)) | 2260 | &best_known_dest)) |
2264 | { | 2261 | { |
2265 | GDS_DATACACHE_handle_get (key,block_type, NULL, 0, | 2262 | GDS_DATACACHE_handle_get (key,block_type, NULL, 0, |
2266 | NULL, 0, 1, &my_identity, NULL,&my_identity); | 2263 | NULL, 0, 1, &my_identity, NULL,&my_identity); |
2267 | 2264 | ||
2268 | return; | 2265 | return; |
2269 | } | 2266 | } |
2270 | else | 2267 | else |
2271 | { | 2268 | { |
2272 | GNUNET_assert (NULL != | 2269 | GNUNET_assert (NULL != |
2273 | (target_friend = | 2270 | (target_friend = |
2274 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 2271 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
2275 | &successor.next_hop))); | 2272 | &successor.next_hop))); |
2276 | } | 2273 | } |
2277 | 2274 | ||
2278 | } | 2275 | } |
2279 | else | 2276 | else |
2280 | { | 2277 | { |
2281 | GNUNET_assert (NULL != | 2278 | GNUNET_assert (NULL != |
2282 | (target_friend = | 2279 | (target_friend = |
2283 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer))); //FIXME: assertion fails. | 2280 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer))); //FIXME: assertion fails. |
2284 | } | 2281 | } |
2285 | 2282 | ||
2286 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 2283 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); |
2287 | pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); | 2284 | pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); |
2288 | pending->importance = 0; /* FIXME */ | 2285 | pending->importance = 0; /* FIXME */ |
@@ -2296,12 +2293,12 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key, | |||
2296 | pgm->intermediate_trail_id = intermediate_trail_id; | 2293 | pgm->intermediate_trail_id = intermediate_trail_id; |
2297 | pgm->hop_count = htonl (hop_count + 1); | 2294 | pgm->hop_count = htonl (hop_count + 1); |
2298 | gp = (struct GNUNET_PeerIdentity *) &pgm[1]; | 2295 | gp = (struct GNUNET_PeerIdentity *) &pgm[1]; |
2299 | 2296 | ||
2300 | if (get_path_length != 0) | 2297 | if (get_path_length != 0) |
2301 | { | 2298 | { |
2302 | memcpy (gp, get_path, get_path_length * sizeof (struct GNUNET_PeerIdentity)); | 2299 | memcpy (gp, get_path, get_path_length * sizeof (struct GNUNET_PeerIdentity)); |
2303 | } | 2300 | } |
2304 | 2301 | ||
2305 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); | 2302 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); |
2306 | target_friend->pending_count++; | 2303 | target_friend->pending_count++; |
2307 | process_friend_queue (target_friend); | 2304 | process_friend_queue (target_friend); |
@@ -2341,7 +2338,7 @@ GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *key, | |||
2341 | int current_path_index; | 2338 | int current_path_index; |
2342 | size_t msize; | 2339 | size_t msize; |
2343 | 2340 | ||
2344 | msize = (put_path_length + get_path_length )* sizeof (struct GNUNET_PeerIdentity) + | 2341 | msize = (put_path_length + get_path_length )* sizeof (struct GNUNET_PeerIdentity) + |
2345 | data_size + | 2342 | data_size + |
2346 | sizeof (struct PeerGetResultMessage); | 2343 | sizeof (struct PeerGetResultMessage); |
2347 | 2344 | ||
@@ -2350,7 +2347,7 @@ GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *key, | |||
2350 | GNUNET_break (0); | 2347 | GNUNET_break (0); |
2351 | return; | 2348 | return; |
2352 | } | 2349 | } |
2353 | 2350 | ||
2354 | current_path_index = 0; | 2351 | current_path_index = 0; |
2355 | if(get_path_length > 0) | 2352 | if(get_path_length > 0) |
2356 | { | 2353 | { |
@@ -2363,7 +2360,7 @@ GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *key, | |||
2363 | } | 2360 | } |
2364 | if (0 == current_path_index) | 2361 | if (0 == current_path_index) |
2365 | { | 2362 | { |
2366 | GDS_CLIENTS_handle_reply (expiration, key, get_path_length, | 2363 | GDS_CLIENTS_handle_reply (expiration, key, get_path_length, |
2367 | get_path, put_path_length, | 2364 | get_path, put_path_length, |
2368 | put_path, type, data_size, data); | 2365 | put_path, type, data_size, data); |
2369 | return; | 2366 | return; |
@@ -2371,7 +2368,7 @@ GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *key, | |||
2371 | 2368 | ||
2372 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 2369 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); |
2373 | pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); | 2370 | pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); |
2374 | pending->importance = 0; | 2371 | pending->importance = 0; |
2375 | get_result = (struct PeerGetResultMessage *)&pending[1]; | 2372 | get_result = (struct PeerGetResultMessage *)&pending[1]; |
2376 | pending->msg = &get_result->header; | 2373 | pending->msg = &get_result->header; |
2377 | get_result->header.size = htons (msize); | 2374 | get_result->header.size = htons (msize); |
@@ -2387,10 +2384,10 @@ GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *key, | |||
2387 | memcpy (&paths[put_path_length], get_path, | 2384 | memcpy (&paths[put_path_length], get_path, |
2388 | get_path_length * sizeof (struct GNUNET_PeerIdentity)); | 2385 | get_path_length * sizeof (struct GNUNET_PeerIdentity)); |
2389 | memcpy (&paths[put_path_length + get_path_length], data, data_size); | 2386 | memcpy (&paths[put_path_length + get_path_length], data, data_size); |
2390 | 2387 | ||
2391 | GNUNET_assert (NULL != | 2388 | GNUNET_assert (NULL != |
2392 | (target_friend = | 2389 | (target_friend = |
2393 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 2390 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
2394 | &get_path[current_path_index - 1]))); | 2391 | &get_path[current_path_index - 1]))); |
2395 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); | 2392 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); |
2396 | target_friend->pending_count++; | 2393 | target_friend->pending_count++; |
@@ -2416,7 +2413,7 @@ select_random_friend () | |||
2416 | struct FriendInfo *friend; | 2413 | struct FriendInfo *friend; |
2417 | 2414 | ||
2418 | current_size = GNUNET_CONTAINER_multipeermap_size (friend_peermap); | 2415 | current_size = GNUNET_CONTAINER_multipeermap_size (friend_peermap); |
2419 | 2416 | ||
2420 | /* No friends.*/ | 2417 | /* No friends.*/ |
2421 | if (0 == current_size) | 2418 | if (0 == current_size) |
2422 | return NULL; | 2419 | return NULL; |
@@ -2438,7 +2435,7 @@ select_random_friend () | |||
2438 | iter = GNUNET_CONTAINER_multipeermap_iterator_create (friend_peermap); | 2435 | iter = GNUNET_CONTAINER_multipeermap_iterator_create (friend_peermap); |
2439 | 2436 | ||
2440 | } | 2437 | } |
2441 | 2438 | ||
2442 | /* Get the friend stored at the index, j*/ | 2439 | /* Get the friend stored at the index, j*/ |
2443 | GNUNET_assert (GNUNET_YES == | 2440 | GNUNET_assert (GNUNET_YES == |
2444 | GNUNET_CONTAINER_multipeermap_iterator_next (iter, | 2441 | GNUNET_CONTAINER_multipeermap_iterator_next (iter, |
@@ -2461,8 +2458,8 @@ select_random_friend () | |||
2461 | 2458 | ||
2462 | 2459 | ||
2463 | /** | 2460 | /** |
2464 | * Compute 64 bit value of finger_identity corresponding to a finger index using | 2461 | * Compute 64 bit value of finger_identity corresponding to a finger index using |
2465 | * chord formula. | 2462 | * chord formula. |
2466 | * For all fingers, n.finger[i] = n + pow (2,i), | 2463 | * For all fingers, n.finger[i] = n + pow (2,i), |
2467 | * For predecessor, n.finger[PREDECESSOR_FINGER_ID] = n - 1, where | 2464 | * For predecessor, n.finger[PREDECESSOR_FINGER_ID] = n - 1, where |
2468 | * n = my_identity, i = finger_index, n.finger[i] = 64 bit finger value | 2465 | * n = my_identity, i = finger_index, n.finger[i] = 64 bit finger value |
@@ -2476,20 +2473,20 @@ compute_finger_identity_value (unsigned int finger_index) | |||
2476 | 2473 | ||
2477 | memcpy (&my_id64, &my_identity, sizeof (uint64_t)); | 2474 | memcpy (&my_id64, &my_identity, sizeof (uint64_t)); |
2478 | my_id64 = GNUNET_ntohll (my_id64); | 2475 | my_id64 = GNUNET_ntohll (my_id64); |
2479 | 2476 | ||
2480 | /* Are we looking for immediate predecessor? */ | 2477 | /* Are we looking for immediate predecessor? */ |
2481 | if (PREDECESSOR_FINGER_ID == finger_index) | 2478 | if (PREDECESSOR_FINGER_ID == finger_index) |
2482 | return (my_id64 - 1); | 2479 | return (my_id64 - 1); |
2483 | else | 2480 | else |
2484 | { | 2481 | { |
2485 | uint64_t add = (uint64_t)1 << finger_index; | 2482 | uint64_t add = (uint64_t)1 << finger_index; |
2486 | return (my_id64 + add); | 2483 | return (my_id64 + add); |
2487 | } | 2484 | } |
2488 | } | 2485 | } |
2489 | 2486 | ||
2490 | 2487 | ||
2491 | /* | 2488 | /* |
2492 | * Choose a random friend. Calculate the next finger identity to search,from | 2489 | * Choose a random friend. Calculate the next finger identity to search,from |
2493 | * current_search_finger_index. Start looking for the trail to reach to | 2490 | * current_search_finger_index. Start looking for the trail to reach to |
2494 | * finger identity through this random friend. | 2491 | * finger identity through this random friend. |
2495 | * | 2492 | * |
@@ -2520,29 +2517,29 @@ send_find_finger_trail_message (void *cls, | |||
2520 | * in their routing table). */ | 2517 | * in their routing table). */ |
2521 | if (GNUNET_YES == GDS_ROUTING_threshold_reached()) | 2518 | if (GNUNET_YES == GDS_ROUTING_threshold_reached()) |
2522 | return; | 2519 | return; |
2523 | 2520 | ||
2524 | 2521 | ||
2525 | target_friend = select_random_friend (); | 2522 | target_friend = select_random_friend (); |
2526 | if (NULL == target_friend) | 2523 | if (NULL == target_friend) |
2527 | { | 2524 | { |
2528 | return; | 2525 | return; |
2529 | } | 2526 | } |
2530 | 2527 | ||
2531 | finger_id_value = compute_finger_identity_value (current_search_finger_index); | 2528 | finger_id_value = compute_finger_identity_value (current_search_finger_index); |
2532 | 2529 | ||
2533 | if (PREDECESSOR_FINGER_ID == current_search_finger_index) | 2530 | if (PREDECESSOR_FINGER_ID == current_search_finger_index) |
2534 | is_predecessor = 1; | 2531 | is_predecessor = 1; |
2535 | else | 2532 | else |
2536 | is_predecessor = 0; | 2533 | is_predecessor = 0; |
2537 | 2534 | ||
2538 | /* Generate a unique trail id for trail we are trying to setup. */ | 2535 | /* Generate a unique trail id for trail we are trying to setup. */ |
2539 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, | 2536 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, |
2540 | &trail_id, sizeof (trail_id)); | 2537 | &trail_id, sizeof (trail_id)); |
2541 | memset(&intermediate_trail_id, 0, sizeof (struct GNUNET_HashCode)); | 2538 | memset(&intermediate_trail_id, 0, sizeof (struct GNUNET_HashCode)); |
2542 | 2539 | ||
2543 | GDS_NEIGHBOURS_send_trail_setup (my_identity, finger_id_value, | 2540 | GDS_NEIGHBOURS_send_trail_setup (my_identity, finger_id_value, |
2544 | target_friend->id, target_friend, 0, NULL, | 2541 | target_friend->id, target_friend, 0, NULL, |
2545 | is_predecessor, trail_id, | 2542 | is_predecessor, trail_id, |
2546 | intermediate_trail_id); | 2543 | intermediate_trail_id); |
2547 | } | 2544 | } |
2548 | 2545 | ||
@@ -2595,10 +2592,10 @@ select_and_replace_trail (struct FingerInfo *existing_finger, | |||
2595 | if (largest_trail_index == (MAXIMUM_TRAILS_PER_FINGER + 1)) | 2592 | if (largest_trail_index == (MAXIMUM_TRAILS_PER_FINGER + 1)) |
2596 | { | 2593 | { |
2597 | struct GNUNET_PeerIdentity next_hop; | 2594 | struct GNUNET_PeerIdentity next_hop; |
2598 | 2595 | ||
2599 | memcpy (&next_hop, &new_trail[0], sizeof(struct GNUNET_PeerIdentity)); | 2596 | memcpy (&next_hop, &new_trail[0], sizeof(struct GNUNET_PeerIdentity)); |
2600 | GDS_ROUTING_remove_trail (new_trail_id); | 2597 | GDS_ROUTING_remove_trail (new_trail_id); |
2601 | GDS_NEIGHBOURS_send_trail_teardown (new_trail_id, | 2598 | GDS_NEIGHBOURS_send_trail_teardown (new_trail_id, |
2602 | GDS_ROUTING_SRC_TO_DEST, | 2599 | GDS_ROUTING_SRC_TO_DEST, |
2603 | next_hop); | 2600 | next_hop); |
2604 | return; | 2601 | return; |
@@ -2623,7 +2620,7 @@ select_and_replace_trail (struct FingerInfo *existing_finger, | |||
2623 | replace_trail->is_present = GNUNET_YES; | 2620 | replace_trail->is_present = GNUNET_YES; |
2624 | replace_trail->trail_length = new_trail_length; | 2621 | replace_trail->trail_length = new_trail_length; |
2625 | replace_trail->trail_id = new_trail_id; | 2622 | replace_trail->trail_id = new_trail_id; |
2626 | //FIXME: Do we need to add pointers for head and tail. | 2623 | //FIXME: Do we need to add pointers for head and tail. |
2627 | i = 0; | 2624 | i = 0; |
2628 | while (i < new_trail_length) | 2625 | while (i < new_trail_length) |
2629 | { | 2626 | { |
@@ -2658,20 +2655,20 @@ is_new_trail_unique (struct FingerInfo *existing_finger, | |||
2658 | int trail_unique = GNUNET_NO; | 2655 | int trail_unique = GNUNET_NO; |
2659 | 2656 | ||
2660 | GNUNET_assert (existing_finger->trails_count > 0); | 2657 | GNUNET_assert (existing_finger->trails_count > 0); |
2661 | 2658 | ||
2662 | /* Iterate over list of trails. */ | 2659 | /* Iterate over list of trails. */ |
2663 | for (i = 0; i < existing_finger->trails_count; i++) | 2660 | for (i = 0; i < existing_finger->trails_count; i++) |
2664 | { | 2661 | { |
2665 | trail_list_iterator = &existing_finger->trail_list[i]; | 2662 | trail_list_iterator = &existing_finger->trail_list[i]; |
2666 | GNUNET_assert (GNUNET_YES == trail_list_iterator->is_present); | 2663 | GNUNET_assert (GNUNET_YES == trail_list_iterator->is_present); |
2667 | 2664 | ||
2668 | /* New trail and existing trail length are not same. */ | 2665 | /* New trail and existing trail length are not same. */ |
2669 | if (trail_list_iterator->trail_length != trail_length) | 2666 | if (trail_list_iterator->trail_length != trail_length) |
2670 | { | 2667 | { |
2671 | trail_unique = GNUNET_YES; | 2668 | trail_unique = GNUNET_YES; |
2672 | continue; | 2669 | continue; |
2673 | } | 2670 | } |
2674 | 2671 | ||
2675 | trail_element = trail_list_iterator->trail_head; | 2672 | trail_element = trail_list_iterator->trail_head; |
2676 | for (j = 0; j < trail_list_iterator->trail_length; j++) | 2673 | for (j = 0; j < trail_list_iterator->trail_length; j++) |
2677 | { | 2674 | { |
@@ -2683,18 +2680,18 @@ is_new_trail_unique (struct FingerInfo *existing_finger, | |||
2683 | } | 2680 | } |
2684 | trail_element = trail_element->next; | 2681 | trail_element = trail_element->next; |
2685 | } | 2682 | } |
2686 | 2683 | ||
2687 | trail_unique = GNUNET_NO; | 2684 | trail_unique = GNUNET_NO; |
2688 | } | 2685 | } |
2689 | 2686 | ||
2690 | return trail_unique; | 2687 | return trail_unique; |
2691 | } | 2688 | } |
2692 | 2689 | ||
2693 | 2690 | ||
2694 | /** | 2691 | /** |
2695 | * Add a new trail to existing finger. This function is called only when finger | 2692 | * Add a new trail to existing finger. This function is called only when finger |
2696 | * is not my own identity or a friend. | 2693 | * is not my own identity or a friend. |
2697 | * @param existing_finger Finger | 2694 | * @param existing_finger Finger |
2698 | * @param new_finger_trail New trail from me to finger, NOT including endpoints | 2695 | * @param new_finger_trail New trail from me to finger, NOT including endpoints |
2699 | * @param new_finger_trail_length Total number of peers in @a new_finger_trail | 2696 | * @param new_finger_trail_length Total number of peers in @a new_finger_trail |
2700 | * @param new_finger_trail_id Unique identifier of the trail. | 2697 | * @param new_finger_trail_id Unique identifier of the trail. |
@@ -2714,27 +2711,27 @@ add_new_trail (struct FingerInfo *existing_finger, | |||
2714 | { | 2711 | { |
2715 | return; | 2712 | return; |
2716 | } | 2713 | } |
2717 | 2714 | ||
2718 | trail_list_iterator = &existing_finger->trail_list[existing_finger->trails_count]; | 2715 | trail_list_iterator = &existing_finger->trail_list[existing_finger->trails_count]; |
2719 | GNUNET_assert (GNUNET_NO == trail_list_iterator->is_present); | 2716 | GNUNET_assert (GNUNET_NO == trail_list_iterator->is_present); |
2720 | trail_list_iterator->trail_id = new_trail_id; | 2717 | trail_list_iterator->trail_id = new_trail_id; |
2721 | trail_list_iterator->trail_length = new_trail_length; | 2718 | trail_list_iterator->trail_length = new_trail_length; |
2722 | existing_finger->trails_count++; | 2719 | existing_finger->trails_count++; |
2723 | trail_list_iterator->is_present = GNUNET_YES; | 2720 | trail_list_iterator->is_present = GNUNET_YES; |
2724 | 2721 | ||
2725 | GNUNET_assert (NULL == (GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 2722 | GNUNET_assert (NULL == (GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
2726 | &existing_finger->finger_identity))); | 2723 | &existing_finger->finger_identity))); |
2727 | /* If finger is a friend then we never call this function. */ | 2724 | /* If finger is a friend then we never call this function. */ |
2728 | GNUNET_assert (new_trail_length > 0); | 2725 | GNUNET_assert (new_trail_length > 0); |
2729 | 2726 | ||
2730 | first_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 2727 | first_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
2731 | &new_trail[0]); | 2728 | &new_trail[0]); |
2732 | first_friend->trails_count++; | 2729 | first_friend->trails_count++; |
2733 | 2730 | ||
2734 | for (i = 0; i < new_trail_length; i++) | 2731 | for (i = 0; i < new_trail_length; i++) |
2735 | { | 2732 | { |
2736 | struct Trail_Element *element; | 2733 | struct Trail_Element *element; |
2737 | 2734 | ||
2738 | element = GNUNET_new (struct Trail_Element); | 2735 | element = GNUNET_new (struct Trail_Element); |
2739 | element->peer = new_trail[i]; | 2736 | element->peer = new_trail[i]; |
2740 | GNUNET_CONTAINER_DLL_insert_tail (trail_list_iterator->trail_head, | 2737 | GNUNET_CONTAINER_DLL_insert_tail (trail_list_iterator->trail_head, |
@@ -2742,19 +2739,19 @@ add_new_trail (struct FingerInfo *existing_finger, | |||
2742 | element); | 2739 | element); |
2743 | } | 2740 | } |
2744 | /* Do we need to add trail head and trail tail in the trail list itearator.*/ | 2741 | /* Do we need to add trail head and trail tail in the trail list itearator.*/ |
2745 | 2742 | ||
2746 | } | 2743 | } |
2747 | 2744 | ||
2748 | 2745 | ||
2749 | /** | 2746 | /** |
2750 | * FIXME Check if this function is called for opposite direction if yes then | 2747 | * FIXME Check if this function is called for opposite direction if yes then |
2751 | * take it as parameter. | 2748 | * take it as parameter. |
2752 | * Get the next hop to send trail teardown message from routing table and | 2749 | * Get the next hop to send trail teardown message from routing table and |
2753 | * then delete the entry from routing table. Send trail teardown message for a | 2750 | * then delete the entry from routing table. Send trail teardown message for a |
2754 | * specific trail of a finger. | 2751 | * specific trail of a finger. |
2755 | * @param finger Finger whose trail is to be removed. | 2752 | * @param finger Finger whose trail is to be removed. |
2756 | * @param trail List of peers in trail from me to a finger, NOT including | 2753 | * @param trail List of peers in trail from me to a finger, NOT including |
2757 | * endpoints. | 2754 | * endpoints. |
2758 | */ | 2755 | */ |
2759 | static void | 2756 | static void |
2760 | send_trail_teardown (struct FingerInfo *finger, | 2757 | send_trail_teardown (struct FingerInfo *finger, |
@@ -2762,31 +2759,31 @@ send_trail_teardown (struct FingerInfo *finger, | |||
2762 | { | 2759 | { |
2763 | struct FriendInfo *friend; | 2760 | struct FriendInfo *friend; |
2764 | struct GNUNET_PeerIdentity *next_hop; | 2761 | struct GNUNET_PeerIdentity *next_hop; |
2765 | 2762 | ||
2766 | GNUNET_assert (NULL != | 2763 | GNUNET_assert (NULL != |
2767 | (next_hop = GDS_ROUTING_get_next_hop (trail->trail_id, | 2764 | (next_hop = GDS_ROUTING_get_next_hop (trail->trail_id, |
2768 | GDS_ROUTING_SRC_TO_DEST))); | 2765 | GDS_ROUTING_SRC_TO_DEST))); |
2769 | 2766 | ||
2770 | GNUNET_assert (0 != GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, | 2767 | GNUNET_assert (0 != GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, |
2771 | &my_identity)); | 2768 | &my_identity)); |
2772 | 2769 | ||
2773 | GNUNET_assert (trail->is_present == GNUNET_YES); | 2770 | GNUNET_assert (trail->is_present == GNUNET_YES); |
2774 | 2771 | ||
2775 | /* Finger is not a friend. */ | 2772 | /* Finger is not a friend. */ |
2776 | if (trail->trail_length > 0) | 2773 | if (trail->trail_length > 0) |
2777 | { | 2774 | { |
2778 | GNUNET_assert (NULL != (friend = | 2775 | GNUNET_assert (NULL != (friend = |
2779 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 2776 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
2780 | &trail->trail_head->peer))); | 2777 | &trail->trail_head->peer))); |
2781 | } | 2778 | } |
2782 | else | 2779 | else |
2783 | { | 2780 | { |
2784 | GNUNET_assert (NULL != (friend = | 2781 | GNUNET_assert (NULL != (friend = |
2785 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 2782 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
2786 | &finger->finger_identity))); | 2783 | &finger->finger_identity))); |
2787 | } | 2784 | } |
2788 | 2785 | ||
2789 | GNUNET_assert (0 == GNUNET_CRYPTO_cmp_peer_identity (next_hop, &friend->id)); //Fixme: assertion fails. | 2786 | GNUNET_assert (0 == GNUNET_CRYPTO_cmp_peer_identity (next_hop, &friend->id)); //Fixme: assertion fails. |
2790 | GNUNET_assert (GNUNET_YES == GDS_ROUTING_remove_trail (trail->trail_id)); | 2787 | GNUNET_assert (GNUNET_YES == GDS_ROUTING_remove_trail (trail->trail_id)); |
2791 | friend->trails_count--; | 2788 | friend->trails_count--; |
2792 | GDS_NEIGHBOURS_send_trail_teardown (trail->trail_id, | 2789 | GDS_NEIGHBOURS_send_trail_teardown (trail->trail_id, |
@@ -2796,18 +2793,18 @@ send_trail_teardown (struct FingerInfo *finger, | |||
2796 | 2793 | ||
2797 | 2794 | ||
2798 | /** | 2795 | /** |
2799 | * Send trail teardown message across all the trails to reach to finger. | 2796 | * Send trail teardown message across all the trails to reach to finger. |
2800 | * @param finger Finger whose all the trail should be freed. | 2797 | * @param finger Finger whose all the trail should be freed. |
2801 | */ | 2798 | */ |
2802 | static void | 2799 | static void |
2803 | send_all_finger_trails_teardown (struct FingerInfo *finger) | 2800 | send_all_finger_trails_teardown (struct FingerInfo *finger) |
2804 | { | 2801 | { |
2805 | unsigned int i; | 2802 | unsigned int i; |
2806 | 2803 | ||
2807 | for (i = 0; i < finger->trails_count; i++) | 2804 | for (i = 0; i < finger->trails_count; i++) |
2808 | { | 2805 | { |
2809 | struct Trail *trail; | 2806 | struct Trail *trail; |
2810 | 2807 | ||
2811 | trail = &finger->trail_list[i]; | 2808 | trail = &finger->trail_list[i]; |
2812 | GNUNET_assert (trail->is_present == GNUNET_YES); | 2809 | GNUNET_assert (trail->is_present == GNUNET_YES); |
2813 | send_trail_teardown (finger, trail); | 2810 | send_trail_teardown (finger, trail); |
@@ -2818,7 +2815,7 @@ send_all_finger_trails_teardown (struct FingerInfo *finger) | |||
2818 | 2815 | ||
2819 | /** | 2816 | /** |
2820 | * Free a specific trail | 2817 | * Free a specific trail |
2821 | * @param trail List of peers to be freed. | 2818 | * @param trail List of peers to be freed. |
2822 | */ | 2819 | */ |
2823 | static void | 2820 | static void |
2824 | free_trail (struct Trail *trail) | 2821 | free_trail (struct Trail *trail) |
@@ -2827,11 +2824,11 @@ free_trail (struct Trail *trail) | |||
2827 | 2824 | ||
2828 | while (NULL != (trail_element = trail->trail_head)) | 2825 | while (NULL != (trail_element = trail->trail_head)) |
2829 | { | 2826 | { |
2830 | GNUNET_CONTAINER_DLL_remove (trail->trail_head, | 2827 | GNUNET_CONTAINER_DLL_remove (trail->trail_head, |
2831 | trail->trail_tail, | 2828 | trail->trail_tail, |
2832 | trail_element); | 2829 | trail_element); |
2833 | GNUNET_free_non_null (trail_element); | 2830 | GNUNET_free_non_null (trail_element); |
2834 | } | 2831 | } |
2835 | trail->trail_head = NULL; | 2832 | trail->trail_head = NULL; |
2836 | trail->trail_tail = NULL; | 2833 | trail->trail_tail = NULL; |
2837 | } | 2834 | } |
@@ -2851,18 +2848,18 @@ free_finger (struct FingerInfo *finger, unsigned int finger_table_index) | |||
2851 | for (i = 0; i < finger->trails_count; i++) | 2848 | for (i = 0; i < finger->trails_count; i++) |
2852 | { | 2849 | { |
2853 | trail = &finger->trail_list[i]; | 2850 | trail = &finger->trail_list[i]; |
2854 | //FIXME: Check if there are any missing entry in this list because of | 2851 | //FIXME: Check if there are any missing entry in this list because of |
2855 | // how we insert. If not then no need of this check. | 2852 | // how we insert. If not then no need of this check. |
2856 | if (GNUNET_NO == trail->is_present) | 2853 | if (GNUNET_NO == trail->is_present) |
2857 | continue; | 2854 | continue; |
2858 | 2855 | ||
2859 | if (trail->trail_length > 0) | 2856 | if (trail->trail_length > 0) |
2860 | { | 2857 | { |
2861 | free_trail (trail); | 2858 | free_trail (trail); |
2862 | } | 2859 | } |
2863 | trail->is_present = GNUNET_NO; | 2860 | trail->is_present = GNUNET_NO; |
2864 | } | 2861 | } |
2865 | 2862 | ||
2866 | finger->is_present = GNUNET_NO; | 2863 | finger->is_present = GNUNET_NO; |
2867 | memset ((void *)&finger_table[finger_table_index], 0, sizeof (finger_table[finger_table_index])); | 2864 | memset ((void *)&finger_table[finger_table_index], 0, sizeof (finger_table[finger_table_index])); |
2868 | } | 2865 | } |
@@ -2871,8 +2868,8 @@ free_finger (struct FingerInfo *finger, unsigned int finger_table_index) | |||
2871 | /** | 2868 | /** |
2872 | * FIXME: ensure that you are not adding any trail to reach to a friend which | 2869 | * FIXME: ensure that you are not adding any trail to reach to a friend which |
2873 | * is a finger. Also decide on should you increment trails count of a friend | 2870 | * is a finger. Also decide on should you increment trails count of a friend |
2874 | * which is also a finger. | 2871 | * which is also a finger. |
2875 | * Add a new entry in finger table at finger_table_index. | 2872 | * Add a new entry in finger table at finger_table_index. |
2876 | * In case finger identity is me or a friend, then don't add a trail. NOTE | 2873 | * In case finger identity is me or a friend, then don't add a trail. NOTE |
2877 | * trail length to reach to a finger can be 0 only if the finger is a friend | 2874 | * trail length to reach to a finger can be 0 only if the finger is a friend |
2878 | * or my identity. | 2875 | * or my identity. |
@@ -2894,12 +2891,12 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity, | |||
2894 | struct FriendInfo *first_trail_hop; | 2891 | struct FriendInfo *first_trail_hop; |
2895 | struct Trail *trail; | 2892 | struct Trail *trail; |
2896 | int i = 0; | 2893 | int i = 0; |
2897 | 2894 | ||
2898 | new_entry = GNUNET_new (struct FingerInfo); | 2895 | new_entry = GNUNET_new (struct FingerInfo); |
2899 | new_entry->finger_identity = finger_identity; | 2896 | new_entry->finger_identity = finger_identity; |
2900 | new_entry->finger_table_index = finger_table_index; | 2897 | new_entry->finger_table_index = finger_table_index; |
2901 | new_entry->is_present = GNUNET_YES; | 2898 | new_entry->is_present = GNUNET_YES; |
2902 | 2899 | ||
2903 | /* If the new entry is my own identity. */ | 2900 | /* If the new entry is my own identity. */ |
2904 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &finger_identity)) | 2901 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &finger_identity)) |
2905 | { | 2902 | { |
@@ -2908,10 +2905,10 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity, | |||
2908 | GNUNET_free (new_entry); | 2905 | GNUNET_free (new_entry); |
2909 | return; | 2906 | return; |
2910 | } | 2907 | } |
2911 | 2908 | ||
2912 | /* If finger is a friend, then we don't actually have a trail. | 2909 | /* If finger is a friend, then we don't actually have a trail. |
2913 | * Just a trail id */ | 2910 | * Just a trail id */ |
2914 | if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 2911 | if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
2915 | &finger_identity)) | 2912 | &finger_identity)) |
2916 | { | 2913 | { |
2917 | new_entry->trail_list[0].trail_id = trail_id; | 2914 | new_entry->trail_list[0].trail_id = trail_id; |
@@ -2921,8 +2918,8 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity, | |||
2921 | new_entry->trail_list[0].trail_head = NULL; | 2918 | new_entry->trail_list[0].trail_head = NULL; |
2922 | new_entry->trail_list[0].trail_tail = NULL; | 2919 | new_entry->trail_list[0].trail_tail = NULL; |
2923 | finger_table[finger_table_index] = *new_entry; | 2920 | finger_table[finger_table_index] = *new_entry; |
2924 | GNUNET_assert (NULL != | 2921 | GNUNET_assert (NULL != |
2925 | (first_trail_hop = | 2922 | (first_trail_hop = |
2926 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 2923 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
2927 | &finger_identity))); | 2924 | &finger_identity))); |
2928 | 2925 | ||
@@ -2930,18 +2927,18 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity, | |||
2930 | GNUNET_free (new_entry); | 2927 | GNUNET_free (new_entry); |
2931 | return; | 2928 | return; |
2932 | } | 2929 | } |
2933 | 2930 | ||
2934 | /* finger trail length can be 0 only in case if finger is my identity or | 2931 | /* finger trail length can be 0 only in case if finger is my identity or |
2935 | finger is friend. We should never reach here. */ | 2932 | finger is friend. We should never reach here. */ |
2936 | GNUNET_assert (finger_trail_length > 0); | 2933 | GNUNET_assert (finger_trail_length > 0); |
2937 | 2934 | ||
2938 | GNUNET_assert (NULL != | 2935 | GNUNET_assert (NULL != |
2939 | (first_trail_hop = | 2936 | (first_trail_hop = |
2940 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 2937 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
2941 | &finger_trail[0]))); | 2938 | &finger_trail[0]))); |
2942 | new_entry->trails_count = 1; | 2939 | new_entry->trails_count = 1; |
2943 | first_trail_hop->trails_count++; | 2940 | first_trail_hop->trails_count++; |
2944 | 2941 | ||
2945 | /* Copy the finger trail into trail. */ | 2942 | /* Copy the finger trail into trail. */ |
2946 | trail = GNUNET_new (struct Trail); | 2943 | trail = GNUNET_new (struct Trail); |
2947 | while (i < finger_trail_length) | 2944 | while (i < finger_trail_length) |
@@ -2956,7 +2953,7 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity, | |||
2956 | element); | 2953 | element); |
2957 | i++; | 2954 | i++; |
2958 | } | 2955 | } |
2959 | 2956 | ||
2960 | /* Add trail to trail list. */ | 2957 | /* Add trail to trail list. */ |
2961 | new_entry->trail_list[0].trail_head = trail->trail_head; | 2958 | new_entry->trail_list[0].trail_head = trail->trail_head; |
2962 | new_entry->trail_list[0].trail_tail = trail->trail_tail; | 2959 | new_entry->trail_list[0].trail_tail = trail->trail_tail; |
@@ -2992,7 +2989,7 @@ scan_and_compress_trail (struct GNUNET_PeerIdentity finger_identity, | |||
2992 | struct FriendInfo *target_friend; | 2989 | struct FriendInfo *target_friend; |
2993 | struct GNUNET_PeerIdentity *new_trail; | 2990 | struct GNUNET_PeerIdentity *new_trail; |
2994 | unsigned int i; | 2991 | unsigned int i; |
2995 | 2992 | ||
2996 | /* I am my own finger. */ | 2993 | /* I am my own finger. */ |
2997 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &finger_identity)) | 2994 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &finger_identity)) |
2998 | { | 2995 | { |
@@ -3005,24 +3002,24 @@ scan_and_compress_trail (struct GNUNET_PeerIdentity finger_identity, | |||
3005 | *new_trail_length = 0; | 3002 | *new_trail_length = 0; |
3006 | return NULL; | 3003 | return NULL; |
3007 | } | 3004 | } |
3008 | 3005 | ||
3009 | /* If finger identity is a friend. */ | 3006 | /* If finger identity is a friend. */ |
3010 | if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, &finger_identity)) | 3007 | if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, &finger_identity)) |
3011 | { | 3008 | { |
3012 | *new_trail_length = 0; | 3009 | *new_trail_length = 0; |
3013 | 3010 | ||
3014 | /* If there is trail to reach this finger/friend */ | 3011 | /* If there is trail to reach this finger/friend */ |
3015 | if (trail_length > 0) | 3012 | if (trail_length > 0) |
3016 | { | 3013 | { |
3017 | /* Finger is your first friend. */ | 3014 | /* Finger is your first friend. */ |
3018 | GDS_ROUTING_update_trail_next_hop (trail_id, finger_identity); | 3015 | GDS_ROUTING_update_trail_next_hop (trail_id, finger_identity); |
3019 | GNUNET_assert (NULL != | 3016 | GNUNET_assert (NULL != |
3020 | (target_friend = | 3017 | (target_friend = |
3021 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 3018 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
3022 | &trail[0]))); | 3019 | &trail[0]))); |
3023 | |||
3024 | 3020 | ||
3025 | GDS_NEIGHBOURS_send_trail_compression (my_identity, | 3021 | |
3022 | GDS_NEIGHBOURS_send_trail_compression (my_identity, | ||
3026 | trail_id, finger_identity, | 3023 | trail_id, finger_identity, |
3027 | target_friend); | 3024 | target_friend); |
3028 | } | 3025 | } |
@@ -3038,16 +3035,16 @@ scan_and_compress_trail (struct GNUNET_PeerIdentity finger_identity, | |||
3038 | struct FriendInfo *target_friend; | 3035 | struct FriendInfo *target_friend; |
3039 | int j = 0; | 3036 | int j = 0; |
3040 | 3037 | ||
3041 | GNUNET_assert (NULL != | 3038 | GNUNET_assert (NULL != |
3042 | (target_friend = | 3039 | (target_friend = |
3043 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 3040 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
3044 | &trail[0]))); | 3041 | &trail[0]))); |
3045 | GDS_ROUTING_update_trail_next_hop (trail_id, trail[i]); | 3042 | GDS_ROUTING_update_trail_next_hop (trail_id, trail[i]); |
3046 | GDS_NEIGHBOURS_send_trail_compression (my_identity, | 3043 | GDS_NEIGHBOURS_send_trail_compression (my_identity, |
3047 | trail_id, trail[i], | 3044 | trail_id, trail[i], |
3048 | target_friend); | 3045 | target_friend); |
3049 | 3046 | ||
3050 | 3047 | ||
3051 | /* Copy the trail from index i to index (trail_length -1) into a new trail | 3048 | /* Copy the trail from index i to index (trail_length -1) into a new trail |
3052 | * and update new trail length */ | 3049 | * and update new trail length */ |
3053 | new_trail = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * (trail_length - i)); | 3050 | new_trail = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * (trail_length - i)); |
@@ -3062,9 +3059,9 @@ scan_and_compress_trail (struct GNUNET_PeerIdentity finger_identity, | |||
3062 | return new_trail; | 3059 | return new_trail; |
3063 | } | 3060 | } |
3064 | } | 3061 | } |
3065 | 3062 | ||
3066 | /* If we did not compress the trail, return the original trail back.*/ | 3063 | /* If we did not compress the trail, return the original trail back.*/ |
3067 | new_trail = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * trail_length); | 3064 | new_trail = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * trail_length); |
3068 | *new_trail_length = trail_length; | 3065 | *new_trail_length = trail_length; |
3069 | memcpy (new_trail, trail, trail_length * sizeof (struct GNUNET_PeerIdentity)); | 3066 | memcpy (new_trail, trail, trail_length * sizeof (struct GNUNET_PeerIdentity)); |
3070 | return new_trail; | 3067 | return new_trail; |
@@ -3074,7 +3071,7 @@ scan_and_compress_trail (struct GNUNET_PeerIdentity finger_identity, | |||
3074 | /** | 3071 | /** |
3075 | * Periodic task to verify current successor. There can be multiple trails to reach | 3072 | * Periodic task to verify current successor. There can be multiple trails to reach |
3076 | * to successor, choose the shortest one and send verify successor message | 3073 | * to successor, choose the shortest one and send verify successor message |
3077 | * across that trail. | 3074 | * across that trail. |
3078 | * @param cls closure for this task | 3075 | * @param cls closure for this task |
3079 | * @param tc the context under which the task is running | 3076 | * @param tc the context under which the task is running |
3080 | */ | 3077 | */ |
@@ -3091,7 +3088,7 @@ send_verify_successor_message (void *cls, | |||
3091 | unsigned int trail_length; | 3088 | unsigned int trail_length; |
3092 | unsigned int j = 0; | 3089 | unsigned int j = 0; |
3093 | struct FingerInfo *successor; | 3090 | struct FingerInfo *successor; |
3094 | 3091 | ||
3095 | /* Schedule another send_find_finger_trail_message task. */ | 3092 | /* Schedule another send_find_finger_trail_message task. */ |
3096 | next_send_time.rel_value_us = | 3093 | next_send_time.rel_value_us = |
3097 | DHT_FIND_FINGER_TRAIL_INTERVAL.rel_value_us + | 3094 | DHT_FIND_FINGER_TRAIL_INTERVAL.rel_value_us + |
@@ -3100,11 +3097,11 @@ send_verify_successor_message (void *cls, | |||
3100 | send_verify_successor_task = | 3097 | send_verify_successor_task = |
3101 | GNUNET_SCHEDULER_add_delayed (next_send_time, &send_verify_successor_message, | 3098 | GNUNET_SCHEDULER_add_delayed (next_send_time, &send_verify_successor_message, |
3102 | NULL); | 3099 | NULL); |
3103 | 3100 | ||
3104 | successor = &finger_table[0]; | 3101 | successor = &finger_table[0]; |
3105 | i = 0; | 3102 | i = 0; |
3106 | trail = &successor->trail_list[i]; | 3103 | trail = &successor->trail_list[i]; |
3107 | 3104 | ||
3108 | /* Store the successor for path tracking */ | 3105 | /* Store the successor for path tracking */ |
3109 | if (track_topology && (NULL != GDS_stats)) | 3106 | if (track_topology && (NULL != GDS_stats)) |
3110 | { | 3107 | { |
@@ -3121,21 +3118,21 @@ send_verify_successor_message (void *cls, | |||
3121 | GNUNET_STATISTICS_update (GDS_stats, "key", 1, 0); | 3118 | GNUNET_STATISTICS_update (GDS_stats, "key", 1, 0); |
3122 | GNUNET_free (key); | 3119 | GNUNET_free (key); |
3123 | } | 3120 | } |
3124 | 3121 | ||
3125 | GNUNET_assert(0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, | 3122 | GNUNET_assert(0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, |
3126 | &successor->finger_identity)); | 3123 | &successor->finger_identity)); |
3127 | 3124 | ||
3128 | /* Trail stored at this index. */ | 3125 | /* Trail stored at this index. */ |
3129 | GNUNET_assert (GNUNET_YES == trail->is_present); | 3126 | GNUNET_assert (GNUNET_YES == trail->is_present); |
3130 | 3127 | ||
3131 | trail_id = trail->trail_id; | 3128 | trail_id = trail->trail_id; |
3132 | trail_length = trail->trail_length; | 3129 | trail_length = trail->trail_length; |
3133 | 3130 | ||
3134 | if (trail_length > 0) | 3131 | if (trail_length > 0) |
3135 | { | 3132 | { |
3136 | /* Copy the trail into peer list. */ | 3133 | /* Copy the trail into peer list. */ |
3137 | struct GNUNET_PeerIdentity peer_list[trail_length]; | 3134 | struct GNUNET_PeerIdentity peer_list[trail_length]; |
3138 | 3135 | ||
3139 | element = trail->trail_head; | 3136 | element = trail->trail_head; |
3140 | while (j < trail_length) | 3137 | while (j < trail_length) |
3141 | { | 3138 | { |
@@ -3143,9 +3140,9 @@ send_verify_successor_message (void *cls, | |||
3143 | element = element->next; | 3140 | element = element->next; |
3144 | j++; | 3141 | j++; |
3145 | } | 3142 | } |
3146 | 3143 | ||
3147 | GNUNET_assert (NULL != (target_friend = | 3144 | GNUNET_assert (NULL != (target_friend = |
3148 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 3145 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
3149 | &peer_list[0]))); | 3146 | &peer_list[0]))); |
3150 | GDS_NEIGHBOURS_send_verify_successor_message (my_identity, | 3147 | GDS_NEIGHBOURS_send_verify_successor_message (my_identity, |
3151 | successor->finger_identity, | 3148 | successor->finger_identity, |
@@ -3155,8 +3152,8 @@ send_verify_successor_message (void *cls, | |||
3155 | } | 3152 | } |
3156 | else | 3153 | else |
3157 | { | 3154 | { |
3158 | GNUNET_assert (NULL != (target_friend = | 3155 | GNUNET_assert (NULL != (target_friend = |
3159 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 3156 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
3160 | &successor->finger_identity))); | 3157 | &successor->finger_identity))); |
3161 | GDS_NEIGHBOURS_send_verify_successor_message (my_identity, | 3158 | GDS_NEIGHBOURS_send_verify_successor_message (my_identity, |
3162 | successor->finger_identity, | 3159 | successor->finger_identity, |
@@ -3168,71 +3165,84 @@ send_verify_successor_message (void *cls, | |||
3168 | 3165 | ||
3169 | 3166 | ||
3170 | /** | 3167 | /** |
3171 | * Update the current search finger index. | 3168 | * Update the current search finger index. |
3169 | * | ||
3170 | * FIXME document parameters! | ||
3172 | */ | 3171 | */ |
3173 | static void | 3172 | static void |
3174 | update_current_search_finger_index (struct GNUNET_PeerIdentity finger_identity, | 3173 | update_current_search_finger_index (struct GNUNET_PeerIdentity finger_identity, |
3175 | unsigned int finger_table_index) | 3174 | unsigned int finger_table_index) |
3176 | { | 3175 | { |
3177 | struct FingerInfo *successor; | 3176 | struct FingerInfo *successor; |
3178 | 3177 | ||
3178 | /* FIXME correct this: only move current index periodically */ | ||
3179 | if (finger_table_index != current_search_finger_index) | 3179 | if (finger_table_index != current_search_finger_index) |
3180 | return; | 3180 | return; |
3181 | 3181 | ||
3182 | successor = &finger_table[0]; | 3182 | successor = &finger_table[0]; |
3183 | GNUNET_assert (GNUNET_YES == successor->is_present); | 3183 | GNUNET_assert (GNUNET_YES == successor->is_present); |
3184 | 3184 | ||
3185 | /* We were looking for immediate successor. */ | 3185 | /* We were looking for immediate successor. */ |
3186 | if (0 == current_search_finger_index) | 3186 | if (0 == current_search_finger_index) |
3187 | { | 3187 | { |
3188 | /* Start looking for immediate predecessor. */ | 3188 | /* Start looking for immediate predecessor. */ |
3189 | current_search_finger_index = PREDECESSOR_FINGER_ID; | 3189 | current_search_finger_index = PREDECESSOR_FINGER_ID; |
3190 | 3190 | ||
3191 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &finger_identity)) | 3191 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &finger_identity)) |
3192 | { | 3192 | { |
3193 | if (GNUNET_SCHEDULER_NO_TASK == send_verify_successor_task) | 3193 | if (GNUNET_SCHEDULER_NO_TASK == send_verify_successor_task) |
3194 | send_verify_successor_task = GNUNET_SCHEDULER_add_now (&send_verify_successor_message, NULL); | 3194 | send_verify_successor_task = GNUNET_SCHEDULER_add_now (&send_verify_successor_message, NULL); |
3195 | } | 3195 | } |
3196 | 3196 | ||
3197 | return; | 3197 | return; |
3198 | } | 3198 | } |
3199 | 3199 | ||
3200 | current_search_finger_index = current_search_finger_index - 1; | 3200 | current_search_finger_index = current_search_finger_index - 1; |
3201 | return; | 3201 | return; |
3202 | } | 3202 | } |
3203 | 3203 | ||
3204 | 3204 | ||
3205 | /** | 3205 | /** |
3206 | * Get the first set bit in val. | 3206 | * Get the least significant bit set in val. |
3207 | * | ||
3207 | * @param val Value | 3208 | * @param val Value |
3208 | * @return Position of first bit set. | 3209 | * @return Position of first bit set, 65 in case of error. |
3209 | */ | 3210 | */ |
3210 | static unsigned int | 3211 | static unsigned int |
3211 | find_set_bit(uint64_t val) | 3212 | find_set_bit (uint64_t val) |
3212 | { | 3213 | { |
3213 | uint64_t i; | 3214 | uint64_t i; |
3214 | unsigned int pos; | 3215 | unsigned int pos; |
3215 | 3216 | ||
3216 | i = 1; | 3217 | i = 1; |
3217 | pos = 0; | 3218 | pos = 0; |
3218 | 3219 | ||
3219 | while(!(i && val)) | 3220 | while (!(i & val)) |
3220 | { | 3221 | { |
3221 | i = i << val; | 3222 | i = i << 1; |
3222 | pos++; | 3223 | pos++; |
3224 | if (pos > 63) | ||
3225 | { | ||
3226 | GNUNET_break (0); | ||
3227 | return 65; | ||
3228 | } | ||
3223 | } | 3229 | } |
3230 | |||
3231 | if (val/i != 1) | ||
3232 | return 65; /* Some other bit was set to 1 as well. */ | ||
3233 | |||
3224 | return pos; | 3234 | return pos; |
3225 | } | 3235 | } |
3226 | 3236 | ||
3237 | |||
3227 | /** | 3238 | /** |
3228 | * Calculate finger_table_index from initial 64 bit finger identity value that | 3239 | * Calculate finger_table_index from initial 64 bit finger identity value that |
3229 | * we send in trail setup message. | 3240 | * we send in trail setup message. |
3230 | * @param ultimate_destination_finger_value Value that we calculated from our | 3241 | * @param ultimate_destination_finger_value Value that we calculated from our |
3231 | * identity and finger_table_index. | 3242 | * identity and finger_table_index. |
3232 | * @param is_predecessor Is the entry for predecessor or not? | 3243 | * @param is_predecessor Is the entry for predecessor or not? |
3233 | * @return finger_table_index Value between 0 <= finger_table_index <= 64 | 3244 | * @return finger_table_index Value between 0 <= finger_table_index <= 64 |
3234 | * finger_table_index > PREDECESSOR_FINGER_ID , | 3245 | * finger_table_index > PREDECESSOR_FINGER_ID, if error occurs. |
3235 | * if no valid finger_table_index is found. | ||
3236 | */ | 3246 | */ |
3237 | static unsigned int | 3247 | static unsigned int |
3238 | get_finger_table_index (uint64_t ultimate_destination_finger_value, | 3248 | get_finger_table_index (uint64_t ultimate_destination_finger_value, |
@@ -3244,7 +3254,7 @@ get_finger_table_index (uint64_t ultimate_destination_finger_value, | |||
3244 | 3254 | ||
3245 | memcpy (&my_id64, &my_identity, sizeof (uint64_t)); | 3255 | memcpy (&my_id64, &my_identity, sizeof (uint64_t)); |
3246 | my_id64 = GNUNET_ntohll (my_id64); | 3256 | my_id64 = GNUNET_ntohll (my_id64); |
3247 | 3257 | ||
3248 | /* Is this a predecessor finger? */ | 3258 | /* Is this a predecessor finger? */ |
3249 | if (1 == is_predecessor) | 3259 | if (1 == is_predecessor) |
3250 | { | 3260 | { |
@@ -3253,31 +3263,31 @@ get_finger_table_index (uint64_t ultimate_destination_finger_value, | |||
3253 | finger_table_index = PREDECESSOR_FINGER_ID; | 3263 | finger_table_index = PREDECESSOR_FINGER_ID; |
3254 | else | 3264 | else |
3255 | finger_table_index = PREDECESSOR_FINGER_ID + 1; //error value | 3265 | finger_table_index = PREDECESSOR_FINGER_ID + 1; //error value |
3256 | 3266 | ||
3257 | } | 3267 | } |
3258 | else | 3268 | else |
3259 | { | 3269 | { |
3260 | diff = ultimate_destination_finger_value - my_id64; | 3270 | diff = ultimate_destination_finger_value - my_id64; |
3261 | finger_table_index = find_set_bit(diff); | 3271 | finger_table_index = find_set_bit (diff); |
3262 | } | 3272 | } |
3263 | 3273 | ||
3264 | return finger_table_index; | 3274 | return finger_table_index; |
3265 | } | 3275 | } |
3266 | 3276 | ||
3267 | 3277 | ||
3268 | /** | 3278 | /** |
3269 | * Remove finger and its associated data structures from finger table. | 3279 | * Remove finger and its associated data structures from finger table. |
3270 | * @param finger Finger to be removed. | 3280 | * @param finger Finger to be removed. |
3271 | */ | 3281 | */ |
3272 | static void | 3282 | static void |
3273 | remove_existing_finger (struct FingerInfo *existing_finger, | 3283 | remove_existing_finger (struct FingerInfo *existing_finger, |
3274 | unsigned int finger_table_index) | 3284 | unsigned int finger_table_index) |
3275 | { | 3285 | { |
3276 | struct FingerInfo *finger; | 3286 | struct FingerInfo *finger; |
3277 | 3287 | ||
3278 | finger = &finger_table[finger_table_index]; | 3288 | finger = &finger_table[finger_table_index]; |
3279 | GNUNET_assert (GNUNET_YES == finger->is_present); | 3289 | GNUNET_assert (GNUNET_YES == finger->is_present); |
3280 | 3290 | ||
3281 | /* If I am my own finger, then we have no trails. */ | 3291 | /* If I am my own finger, then we have no trails. */ |
3282 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, | 3292 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, |
3283 | &my_identity)) | 3293 | &my_identity)) |
@@ -3287,7 +3297,7 @@ remove_existing_finger (struct FingerInfo *existing_finger, | |||
3287 | sizeof (finger_table[finger_table_index])); | 3297 | sizeof (finger_table[finger_table_index])); |
3288 | return; | 3298 | return; |
3289 | } | 3299 | } |
3290 | 3300 | ||
3291 | /* For all other fingers, send trail teardown across all the trails to reach | 3301 | /* For all other fingers, send trail teardown across all the trails to reach |
3292 | finger, and free the finger. */ | 3302 | finger, and free the finger. */ |
3293 | send_all_finger_trails_teardown (finger); | 3303 | send_all_finger_trails_teardown (finger); |
@@ -3300,15 +3310,15 @@ remove_existing_finger (struct FingerInfo *existing_finger, | |||
3300 | * Check if there is already an entry in finger_table at finger_table_index. | 3310 | * Check if there is already an entry in finger_table at finger_table_index. |
3301 | * We get the finger_table_index from 64bit finger value we got from the network. | 3311 | * We get the finger_table_index from 64bit finger value we got from the network. |
3302 | * -- If yes, then select the closest finger. | 3312 | * -- If yes, then select the closest finger. |
3303 | * -- If new and existing finger are same, then check if you can store more | 3313 | * -- If new and existing finger are same, then check if you can store more |
3304 | * trails. | 3314 | * trails. |
3305 | * -- If yes then add trail, else keep the best trails to reach to the | 3315 | * -- If yes then add trail, else keep the best trails to reach to the |
3306 | * finger. | 3316 | * finger. |
3307 | * -- If the new finger is closest, remove the existing entry, send trail | 3317 | * -- If the new finger is closest, remove the existing entry, send trail |
3308 | * teardown message across all the trails to reach the existing entry. | 3318 | * teardown message across all the trails to reach the existing entry. |
3309 | * Add the new finger. | 3319 | * Add the new finger. |
3310 | * -- If new and existing finger are different, and existing finger is closest | 3320 | * -- If new and existing finger are different, and existing finger is closest |
3311 | * then do nothing. | 3321 | * then do nothing. |
3312 | * -- Update current_search_finger_index. | 3322 | * -- Update current_search_finger_index. |
3313 | * @param finger_identity Peer Identity of new finger | 3323 | * @param finger_identity Peer Identity of new finger |
3314 | * @param finger_trail Trail to reach the new finger | 3324 | * @param finger_trail Trail to reach the new finger |
@@ -3318,22 +3328,22 @@ remove_existing_finger (struct FingerInfo *existing_finger, | |||
3318 | * @param finger_trail_id Unique identifier of @finger_trail. | 3328 | * @param finger_trail_id Unique identifier of @finger_trail. |
3319 | */ | 3329 | */ |
3320 | static void | 3330 | static void |
3321 | finger_table_add (struct GNUNET_PeerIdentity finger_identity, | 3331 | finger_table_add (struct GNUNET_PeerIdentity finger_identity, |
3322 | const struct GNUNET_PeerIdentity *finger_trail, | 3332 | const struct GNUNET_PeerIdentity *finger_trail, |
3323 | unsigned int finger_trail_length, | 3333 | unsigned int finger_trail_length, |
3324 | unsigned int is_predecessor, | 3334 | unsigned int is_predecessor, |
3325 | uint64_t finger_value, | 3335 | uint64_t finger_value, |
3326 | struct GNUNET_HashCode finger_trail_id) | 3336 | struct GNUNET_HashCode finger_trail_id) |
3327 | { | 3337 | { |
3328 | struct FingerInfo *existing_finger; | 3338 | struct FingerInfo *existing_finger; |
3329 | struct GNUNET_PeerIdentity *closest_peer; | 3339 | const struct GNUNET_PeerIdentity *closest_peer; |
3330 | struct FingerInfo *successor; | 3340 | struct FingerInfo *successor; |
3331 | int updated_finger_trail_length; | 3341 | int updated_finger_trail_length; |
3332 | unsigned int finger_table_index; | 3342 | unsigned int finger_table_index; |
3333 | 3343 | ||
3334 | /* Get the finger_table_index corresponding to finger_value we got from network.*/ | 3344 | /* Get the finger_table_index corresponding to finger_value we got from network.*/ |
3335 | finger_table_index = get_finger_table_index (finger_value, is_predecessor); | 3345 | finger_table_index = get_finger_table_index (finger_value, is_predecessor); |
3336 | 3346 | ||
3337 | /* Invalid finger_table_index. */ | 3347 | /* Invalid finger_table_index. */ |
3338 | if ((finger_table_index > PREDECESSOR_FINGER_ID)) | 3348 | if ((finger_table_index > PREDECESSOR_FINGER_ID)) |
3339 | { | 3349 | { |
@@ -3342,11 +3352,15 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity, | |||
3342 | } | 3352 | } |
3343 | 3353 | ||
3344 | /* New entry same as successor. */ | 3354 | /* New entry same as successor. */ |
3345 | if ((0 != finger_table_index) && | 3355 | if ((0 != finger_table_index) && |
3346 | (PREDECESSOR_FINGER_ID != finger_table_index)) | 3356 | (PREDECESSOR_FINGER_ID != finger_table_index)) |
3347 | { | 3357 | { |
3348 | successor = &finger_table[0]; | 3358 | successor = &finger_table[0]; |
3349 | GNUNET_assert (GNUNET_YES == successor->is_present); | 3359 | if (GNUNET_NO == successor->is_present) |
3360 | { | ||
3361 | GNUNET_break_op (0); | ||
3362 | return; | ||
3363 | } | ||
3350 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, | 3364 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, |
3351 | &successor->finger_identity)) | 3365 | &successor->finger_identity)) |
3352 | { | 3366 | { |
@@ -3354,39 +3368,39 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity, | |||
3354 | return; | 3368 | return; |
3355 | } | 3369 | } |
3356 | } | 3370 | } |
3357 | 3371 | ||
3358 | existing_finger = &finger_table[finger_table_index]; | 3372 | existing_finger = &finger_table[finger_table_index]; |
3359 | 3373 | ||
3360 | /* No entry present in finger_table for given finger map index. */ | 3374 | /* No entry present in finger_table for given finger map index. */ |
3361 | if (GNUNET_NO == existing_finger->is_present) | 3375 | if (GNUNET_NO == existing_finger->is_present) |
3362 | { | 3376 | { |
3363 | struct GNUNET_PeerIdentity *updated_trail; | 3377 | struct GNUNET_PeerIdentity *updated_trail; |
3364 | 3378 | ||
3365 | /* Shorten the trail if possible. */ | 3379 | /* Shorten the trail if possible. */ |
3366 | updated_finger_trail_length = finger_trail_length; | 3380 | updated_finger_trail_length = finger_trail_length; |
3367 | updated_trail = | 3381 | updated_trail = scan_and_compress_trail (finger_identity, finger_trail, |
3368 | scan_and_compress_trail (finger_identity, finger_trail, | 3382 | finger_trail_length, |
3369 | finger_trail_length, finger_trail_id, | 3383 | finger_trail_id, |
3370 | &updated_finger_trail_length); | 3384 | &updated_finger_trail_length); |
3371 | 3385 | ||
3372 | add_new_finger (finger_identity, updated_trail, | 3386 | add_new_finger (finger_identity, updated_trail, |
3373 | updated_finger_trail_length, | 3387 | updated_finger_trail_length, |
3374 | finger_trail_id, finger_table_index); | 3388 | finger_trail_id, finger_table_index); |
3375 | update_current_search_finger_index (finger_identity, | 3389 | update_current_search_finger_index (finger_identity, |
3376 | finger_table_index); | 3390 | finger_table_index); |
3377 | return; | 3391 | return; |
3378 | } | 3392 | } |
3379 | 3393 | ||
3380 | 3394 | ||
3381 | /* If existing entry and finger identity are not same. */ | 3395 | /* If existing entry and finger identity are not same. */ |
3382 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&(existing_finger->finger_identity), | 3396 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&(existing_finger->finger_identity), |
3383 | &finger_identity)) | 3397 | &finger_identity)) |
3384 | { | 3398 | { |
3385 | closest_peer = select_closest_peer (&existing_finger->finger_identity, | 3399 | closest_peer = select_closest_peer (&existing_finger->finger_identity, |
3386 | &finger_identity, | 3400 | &finger_identity, |
3387 | finger_value, | 3401 | finger_value, |
3388 | is_predecessor); | 3402 | is_predecessor); |
3389 | 3403 | ||
3390 | /* If the new finger is the closest peer. */ | 3404 | /* If the new finger is the closest peer. */ |
3391 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, closest_peer)) | 3405 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, closest_peer)) |
3392 | { | 3406 | { |
@@ -3395,25 +3409,25 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity, | |||
3395 | updated_finger_trail_length = finger_trail_length; | 3409 | updated_finger_trail_length = finger_trail_length; |
3396 | updated_trail = | 3410 | updated_trail = |
3397 | scan_and_compress_trail (finger_identity, finger_trail, | 3411 | scan_and_compress_trail (finger_identity, finger_trail, |
3398 | finger_trail_length, finger_trail_id, | 3412 | finger_trail_length, finger_trail_id, |
3399 | &updated_finger_trail_length); | 3413 | &updated_finger_trail_length); |
3400 | remove_existing_finger (existing_finger, finger_table_index); | 3414 | remove_existing_finger (existing_finger, finger_table_index); |
3401 | add_new_finger (finger_identity, updated_trail, updated_finger_trail_length, | 3415 | add_new_finger (finger_identity, updated_trail, updated_finger_trail_length, |
3402 | finger_trail_id, finger_table_index); | 3416 | finger_trail_id, finger_table_index); |
3403 | 3417 | ||
3404 | } | 3418 | } |
3405 | else | 3419 | else |
3406 | { | 3420 | { |
3407 | /* Existing finger is the closest one. We need to send trail teardown | 3421 | /* Existing finger is the closest one. We need to send trail teardown |
3408 | across the trail setup in routing table of all the peers. */ | 3422 | across the trail setup in routing table of all the peers. */ |
3409 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, &my_identity)) | 3423 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, &my_identity)) |
3410 | { | 3424 | { |
3411 | if (finger_trail_length > 0) | 3425 | if (finger_trail_length > 0) |
3412 | GDS_NEIGHBOURS_send_trail_teardown (finger_trail_id, | 3426 | GDS_NEIGHBOURS_send_trail_teardown (finger_trail_id, |
3413 | GDS_ROUTING_SRC_TO_DEST, | 3427 | GDS_ROUTING_SRC_TO_DEST, |
3414 | finger_trail[0]); | 3428 | finger_trail[0]); |
3415 | else | 3429 | else |
3416 | GDS_NEIGHBOURS_send_trail_teardown (finger_trail_id, | 3430 | GDS_NEIGHBOURS_send_trail_teardown (finger_trail_id, |
3417 | GDS_ROUTING_SRC_TO_DEST, | 3431 | GDS_ROUTING_SRC_TO_DEST, |
3418 | finger_identity); | 3432 | finger_identity); |
3419 | } | 3433 | } |
@@ -3433,12 +3447,12 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity, | |||
3433 | &existing_finger->finger_identity)) | 3447 | &existing_finger->finger_identity)) |
3434 | { | 3448 | { |
3435 | struct GNUNET_PeerIdentity *updated_trail; | 3449 | struct GNUNET_PeerIdentity *updated_trail; |
3436 | 3450 | ||
3437 | /* Shorten the trail if possible. */ | 3451 | /* Shorten the trail if possible. */ |
3438 | updated_finger_trail_length = finger_trail_length; | 3452 | updated_finger_trail_length = finger_trail_length; |
3439 | updated_trail = | 3453 | updated_trail = |
3440 | scan_and_compress_trail (finger_identity, finger_trail, | 3454 | scan_and_compress_trail (finger_identity, finger_trail, |
3441 | finger_trail_length, finger_trail_id, | 3455 | finger_trail_length, finger_trail_id, |
3442 | &updated_finger_trail_length); | 3456 | &updated_finger_trail_length); |
3443 | /* If there is space to store more trails. */ | 3457 | /* If there is space to store more trails. */ |
3444 | if (existing_finger->trails_count < MAXIMUM_TRAILS_PER_FINGER) | 3458 | if (existing_finger->trails_count < MAXIMUM_TRAILS_PER_FINGER) |
@@ -3447,7 +3461,7 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity, | |||
3447 | else | 3461 | else |
3448 | select_and_replace_trail (existing_finger, updated_trail, | 3462 | select_and_replace_trail (existing_finger, updated_trail, |
3449 | updated_finger_trail_length, finger_trail_id); | 3463 | updated_finger_trail_length, finger_trail_id); |
3450 | 3464 | ||
3451 | } | 3465 | } |
3452 | } | 3466 | } |
3453 | update_current_search_finger_index (finger_identity, finger_table_index); | 3467 | update_current_search_finger_index (finger_identity, finger_table_index); |
@@ -3478,18 +3492,18 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3478 | uint32_t putlen; | 3492 | uint32_t putlen; |
3479 | size_t payload_size; | 3493 | size_t payload_size; |
3480 | uint64_t key_value; | 3494 | uint64_t key_value; |
3481 | 3495 | ||
3482 | msize = ntohs (message->size); | 3496 | msize = ntohs (message->size); |
3483 | if (msize < sizeof (struct PeerPutMessage)) | 3497 | if (msize < sizeof (struct PeerPutMessage)) |
3484 | { | 3498 | { |
3485 | GNUNET_break_op (0); | 3499 | GNUNET_break_op (0); |
3486 | return GNUNET_OK; | 3500 | return GNUNET_OK; |
3487 | } | 3501 | } |
3488 | 3502 | ||
3489 | put = (struct PeerPutMessage *) message; | 3503 | put = (struct PeerPutMessage *) message; |
3490 | putlen = ntohl (put->put_path_length); | 3504 | putlen = ntohl (put->put_path_length); |
3491 | 3505 | ||
3492 | 3506 | ||
3493 | if ((msize < | 3507 | if ((msize < |
3494 | sizeof (struct PeerPutMessage) + | 3508 | sizeof (struct PeerPutMessage) + |
3495 | putlen * sizeof (struct GNUNET_PeerIdentity)) || | 3509 | putlen * sizeof (struct GNUNET_PeerIdentity)) || |
@@ -3505,10 +3519,10 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3505 | payload = &put_path[putlen]; | 3519 | payload = &put_path[putlen]; |
3506 | options = ntohl (put->options); | 3520 | options = ntohl (put->options); |
3507 | intermediate_trail_id = put->intermediate_trail_id; | 3521 | intermediate_trail_id = put->intermediate_trail_id; |
3508 | 3522 | ||
3509 | payload_size = msize - (sizeof (struct PeerPutMessage) + | 3523 | payload_size = msize - (sizeof (struct PeerPutMessage) + |
3510 | putlen * sizeof (struct GNUNET_PeerIdentity)); | 3524 | putlen * sizeof (struct GNUNET_PeerIdentity)); |
3511 | 3525 | ||
3512 | switch (GNUNET_BLOCK_get_key (GDS_block_context, ntohl (put->block_type), | 3526 | switch (GNUNET_BLOCK_get_key (GDS_block_context, ntohl (put->block_type), |
3513 | payload, payload_size, &test_key)) | 3527 | payload, payload_size, &test_key)) |
3514 | { | 3528 | { |
@@ -3531,7 +3545,7 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3531 | /* cannot verify, good luck */ | 3545 | /* cannot verify, good luck */ |
3532 | break; | 3546 | break; |
3533 | } | 3547 | } |
3534 | 3548 | ||
3535 | if (ntohl (put->block_type) == GNUNET_BLOCK_TYPE_REGEX) /* FIXME: do for all tpyes */ | 3549 | if (ntohl (put->block_type) == GNUNET_BLOCK_TYPE_REGEX) /* FIXME: do for all tpyes */ |
3536 | { | 3550 | { |
3537 | switch (GNUNET_BLOCK_evaluate (GDS_block_context, | 3551 | switch (GNUNET_BLOCK_evaluate (GDS_block_context, |
@@ -3556,7 +3570,7 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3556 | return GNUNET_OK; | 3570 | return GNUNET_OK; |
3557 | } | 3571 | } |
3558 | } | 3572 | } |
3559 | 3573 | ||
3560 | /* extend 'put path' by sender */ | 3574 | /* extend 'put path' by sender */ |
3561 | struct GNUNET_PeerIdentity pp[putlen + 1]; | 3575 | struct GNUNET_PeerIdentity pp[putlen + 1]; |
3562 | if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE)) | 3576 | if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE)) |
@@ -3567,11 +3581,11 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3567 | } | 3581 | } |
3568 | else | 3582 | else |
3569 | putlen = 0; | 3583 | putlen = 0; |
3570 | 3584 | ||
3571 | memcpy (&key_value, &(put->key), sizeof (uint64_t)); | 3585 | memcpy (&key_value, &(put->key), sizeof (uint64_t)); |
3572 | if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&best_known_dest, &my_identity))) | 3586 | if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&best_known_dest, &my_identity))) |
3573 | { | 3587 | { |
3574 | next_hop = GDS_ROUTING_get_next_hop (intermediate_trail_id, | 3588 | next_hop = GDS_ROUTING_get_next_hop (intermediate_trail_id, |
3575 | GDS_ROUTING_SRC_TO_DEST); | 3589 | GDS_ROUTING_SRC_TO_DEST); |
3576 | if (NULL == next_hop) | 3590 | if (NULL == next_hop) |
3577 | { | 3591 | { |
@@ -3587,13 +3601,13 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3587 | struct Closest_Peer successor; | 3601 | struct Closest_Peer successor; |
3588 | key_value = GNUNET_ntohll (key_value); | 3602 | key_value = GNUNET_ntohll (key_value); |
3589 | successor = find_successor (key_value, GDS_FINGER_TYPE_NON_PREDECESSOR); | 3603 | successor = find_successor (key_value, GDS_FINGER_TYPE_NON_PREDECESSOR); |
3590 | 3604 | ||
3591 | next_hop = GNUNET_new (struct GNUNET_PeerIdentity); | 3605 | next_hop = GNUNET_new (struct GNUNET_PeerIdentity); |
3592 | *next_hop = successor.next_hop; | 3606 | *next_hop = successor.next_hop; |
3593 | intermediate_trail_id = successor.trail_id; | 3607 | intermediate_trail_id = successor.trail_id; |
3594 | best_known_dest = successor.best_known_destination; | 3608 | best_known_dest = successor.best_known_destination; |
3595 | } | 3609 | } |
3596 | 3610 | ||
3597 | GDS_CLIENTS_process_put (options, | 3611 | GDS_CLIENTS_process_put (options, |
3598 | ntohl (put->block_type), | 3612 | ntohl (put->block_type), |
3599 | ntohl (put->hop_count), | 3613 | ntohl (put->hop_count), |
@@ -3603,17 +3617,17 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3603 | &put->key, | 3617 | &put->key, |
3604 | payload, | 3618 | payload, |
3605 | payload_size); | 3619 | payload_size); |
3606 | 3620 | ||
3607 | /* I am the final destination */ | 3621 | /* I am the final destination */ |
3608 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &best_known_dest)) | 3622 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &best_known_dest)) |
3609 | { | 3623 | { |
3610 | GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (put->expiration_time), | 3624 | GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (put->expiration_time), |
3611 | &(put->key),putlen, pp, ntohl (put->block_type), | 3625 | &(put->key),putlen, pp, ntohl (put->block_type), |
3612 | payload_size, payload); | 3626 | payload_size, payload); |
3613 | } | 3627 | } |
3614 | else | 3628 | else |
3615 | { | 3629 | { |
3616 | GDS_NEIGHBOURS_send_put (&put->key, | 3630 | GDS_NEIGHBOURS_send_put (&put->key, |
3617 | ntohl (put->block_type),ntohl (put->options), | 3631 | ntohl (put->block_type),ntohl (put->options), |
3618 | ntohl (put->desired_replication_level), | 3632 | ntohl (put->desired_replication_level), |
3619 | best_known_dest, intermediate_trail_id, next_hop, | 3633 | best_known_dest, intermediate_trail_id, next_hop, |
@@ -3646,7 +3660,7 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3646 | uint32_t get_length; | 3660 | uint32_t get_length; |
3647 | uint64_t key_value; | 3661 | uint64_t key_value; |
3648 | size_t msize; | 3662 | size_t msize; |
3649 | 3663 | ||
3650 | msize = ntohs (message->size); | 3664 | msize = ntohs (message->size); |
3651 | if (msize < sizeof (struct PeerGetMessage)) | 3665 | if (msize < sizeof (struct PeerGetMessage)) |
3652 | { | 3666 | { |
@@ -3659,7 +3673,7 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3659 | best_known_dest = get->best_known_destination; | 3673 | best_known_dest = get->best_known_destination; |
3660 | intermediate_trail_id = get->intermediate_trail_id; | 3674 | intermediate_trail_id = get->intermediate_trail_id; |
3661 | get_path = (const struct GNUNET_PeerIdentity *)&get[1]; | 3675 | get_path = (const struct GNUNET_PeerIdentity *)&get[1]; |
3662 | 3676 | ||
3663 | if ((msize < | 3677 | if ((msize < |
3664 | sizeof (struct PeerGetMessage) + | 3678 | sizeof (struct PeerGetMessage) + |
3665 | get_length * sizeof (struct GNUNET_PeerIdentity)) || | 3679 | get_length * sizeof (struct GNUNET_PeerIdentity)) || |
@@ -3667,23 +3681,23 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3667 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity))) | 3681 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity))) |
3668 | { | 3682 | { |
3669 | GNUNET_break_op (0); | 3683 | GNUNET_break_op (0); |
3670 | return GNUNET_YES; | 3684 | return GNUNET_YES; |
3671 | } | 3685 | } |
3672 | 3686 | ||
3673 | /* Add sender to get path */ | 3687 | /* Add sender to get path */ |
3674 | struct GNUNET_PeerIdentity gp[get_length + 1]; | 3688 | struct GNUNET_PeerIdentity gp[get_length + 1]; |
3675 | if (get_length > 0) | 3689 | if (get_length > 0) |
3676 | memcpy (gp, get_path, get_length * sizeof (struct GNUNET_PeerIdentity)); | 3690 | memcpy (gp, get_path, get_length * sizeof (struct GNUNET_PeerIdentity)); |
3677 | gp[get_length] = *peer; | 3691 | gp[get_length] = *peer; |
3678 | get_length = get_length + 1; | 3692 | get_length = get_length + 1; |
3679 | 3693 | ||
3680 | memcpy (&key_value, &(get->key), sizeof (uint64_t)); | 3694 | memcpy (&key_value, &(get->key), sizeof (uint64_t)); |
3681 | key_value = GNUNET_ntohll (key_value); | 3695 | key_value = GNUNET_ntohll (key_value); |
3682 | 3696 | ||
3683 | /* I am not the final destination. I am part of trail to reach final dest. */ | 3697 | /* I am not the final destination. I am part of trail to reach final dest. */ |
3684 | if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&best_known_dest, &my_identity))) | 3698 | if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&best_known_dest, &my_identity))) |
3685 | { | 3699 | { |
3686 | next_hop = GDS_ROUTING_get_next_hop (intermediate_trail_id, | 3700 | next_hop = GDS_ROUTING_get_next_hop (intermediate_trail_id, |
3687 | GDS_ROUTING_SRC_TO_DEST); | 3701 | GDS_ROUTING_SRC_TO_DEST); |
3688 | if (NULL == next_hop) | 3702 | if (NULL == next_hop) |
3689 | { | 3703 | { |
@@ -3704,7 +3718,7 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3704 | best_known_dest = successor.best_known_destination; | 3718 | best_known_dest = successor.best_known_destination; |
3705 | intermediate_trail_id = successor.trail_id; | 3719 | intermediate_trail_id = successor.trail_id; |
3706 | } | 3720 | } |
3707 | 3721 | ||
3708 | GDS_CLIENTS_process_get (get->options, get->block_type,get->hop_count, | 3722 | GDS_CLIENTS_process_get (get->options, get->block_type,get->hop_count, |
3709 | get->desired_replication_level, get->get_path_length, | 3723 | get->desired_replication_level, get->get_path_length, |
3710 | gp, &get->key); | 3724 | gp, &get->key); |
@@ -3716,17 +3730,17 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3716 | memcpy (final_get_path, gp, get_length * sizeof (struct GNUNET_PeerIdentity)); | 3730 | memcpy (final_get_path, gp, get_length * sizeof (struct GNUNET_PeerIdentity)); |
3717 | memcpy (&final_get_path[get_length], &my_identity, sizeof (struct GNUNET_PeerIdentity)); | 3731 | memcpy (&final_get_path[get_length], &my_identity, sizeof (struct GNUNET_PeerIdentity)); |
3718 | get_length = get_length + 1; | 3732 | get_length = get_length + 1; |
3719 | 3733 | ||
3720 | GDS_DATACACHE_handle_get (&(get->key),(get->block_type), NULL, 0, NULL, 0, | 3734 | GDS_DATACACHE_handle_get (&(get->key),(get->block_type), NULL, 0, NULL, 0, |
3721 | get_length, final_get_path, | 3735 | get_length, final_get_path, |
3722 | &final_get_path[get_length-2], &my_identity); | 3736 | &final_get_path[get_length-2], &my_identity); |
3723 | } | 3737 | } |
3724 | else | 3738 | else |
3725 | { | 3739 | { |
3726 | GDS_NEIGHBOURS_send_get (&(get->key), get->block_type, get->options, | 3740 | GDS_NEIGHBOURS_send_get (&(get->key), get->block_type, get->options, |
3727 | get->desired_replication_level, best_known_dest, | 3741 | get->desired_replication_level, best_known_dest, |
3728 | intermediate_trail_id, next_hop, 0, | 3742 | intermediate_trail_id, next_hop, 0, |
3729 | get_length, gp); | 3743 | get_length, gp); |
3730 | } | 3744 | } |
3731 | return GNUNET_YES; | 3745 | return GNUNET_YES; |
3732 | } | 3746 | } |
@@ -3753,7 +3767,7 @@ handle_dht_p2p_get_result (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3753 | unsigned int getlen; | 3767 | unsigned int getlen; |
3754 | unsigned int putlen; | 3768 | unsigned int putlen; |
3755 | int current_path_index; | 3769 | int current_path_index; |
3756 | 3770 | ||
3757 | msize = ntohs (message->size); | 3771 | msize = ntohs (message->size); |
3758 | if (msize < sizeof (struct PeerGetResultMessage)) | 3772 | if (msize < sizeof (struct PeerGetResultMessage)) |
3759 | { | 3773 | { |
@@ -3764,10 +3778,10 @@ handle_dht_p2p_get_result (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3764 | get_result = (const struct PeerGetResultMessage *)message; | 3778 | get_result = (const struct PeerGetResultMessage *)message; |
3765 | getlen = ntohl (get_result->get_path_length); | 3779 | getlen = ntohl (get_result->get_path_length); |
3766 | putlen = ntohl (get_result->put_path_length); | 3780 | putlen = ntohl (get_result->put_path_length); |
3767 | 3781 | ||
3768 | if ((msize < | 3782 | if ((msize < |
3769 | sizeof (struct PeerGetResultMessage) + | 3783 | sizeof (struct PeerGetResultMessage) + |
3770 | getlen * sizeof (struct GNUNET_PeerIdentity) + | 3784 | getlen * sizeof (struct GNUNET_PeerIdentity) + |
3771 | putlen * sizeof (struct GNUNET_PeerIdentity)) || | 3785 | putlen * sizeof (struct GNUNET_PeerIdentity)) || |
3772 | (getlen > | 3786 | (getlen > |
3773 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity) || | 3787 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity) || |
@@ -3777,16 +3791,16 @@ handle_dht_p2p_get_result (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3777 | GNUNET_break_op (0); | 3791 | GNUNET_break_op (0); |
3778 | return GNUNET_YES; | 3792 | return GNUNET_YES; |
3779 | } | 3793 | } |
3780 | 3794 | ||
3781 | put_path = (const struct GNUNET_PeerIdentity *) &get_result[1]; | 3795 | put_path = (const struct GNUNET_PeerIdentity *) &get_result[1]; |
3782 | get_path = &put_path[putlen]; | 3796 | get_path = &put_path[putlen]; |
3783 | payload = (const void *) &get_path[getlen]; | 3797 | payload = (const void *) &get_path[getlen]; |
3784 | payload_size = msize - (sizeof (struct PeerGetResultMessage) + | 3798 | payload_size = msize - (sizeof (struct PeerGetResultMessage) + |
3785 | (getlen + putlen) * sizeof (struct GNUNET_PeerIdentity)); | 3799 | (getlen + putlen) * sizeof (struct GNUNET_PeerIdentity)); |
3786 | 3800 | ||
3787 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &(get_path[0])))) | 3801 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &(get_path[0])))) |
3788 | { | 3802 | { |
3789 | GDS_CLIENTS_handle_reply (get_result->expiration_time, &(get_result->key), | 3803 | GDS_CLIENTS_handle_reply (get_result->expiration_time, &(get_result->key), |
3790 | getlen, get_path, putlen, | 3804 | getlen, get_path, putlen, |
3791 | put_path, get_result->type, payload_size, payload); | 3805 | put_path, get_result->type, payload_size, payload); |
3792 | return GNUNET_YES; | 3806 | return GNUNET_YES; |
@@ -3805,7 +3819,7 @@ handle_dht_p2p_get_result (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3805 | getlen, get_path, get_result->expiration_time, | 3819 | getlen, get_path, get_result->expiration_time, |
3806 | payload, payload_size); | 3820 | payload, payload_size); |
3807 | return GNUNET_YES; | 3821 | return GNUNET_YES; |
3808 | } | 3822 | } |
3809 | return GNUNET_SYSERR; | 3823 | return GNUNET_SYSERR; |
3810 | } | 3824 | } |
3811 | 3825 | ||
@@ -3816,16 +3830,16 @@ handle_dht_p2p_get_result (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3816 | * then get the next hop from routing table. Compare next_hop from routing table | 3830 | * then get the next hop from routing table. Compare next_hop from routing table |
3817 | * and local best known hop, and return the closest one to final_dest_finger_val | 3831 | * and local best known hop, and return the closest one to final_dest_finger_val |
3818 | * @param final_dest_finger_val 64 bit value of finger identity | 3832 | * @param final_dest_finger_val 64 bit value of finger identity |
3819 | * @param intermediate_trail_id If you are part of trail to reach to some other | 3833 | * @param intermediate_trail_id If you are part of trail to reach to some other |
3820 | * finger, then it is the trail id to reach to | 3834 | * finger, then it is the trail id to reach to |
3821 | * that finger, else set to 0. | 3835 | * that finger, else set to 0. |
3822 | * @param is_predecessor Are we looking for closest successor or predecessor. | 3836 | * @param is_predecessor Are we looking for closest successor or predecessor. |
3823 | * @param current_dest In case you are part of trail, then finger to which | 3837 | * @param current_dest In case you are part of trail, then finger to which |
3824 | * we should forward the message. Else my own identity | 3838 | * we should forward the message. Else my own identity |
3825 | * @return Closest Peer for @a final_dest_finger_val | 3839 | * @return Closest Peer for @a final_dest_finger_val |
3826 | */ | 3840 | */ |
3827 | static struct Closest_Peer | 3841 | static struct Closest_Peer |
3828 | get_local_best_known_next_hop (uint64_t final_dest_finger_val, | 3842 | get_local_best_known_next_hop (uint64_t final_dest_finger_val, |
3829 | struct GNUNET_HashCode intermediate_trail_id, | 3843 | struct GNUNET_HashCode intermediate_trail_id, |
3830 | unsigned int is_predecessor, | 3844 | unsigned int is_predecessor, |
3831 | struct GNUNET_PeerIdentity prev_hop, | 3845 | struct GNUNET_PeerIdentity prev_hop, |
@@ -3833,48 +3847,42 @@ get_local_best_known_next_hop (uint64_t final_dest_finger_val, | |||
3833 | struct GNUNET_PeerIdentity *current_dest) | 3847 | struct GNUNET_PeerIdentity *current_dest) |
3834 | { | 3848 | { |
3835 | struct Closest_Peer peer; | 3849 | struct Closest_Peer peer; |
3836 | 3850 | ||
3837 | /* Find a local best known peer. */ | 3851 | /* Find a local best known peer. */ |
3838 | peer = find_successor (final_dest_finger_val, is_predecessor);//FIXME: chnage to better name | 3852 | peer = find_successor (final_dest_finger_val, is_predecessor);//FIXME: chnage to better name |
3839 | 3853 | ||
3840 | /* Am I just a part of a trail towards a finger (current_destination)? */ | 3854 | /* Am I just a part of a trail towards a finger (current_destination)? */ |
3841 | if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&my_identity, current_dest))) | 3855 | /* Select best successor among one found locally and current_destination |
3842 | { | 3856 | * that we got from network.*/ |
3843 | /* Select best successor among one found locally and current_destination | 3857 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, current_dest) && |
3844 | * that we got from network.*/ | 3858 | 0 != GNUNET_CRYPTO_cmp_peer_identity (&peer.best_known_destination, |
3845 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&peer.best_known_destination, | 3859 | current_dest)) |
3846 | current_dest)) | 3860 | { |
3847 | { | 3861 | const struct GNUNET_PeerIdentity *closest_peer; |
3848 | struct GNUNET_PeerIdentity *closest_peer; | 3862 | |
3849 | struct GNUNET_PeerIdentity *local_best_known_dest; | 3863 | closest_peer = select_closest_peer (&peer.best_known_destination, |
3850 | local_best_known_dest = GNUNET_new(struct GNUNET_PeerIdentity); | 3864 | current_dest, |
3851 | memcpy(local_best_known_dest, &peer.best_known_destination, sizeof(struct GNUNET_PeerIdentity)); | 3865 | final_dest_finger_val, |
3852 | 3866 | is_predecessor); | |
3853 | closest_peer = select_closest_peer (local_best_known_dest, | 3867 | |
3854 | current_dest, | 3868 | /* Is current dest (end point of the trail of which I am a part) closest_peer? */ |
3855 | final_dest_finger_val, | 3869 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (current_dest, closest_peer)) |
3856 | is_predecessor); | 3870 | { |
3857 | 3871 | struct GNUNET_PeerIdentity *next_hop; | |
3858 | GNUNET_free(local_best_known_dest); | 3872 | next_hop = GDS_ROUTING_get_next_hop (intermediate_trail_id, |
3859 | /* Is current dest (end point of the trail of which I am a part) closest_peer? */ | 3873 | GDS_ROUTING_SRC_TO_DEST); |
3860 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (current_dest, closest_peer)) | 3874 | GNUNET_assert (NULL != next_hop); |
3861 | { | 3875 | |
3862 | struct GNUNET_PeerIdentity *next_hop; | 3876 | peer.next_hop = *next_hop; |
3863 | next_hop = GDS_ROUTING_get_next_hop (intermediate_trail_id, | 3877 | peer.best_known_destination = *current_dest; |
3864 | GDS_ROUTING_SRC_TO_DEST); | 3878 | peer.trail_id = intermediate_trail_id; |
3865 | GNUNET_assert (NULL != next_hop); | 3879 | } |
3866 | |||
3867 | peer.next_hop = *next_hop; | ||
3868 | peer.best_known_destination = *current_dest; | ||
3869 | peer.trail_id = intermediate_trail_id; | ||
3870 | } | ||
3871 | } | ||
3872 | } | 3880 | } |
3873 | return peer; | 3881 | return peer; |
3874 | } | 3882 | } |
3875 | 3883 | ||
3876 | 3884 | ||
3877 | /* | 3885 | /* |
3878 | * Core handle for PeerTrailSetupMessage. | 3886 | * Core handle for PeerTrailSetupMessage. |
3879 | * @param cls closure | 3887 | * @param cls closure |
3880 | * @param message message | 3888 | * @param message message |
@@ -3907,33 +3915,52 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3907 | trail_setup = (const struct PeerTrailSetupMessage *) message; | 3915 | trail_setup = (const struct PeerTrailSetupMessage *) message; |
3908 | trail_length = (msize - sizeof (struct PeerTrailSetupMessage))/ | 3916 | trail_length = (msize - sizeof (struct PeerTrailSetupMessage))/ |
3909 | sizeof (struct GNUNET_PeerIdentity); | 3917 | sizeof (struct GNUNET_PeerIdentity); |
3910 | if ((msize - sizeof (struct PeerTrailSetupMessage)) % | 3918 | if ((msize - sizeof (struct PeerTrailSetupMessage)) % |
3911 | sizeof (struct GNUNET_PeerIdentity) != 0) | 3919 | sizeof (struct GNUNET_PeerIdentity) != 0) |
3912 | { | 3920 | { |
3913 | GNUNET_break_op (0); | 3921 | GNUNET_break_op (0); |
3914 | return GNUNET_OK; | 3922 | return GNUNET_OK; |
3915 | } | 3923 | } |
3916 | 3924 | ||
3917 | trail_peer_list = (const struct GNUNET_PeerIdentity *)&trail_setup[1]; | 3925 | trail_peer_list = (const struct GNUNET_PeerIdentity *)&trail_setup[1]; |
3918 | current_dest = trail_setup->best_known_destination; | 3926 | current_dest = trail_setup->best_known_destination; |
3919 | trail_id = trail_setup->trail_id; | 3927 | trail_id = trail_setup->trail_id; |
3920 | final_dest_finger_val = | 3928 | final_dest_finger_val = |
3921 | GNUNET_ntohll (trail_setup->final_destination_finger_value); | 3929 | GNUNET_ntohll (trail_setup->final_destination_finger_value); |
3922 | source = trail_setup->source_peer; | 3930 | source = trail_setup->source_peer; |
3923 | is_predecessor = ntohl (trail_setup->is_predecessor); | 3931 | is_predecessor = ntohl (trail_setup->is_predecessor); |
3924 | intermediate_trail_id = trail_setup->intermediate_trail_id; | 3932 | intermediate_trail_id = trail_setup->intermediate_trail_id; |
3925 | 3933 | ||
3926 | /* If I was the source and got the message back, then set trail length to 0.*/ | 3934 | /* If I was the source and got the message back, then set trail length to 0.*/ |
3927 | if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity, &source)) | 3935 | if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity, &source)) |
3928 | { | 3936 | { |
3929 | trail_length = 0; | 3937 | /* IF (!) the peers know the destinations of the trails in their routing |
3938 | * table, then: | ||
3939 | * | ||
3940 | * This shoud only happen after 1 hop, since the first message is sent | ||
3941 | * to random friend, and we can happen to be on the best trail to the dest. | ||
3942 | * If the first friend selects someone else, the request should never come | ||
3943 | * back to us. | ||
3944 | * | ||
3945 | * (TODO) | ||
3946 | */ | ||
3947 | // GNUNET_break_op (1 == trail_length); | ||
3948 | trail_length = 0; | ||
3949 | } | ||
3950 | |||
3951 | /* Did the friend insert its ID in the trail list? */ | ||
3952 | if (trail_length > 0 && | ||
3953 | 0 != memcmp (&trail_peer_list[trail_length-1], peer, sizeof (*peer))) | ||
3954 | { | ||
3955 | GNUNET_break_op (0); | ||
3956 | return GNUNET_SYSERR; | ||
3930 | } | 3957 | } |
3931 | 3958 | ||
3932 | /* Is my routing table full? */ | 3959 | /* Is my routing table full? */ |
3933 | if (GNUNET_YES == GDS_ROUTING_threshold_reached()) | 3960 | if (GNUNET_YES == GDS_ROUTING_threshold_reached()) |
3934 | { | 3961 | { |
3935 | GNUNET_assert (NULL != | 3962 | GNUNET_assert (NULL != |
3936 | (target_friend = | 3963 | (target_friend = |
3937 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer))); | 3964 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer))); |
3938 | GDS_NEIGHBOURS_send_trail_rejection (source, final_dest_finger_val, | 3965 | GDS_NEIGHBOURS_send_trail_rejection (source, final_dest_finger_val, |
3939 | my_identity, is_predecessor, | 3966 | my_identity, is_predecessor, |
@@ -3942,70 +3969,66 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3942 | CONGESTION_TIMEOUT); | 3969 | CONGESTION_TIMEOUT); |
3943 | return GNUNET_OK; | 3970 | return GNUNET_OK; |
3944 | } | 3971 | } |
3945 | 3972 | ||
3946 | /* Get the next hop to forward the trail setup request. */ | 3973 | /* Get the next hop to forward the trail setup request. */ |
3947 | struct Closest_Peer next_peer = | 3974 | struct Closest_Peer next_peer = |
3948 | get_local_best_known_next_hop (final_dest_finger_val, | 3975 | get_local_best_known_next_hop (final_dest_finger_val, |
3949 | intermediate_trail_id, | 3976 | intermediate_trail_id, |
3950 | is_predecessor, | 3977 | is_predecessor, |
3951 | *peer, | 3978 | *peer, |
3952 | source, | 3979 | source, |
3953 | ¤t_dest); | 3980 | ¤t_dest); |
3954 | 3981 | ||
3955 | /* Am I the final destination? */ | 3982 | /* Am I the final destination? */ |
3956 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&next_peer.best_known_destination, | 3983 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&next_peer.best_known_destination, |
3957 | &my_identity))) | 3984 | &my_identity))) |
3958 | { | 3985 | { |
3959 | // | ||
3960 | /* If I was not the source of this message for which now I am destination */ | 3986 | /* If I was not the source of this message for which now I am destination */ |
3961 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&source, &my_identity)) | 3987 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&source, &my_identity)) |
3962 | { | 3988 | { |
3963 | GDS_ROUTING_add (trail_id, *peer, my_identity); | 3989 | GDS_ROUTING_add (trail_id, *peer, my_identity); |
3964 | } | 3990 | } |
3965 | 3991 | ||
3966 | if(trail_length > 0) | 3992 | if(0 == GNUNET_CRYPTO_cmp_peer_identity (&source, &my_identity)) |
3967 | { | 3993 | { |
3968 | GNUNET_assert (NULL != | 3994 | finger_table_add (my_identity, NULL, 0, is_predecessor, |
3969 | (target_friend = | 3995 | final_dest_finger_val, trail_id); |
3970 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 3996 | return GNUNET_OK; |
3971 | &trail_peer_list[trail_length-1]))); | ||
3972 | } | 3997 | } |
3998 | |||
3999 | if (trail_length > 0) | ||
4000 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer); | ||
3973 | else | 4001 | else |
4002 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &source); | ||
4003 | if (NULL != target_friend) | ||
3974 | { | 4004 | { |
3975 | if(0 == GNUNET_CRYPTO_cmp_peer_identity (&source, &my_identity)) | 4005 | GNUNET_break_op (0); |
3976 | { | 4006 | return GNUNET_SYSERR; |
3977 | finger_table_add (my_identity, NULL, 0, is_predecessor, | ||
3978 | final_dest_finger_val, trail_id); | ||
3979 | return GNUNET_OK; | ||
3980 | } | ||
3981 | GNUNET_assert (NULL != | ||
3982 | (target_friend = | ||
3983 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, &source))); | ||
3984 | } | 4007 | } |
3985 | 4008 | ||
3986 | GDS_NEIGHBOURS_send_trail_setup_result (source, | 4009 | GDS_NEIGHBOURS_send_trail_setup_result (source, |
3987 | my_identity, | 4010 | my_identity, |
3988 | target_friend, trail_length, | 4011 | target_friend, trail_length, |
3989 | trail_peer_list, | 4012 | trail_peer_list, |
3990 | is_predecessor, | 4013 | is_predecessor, |
3991 | final_dest_finger_val,trail_id); | 4014 | final_dest_finger_val,trail_id); |
3992 | } | 4015 | } |
3993 | else | 4016 | else /* I'm not the final destination. */ |
3994 | { | 4017 | { |
3995 | GNUNET_assert (NULL != | 4018 | GNUNET_assert (NULL != |
3996 | (target_friend = | 4019 | (target_friend = |
3997 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 4020 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
3998 | &next_peer.next_hop))); | 4021 | &next_peer.next_hop))); |
3999 | 4022 | ||
4000 | if (0 != GNUNET_CRYPTO_cmp_peer_identity(&my_identity, &source)) | 4023 | if (0 != GNUNET_CRYPTO_cmp_peer_identity(&my_identity, &source)) |
4001 | { | 4024 | { |
4002 | /* Add yourself to list of peers. */ | 4025 | /* Add yourself to list of peers. */ |
4003 | struct GNUNET_PeerIdentity peer_list[trail_length + 1]; | 4026 | struct GNUNET_PeerIdentity peer_list[trail_length + 1]; |
4004 | 4027 | ||
4005 | memcpy (peer_list, trail_peer_list, | 4028 | memcpy (peer_list, trail_peer_list, |
4006 | trail_length * sizeof (struct GNUNET_PeerIdentity)); | 4029 | trail_length * sizeof (struct GNUNET_PeerIdentity)); |
4007 | peer_list[trail_length] = my_identity; | 4030 | peer_list[trail_length] = my_identity; |
4008 | 4031 | ||
4009 | GDS_NEIGHBOURS_send_trail_setup (source, | 4032 | GDS_NEIGHBOURS_send_trail_setup (source, |
4010 | final_dest_finger_val, | 4033 | final_dest_finger_val, |
4011 | next_peer.best_known_destination, | 4034 | next_peer.best_known_destination, |
@@ -4030,17 +4053,17 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
4030 | /** | 4053 | /** |
4031 | * FIXME: Should we call this function everywhere in all the handle functions | 4054 | * FIXME: Should we call this function everywhere in all the handle functions |
4032 | * where we have a trail to verify from or a trail id. something like | 4055 | * where we have a trail to verify from or a trail id. something like |
4033 | * if prev hop is not same then drop the message. | 4056 | * if prev hop is not same then drop the message. |
4034 | * Check if sender_peer and peer from which we should receive the message are | 4057 | * Check if sender_peer and peer from which we should receive the message are |
4035 | * same or different. | 4058 | * same or different. |
4036 | * @param trail_peer_list List of peers in trail | 4059 | * @param trail_peer_list List of peers in trail |
4037 | * @param trail_length Total number of peers in @a trail_peer_list | 4060 | * @param trail_length Total number of peers in @a trail_peer_list |
4038 | * @param sender_peer Peer from which we got the message. | 4061 | * @param sender_peer Peer from which we got the message. |
4039 | * @param finger_identity Finger to which trail is setup. It is not part of trail. | 4062 | * @param finger_identity Finger to which trail is setup. It is not part of trail. |
4040 | * @return #GNUNET_YES if sender_peer and peer from which we should receive the | 4063 | * @return #GNUNET_YES if sender_peer and peer from which we should receive the |
4041 | * message are different. | 4064 | * message are different. |
4042 | * #GNUNET_NO if sender_peer and peer from which we should receive the | 4065 | * #GNUNET_NO if sender_peer and peer from which we should receive the |
4043 | * message are different. | 4066 | * message are different. |
4044 | */ | 4067 | */ |
4045 | static int | 4068 | static int |
4046 | is_sender_peer_correct (const struct GNUNET_PeerIdentity *trail_peer_list, | 4069 | is_sender_peer_correct (const struct GNUNET_PeerIdentity *trail_peer_list, |
@@ -4050,7 +4073,7 @@ is_sender_peer_correct (const struct GNUNET_PeerIdentity *trail_peer_list, | |||
4050 | struct GNUNET_PeerIdentity source_peer) | 4073 | struct GNUNET_PeerIdentity source_peer) |
4051 | { | 4074 | { |
4052 | int my_index; | 4075 | int my_index; |
4053 | 4076 | ||
4054 | /* I am the source peer. */ | 4077 | /* I am the source peer. */ |
4055 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&source_peer, | 4078 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&source_peer, |
4056 | &my_identity))) | 4079 | &my_identity))) |
@@ -4076,7 +4099,7 @@ is_sender_peer_correct (const struct GNUNET_PeerIdentity *trail_peer_list, | |||
4076 | my_index = search_my_index (trail_peer_list, trail_length); | 4099 | my_index = search_my_index (trail_peer_list, trail_length); |
4077 | if (-1 == my_index) | 4100 | if (-1 == my_index) |
4078 | return GNUNET_NO; | 4101 | return GNUNET_NO; |
4079 | 4102 | ||
4080 | /* I am the last element in the trail. */ | 4103 | /* I am the last element in the trail. */ |
4081 | if ((trail_length - 1) == my_index) | 4104 | if ((trail_length - 1) == my_index) |
4082 | { | 4105 | { |
@@ -4104,7 +4127,7 @@ is_sender_peer_correct (const struct GNUNET_PeerIdentity *trail_peer_list, | |||
4104 | * Core handle for p2p trail setup result messages. | 4127 | * Core handle for p2p trail setup result messages. |
4105 | * @param closure | 4128 | * @param closure |
4106 | * @param message message | 4129 | * @param message message |
4107 | * @param peer sender of this message. | 4130 | * @param peer sender of this message. |
4108 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 4131 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
4109 | */ | 4132 | */ |
4110 | static int | 4133 | static int |
@@ -4134,19 +4157,19 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p | |||
4134 | trail_result = (const struct PeerTrailSetupResultMessage *) message; | 4157 | trail_result = (const struct PeerTrailSetupResultMessage *) message; |
4135 | trail_length = (msize - sizeof (struct PeerTrailSetupResultMessage))/ | 4158 | trail_length = (msize - sizeof (struct PeerTrailSetupResultMessage))/ |
4136 | sizeof (struct GNUNET_PeerIdentity); | 4159 | sizeof (struct GNUNET_PeerIdentity); |
4137 | if ((msize - sizeof (struct PeerTrailSetupResultMessage)) % | 4160 | if ((msize - sizeof (struct PeerTrailSetupResultMessage)) % |
4138 | sizeof (struct GNUNET_PeerIdentity) != 0) | 4161 | sizeof (struct GNUNET_PeerIdentity) != 0) |
4139 | { | 4162 | { |
4140 | GNUNET_break_op (0); | 4163 | GNUNET_break_op (0); |
4141 | return GNUNET_OK; | 4164 | return GNUNET_OK; |
4142 | } | 4165 | } |
4143 | 4166 | ||
4144 | is_predecessor = ntohl (trail_result->is_predecessor); | 4167 | is_predecessor = ntohl (trail_result->is_predecessor); |
4145 | querying_peer = trail_result->querying_peer; | 4168 | querying_peer = trail_result->querying_peer; |
4146 | finger_identity = trail_result->finger_identity; | 4169 | finger_identity = trail_result->finger_identity; |
4147 | trail_id = trail_result->trail_id; | 4170 | trail_id = trail_result->trail_id; |
4148 | trail_peer_list = (const struct GNUNET_PeerIdentity *) &trail_result[1]; | 4171 | trail_peer_list = (const struct GNUNET_PeerIdentity *) &trail_result[1]; |
4149 | ulitmate_destination_finger_value = | 4172 | ulitmate_destination_finger_value = |
4150 | GNUNET_ntohll (trail_result->ulitmate_destination_finger_value); | 4173 | GNUNET_ntohll (trail_result->ulitmate_destination_finger_value); |
4151 | 4174 | ||
4152 | /* FIXME: here we are calculating my_index and comparing also in this function. | 4175 | /* FIXME: here we are calculating my_index and comparing also in this function. |
@@ -4161,21 +4184,22 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p | |||
4161 | return GNUNET_SYSERR; | 4184 | return GNUNET_SYSERR; |
4162 | } | 4185 | } |
4163 | #endif | 4186 | #endif |
4164 | 4187 | ||
4165 | /* Am I the one who initiated the query? */ | 4188 | /* Am I the one who initiated the query? */ |
4166 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&querying_peer, &my_identity))) | 4189 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&querying_peer, &my_identity))) |
4167 | { | 4190 | { |
4168 | /* If I am not my own finger identity, then add routing table entry. */ | 4191 | /* If I am my own finger identity, error. */ |
4169 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &finger_identity)) | 4192 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &finger_identity)) |
4170 | { | 4193 | { |
4171 | GDS_ROUTING_add (trail_id, my_identity, *peer); | 4194 | GNUNET_break_op (0); |
4195 | return GNUNET_SYSERR; | ||
4172 | } | 4196 | } |
4173 | 4197 | GDS_ROUTING_add (trail_id, my_identity, *peer); | |
4174 | finger_table_add (finger_identity, trail_peer_list, trail_length, | 4198 | finger_table_add (finger_identity, trail_peer_list, trail_length, |
4175 | is_predecessor, ulitmate_destination_finger_value, trail_id); | 4199 | is_predecessor, ulitmate_destination_finger_value, trail_id); |
4176 | return GNUNET_YES; | 4200 | return GNUNET_YES; |
4177 | } | 4201 | } |
4178 | 4202 | ||
4179 | /* Get my location in the trail. */ | 4203 | /* Get my location in the trail. */ |
4180 | my_index = search_my_index (trail_peer_list, trail_length); | 4204 | my_index = search_my_index (trail_peer_list, trail_length); |
4181 | if (-1 == my_index) | 4205 | if (-1 == my_index) |
@@ -4183,24 +4207,31 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p | |||
4183 | GNUNET_break_op(0); | 4207 | GNUNET_break_op(0); |
4184 | return GNUNET_SYSERR; | 4208 | return GNUNET_SYSERR; |
4185 | } | 4209 | } |
4186 | 4210 | ||
4187 | if (my_index == 0) | 4211 | if (my_index == 0) |
4188 | next_hop = trail_result->querying_peer; | 4212 | next_hop = trail_result->querying_peer; |
4189 | else | 4213 | else |
4190 | next_hop = trail_peer_list[my_index - 1]; | 4214 | next_hop = trail_peer_list[my_index - 1]; |
4191 | 4215 | ||
4192 | if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&(trail_result->querying_peer), | 4216 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop); |
4217 | if (NULL == target_friend) | ||
4218 | { | ||
4219 | GNUNET_break_op (0); | ||
4220 | return GNUNET_SYSERR; | ||
4221 | } | ||
4222 | |||
4223 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&(trail_result->querying_peer), | ||
4193 | &(trail_result->finger_identity)))) | 4224 | &(trail_result->finger_identity)))) |
4194 | { | 4225 | { |
4195 | GDS_ROUTING_add (trail_id, next_hop, *peer); | 4226 | GNUNET_break_op (0); |
4227 | return GNUNET_SYSERR; | ||
4196 | } | 4228 | } |
4197 | 4229 | ||
4198 | GNUNET_assert (NULL != | 4230 | GDS_ROUTING_add (trail_id, next_hop, *peer); |
4199 | (target_friend = | 4231 | |
4200 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop))); | ||
4201 | GDS_NEIGHBOURS_send_trail_setup_result (querying_peer, finger_identity, | 4232 | GDS_NEIGHBOURS_send_trail_setup_result (querying_peer, finger_identity, |
4202 | target_friend, trail_length, trail_peer_list, | 4233 | target_friend, trail_length, trail_peer_list, |
4203 | is_predecessor, | 4234 | is_predecessor, |
4204 | ulitmate_destination_finger_value, | 4235 | ulitmate_destination_finger_value, |
4205 | trail_id); | 4236 | trail_id); |
4206 | return GNUNET_OK; | 4237 | return GNUNET_OK; |
@@ -4231,7 +4262,7 @@ invert_trail (const struct GNUNET_PeerIdentity *trail, | |||
4231 | i++; | 4262 | i++; |
4232 | j--; | 4263 | j--; |
4233 | } | 4264 | } |
4234 | 4265 | ||
4235 | GNUNET_assert(NULL != GNUNET_CONTAINER_multipeermap_get(friend_peermap, | 4266 | GNUNET_assert(NULL != GNUNET_CONTAINER_multipeermap_get(friend_peermap, |
4236 | &inverted_trail[0])); | 4267 | &inverted_trail[0])); |
4237 | return inverted_trail; | 4268 | return inverted_trail; |
@@ -4240,10 +4271,10 @@ invert_trail (const struct GNUNET_PeerIdentity *trail, | |||
4240 | 4271 | ||
4241 | /** | 4272 | /** |
4242 | * Return the shortest trail among all the trails to reach to finger from me. | 4273 | * Return the shortest trail among all the trails to reach to finger from me. |
4243 | * @param finger Finger | 4274 | * @param finger Finger |
4244 | * @param shortest_trail_length[out] Trail length of shortest trail from me | 4275 | * @param shortest_trail_length[out] Trail length of shortest trail from me |
4245 | * to @a finger | 4276 | * to @a finger |
4246 | * @return Shortest trail. | 4277 | * @return Shortest trail. |
4247 | */ | 4278 | */ |
4248 | static struct GNUNET_PeerIdentity * | 4279 | static struct GNUNET_PeerIdentity * |
4249 | get_shortest_trail (struct FingerInfo *finger, | 4280 | get_shortest_trail (struct FingerInfo *finger, |
@@ -4256,22 +4287,22 @@ get_shortest_trail (struct FingerInfo *finger, | |||
4256 | struct Trail_Element *trail_element; | 4287 | struct Trail_Element *trail_element; |
4257 | struct GNUNET_PeerIdentity *trail_list; | 4288 | struct GNUNET_PeerIdentity *trail_list; |
4258 | unsigned int i; | 4289 | unsigned int i; |
4259 | 4290 | ||
4260 | trail = GNUNET_new (struct Trail); | 4291 | trail = GNUNET_new (struct Trail); |
4261 | 4292 | ||
4262 | /* Get the shortest trail to reach to current successor. */ | 4293 | /* Get the shortest trail to reach to current successor. */ |
4263 | for (i = 0; i < finger->trails_count; i++) | 4294 | for (i = 0; i < finger->trails_count; i++) |
4264 | { | 4295 | { |
4265 | trail = &finger->trail_list[i]; | 4296 | trail = &finger->trail_list[i]; |
4266 | 4297 | ||
4267 | if (0 == flag) | 4298 | if (0 == flag) |
4268 | { | 4299 | { |
4269 | shortest_trail_index = i; | 4300 | shortest_trail_index = i; |
4270 | shortest_trail_length = trail->trail_length; | 4301 | shortest_trail_length = trail->trail_length; |
4271 | flag = 1; | 4302 | flag = 1; |
4272 | continue; | 4303 | continue; |
4273 | } | 4304 | } |
4274 | 4305 | ||
4275 | if (shortest_trail_length > trail->trail_length) | 4306 | if (shortest_trail_length > trail->trail_length) |
4276 | { | 4307 | { |
4277 | shortest_trail_index = i; | 4308 | shortest_trail_index = i; |
@@ -4279,20 +4310,20 @@ get_shortest_trail (struct FingerInfo *finger, | |||
4279 | } | 4310 | } |
4280 | continue; | 4311 | continue; |
4281 | } | 4312 | } |
4282 | 4313 | ||
4283 | /* Copy the shortest trail and return. */ | 4314 | /* Copy the shortest trail and return. */ |
4284 | trail = &finger->trail_list[shortest_trail_index]; | 4315 | trail = &finger->trail_list[shortest_trail_index]; |
4285 | trail_element = trail->trail_head; | 4316 | trail_element = trail->trail_head; |
4286 | trail_list = GNUNET_malloc (sizeof(struct GNUNET_PeerIdentity)* | 4317 | trail_list = GNUNET_malloc (sizeof(struct GNUNET_PeerIdentity)* |
4287 | shortest_trail_length); | 4318 | shortest_trail_length); |
4288 | 4319 | ||
4289 | for(i = 0; i < shortest_trail_length; i++,trail_element = trail_element->next) | 4320 | for(i = 0; i < shortest_trail_length; i++,trail_element = trail_element->next) |
4290 | { | 4321 | { |
4291 | trail_list[i] = trail_element->peer; | 4322 | trail_list[i] = trail_element->peer; |
4292 | } | 4323 | } |
4293 | 4324 | ||
4294 | GNUNET_assert(shortest_trail_length != -1); | 4325 | GNUNET_assert(shortest_trail_length != -1); |
4295 | 4326 | ||
4296 | *trail_length = shortest_trail_length; | 4327 | *trail_length = shortest_trail_length; |
4297 | return trail_list; | 4328 | return trail_list; |
4298 | } | 4329 | } |
@@ -4300,13 +4331,13 @@ get_shortest_trail (struct FingerInfo *finger, | |||
4300 | 4331 | ||
4301 | /** | 4332 | /** |
4302 | * Return the trail from source to my current predecessor. Check if source | 4333 | * Return the trail from source to my current predecessor. Check if source |
4303 | * is already part of the this trail, if yes then return the shorten trail. | 4334 | * is already part of the this trail, if yes then return the shorten trail. |
4304 | * @param current_trail Trail from source to me, NOT including the endpoints. | 4335 | * @param current_trail Trail from source to me, NOT including the endpoints. |
4305 | * @param current_trail_length Number of peers in @a current_trail. | 4336 | * @param current_trail_length Number of peers in @a current_trail. |
4306 | * @param trail_src_to_curr_pred_length[out] Number of peers in trail from | 4337 | * @param trail_src_to_curr_pred_length[out] Number of peers in trail from |
4307 | * source to my predecessor, NOT including | 4338 | * source to my predecessor, NOT including |
4308 | * the endpoints. | 4339 | * the endpoints. |
4309 | * @return Trail from source to my predecessor. | 4340 | * @return Trail from source to my predecessor. |
4310 | */ | 4341 | */ |
4311 | static struct GNUNET_PeerIdentity * | 4342 | static struct GNUNET_PeerIdentity * |
4312 | get_trail_src_to_curr_pred (struct GNUNET_PeerIdentity source_peer, | 4343 | get_trail_src_to_curr_pred (struct GNUNET_PeerIdentity source_peer, |
@@ -4320,11 +4351,11 @@ get_trail_src_to_curr_pred (struct GNUNET_PeerIdentity source_peer, | |||
4320 | struct FingerInfo *current_predecessor; | 4351 | struct FingerInfo *current_predecessor; |
4321 | unsigned int i; | 4352 | unsigned int i; |
4322 | unsigned int j; | 4353 | unsigned int j; |
4323 | 4354 | ||
4324 | current_predecessor = &finger_table[PREDECESSOR_FINGER_ID]; | 4355 | current_predecessor = &finger_table[PREDECESSOR_FINGER_ID]; |
4325 | trail_me_to_curr_pred = get_shortest_trail (current_predecessor, | 4356 | trail_me_to_curr_pred = get_shortest_trail (current_predecessor, |
4326 | &trail_me_to_curr_pred_length); | 4357 | &trail_me_to_curr_pred_length); |
4327 | 4358 | ||
4328 | /* Check if trail_me_to_curr_pred contains source. */ | 4359 | /* Check if trail_me_to_curr_pred contains source. */ |
4329 | if (trail_me_to_curr_pred_length > 0) | 4360 | if (trail_me_to_curr_pred_length > 0) |
4330 | { | 4361 | { |
@@ -4333,17 +4364,17 @@ get_trail_src_to_curr_pred (struct GNUNET_PeerIdentity source_peer, | |||
4333 | if(0 != GNUNET_CRYPTO_cmp_peer_identity (&source_peer, | 4364 | if(0 != GNUNET_CRYPTO_cmp_peer_identity (&source_peer, |
4334 | &trail_me_to_curr_pred[i])) | 4365 | &trail_me_to_curr_pred[i])) |
4335 | continue; | 4366 | continue; |
4336 | 4367 | ||
4337 | i = i+1; | 4368 | i = i+1; |
4338 | 4369 | ||
4339 | /* Source is the last element in the trail to reach to my pred. | 4370 | /* Source is the last element in the trail to reach to my pred. |
4340 | Source is direct friend of the pred. */ | 4371 | Source is direct friend of the pred. */ |
4341 | if (trail_me_to_curr_pred_length == i) | 4372 | if (trail_me_to_curr_pred_length == i) |
4342 | { | 4373 | { |
4343 | *trail_src_to_curr_pred_length = 0; | 4374 | *trail_src_to_curr_pred_length = 0; |
4344 | return NULL; | 4375 | return NULL; |
4345 | } | 4376 | } |
4346 | 4377 | ||
4347 | *trail_src_to_curr_pred_length = trail_me_to_curr_pred_length - i; | 4378 | *trail_src_to_curr_pred_length = trail_me_to_curr_pred_length - i; |
4348 | trail_src_to_curr_pred = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)* | 4379 | trail_src_to_curr_pred = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)* |
4349 | *trail_src_to_curr_pred_length); | 4380 | *trail_src_to_curr_pred_length); |
@@ -4351,60 +4382,60 @@ get_trail_src_to_curr_pred (struct GNUNET_PeerIdentity source_peer, | |||
4351 | { | 4382 | { |
4352 | trail_src_to_curr_pred[j] = trail_me_to_curr_pred[i]; | 4383 | trail_src_to_curr_pred[j] = trail_me_to_curr_pred[i]; |
4353 | } | 4384 | } |
4354 | 4385 | ||
4355 | return trail_src_to_curr_pred; | 4386 | return trail_src_to_curr_pred; |
4356 | } | 4387 | } |
4357 | } | 4388 | } |
4358 | 4389 | ||
4359 | /* Append trail from source to me to my current_predecessor. */ | 4390 | /* Append trail from source to me to my current_predecessor. */ |
4360 | *trail_src_to_curr_pred_length = trail_src_to_me_len + | 4391 | *trail_src_to_curr_pred_length = trail_src_to_me_len + |
4361 | trail_me_to_curr_pred_length + 1; | 4392 | trail_me_to_curr_pred_length + 1; |
4362 | 4393 | ||
4363 | trail_src_to_curr_pred = GNUNET_malloc (sizeof(struct GNUNET_PeerIdentity)* | 4394 | trail_src_to_curr_pred = GNUNET_malloc (sizeof(struct GNUNET_PeerIdentity)* |
4364 | *trail_src_to_curr_pred_length); | 4395 | *trail_src_to_curr_pred_length); |
4365 | 4396 | ||
4366 | for (i = 0; i < trail_src_to_me_len; i++) | 4397 | for (i = 0; i < trail_src_to_me_len; i++) |
4367 | trail_src_to_curr_pred[i] = trail_src_to_me[i]; | 4398 | trail_src_to_curr_pred[i] = trail_src_to_me[i]; |
4368 | 4399 | ||
4369 | trail_src_to_curr_pred[i] = my_identity; | 4400 | trail_src_to_curr_pred[i] = my_identity; |
4370 | i++; | 4401 | i++; |
4371 | 4402 | ||
4372 | for (j = 0; i < *trail_src_to_curr_pred_length; i++,j++) | 4403 | for (j = 0; i < *trail_src_to_curr_pred_length; i++,j++) |
4373 | trail_src_to_curr_pred[i] = trail_me_to_curr_pred[j]; | 4404 | trail_src_to_curr_pred[i] = trail_me_to_curr_pred[j]; |
4374 | 4405 | ||
4375 | return trail_src_to_curr_pred; | 4406 | return trail_src_to_curr_pred; |
4376 | } | 4407 | } |
4377 | 4408 | ||
4378 | 4409 | ||
4379 | /** | 4410 | /** |
4380 | * Add finger as your predecessor. To add, first generate a new trail id, invert | 4411 | * Add finger as your predecessor. To add, first generate a new trail id, invert |
4381 | * the trail to get the trail from me to finger, add an entry in your routing | 4412 | * the trail to get the trail from me to finger, add an entry in your routing |
4382 | * table, send add trail message to peers which are part of trail from me to | 4413 | * table, send add trail message to peers which are part of trail from me to |
4383 | * finger and add finger in finger table. | 4414 | * finger and add finger in finger table. |
4384 | * @param finger | 4415 | * @param finger |
4385 | * @param trail | 4416 | * @param trail |
4386 | * @param trail_length | 4417 | * @param trail_length |
4387 | */ | 4418 | */ |
4388 | static void | 4419 | static void |
4389 | update_predecessor (struct GNUNET_PeerIdentity finger, | 4420 | update_predecessor (struct GNUNET_PeerIdentity finger, |
4390 | struct GNUNET_PeerIdentity *trail, | 4421 | struct GNUNET_PeerIdentity *trail, |
4391 | unsigned int trail_length) | 4422 | unsigned int trail_length) |
4392 | { | 4423 | { |
4393 | struct GNUNET_HashCode trail_to_new_predecessor_id; | 4424 | struct GNUNET_HashCode trail_to_new_predecessor_id; |
4394 | struct GNUNET_PeerIdentity *trail_to_new_predecessor; | 4425 | struct GNUNET_PeerIdentity *trail_to_new_predecessor; |
4395 | struct FriendInfo *target_friend; | 4426 | struct FriendInfo *target_friend; |
4396 | 4427 | ||
4397 | /* Generate trail id for trail from me to new predecessor = finger. */ | 4428 | /* Generate trail id for trail from me to new predecessor = finger. */ |
4398 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, | 4429 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, |
4399 | &trail_to_new_predecessor_id, | 4430 | &trail_to_new_predecessor_id, |
4400 | sizeof (trail_to_new_predecessor_id)); | 4431 | sizeof (trail_to_new_predecessor_id)); |
4401 | 4432 | ||
4402 | /* Finger is a friend. */ | 4433 | /* Finger is a friend. */ |
4403 | if (trail_length == 0) | 4434 | if (trail_length == 0) |
4404 | { | 4435 | { |
4405 | trail_to_new_predecessor = NULL; | 4436 | trail_to_new_predecessor = NULL; |
4406 | GDS_ROUTING_add (trail_to_new_predecessor_id, my_identity, finger); | 4437 | GDS_ROUTING_add (trail_to_new_predecessor_id, my_identity, finger); |
4407 | GNUNET_assert (NULL != (target_friend = | 4438 | GNUNET_assert (NULL != (target_friend = |
4408 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 4439 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
4409 | &finger))); | 4440 | &finger))); |
4410 | } | 4441 | } |
@@ -4413,23 +4444,23 @@ update_predecessor (struct GNUNET_PeerIdentity finger, | |||
4413 | /* Invert the trail to get the trail from me to finger, NOT including the | 4444 | /* Invert the trail to get the trail from me to finger, NOT including the |
4414 | endpoints.*/ | 4445 | endpoints.*/ |
4415 | trail_to_new_predecessor = invert_trail (trail, trail_length); | 4446 | trail_to_new_predecessor = invert_trail (trail, trail_length); |
4416 | 4447 | ||
4417 | /* Add an entry in your routing table. */ | 4448 | /* Add an entry in your routing table. */ |
4418 | GDS_ROUTING_add (trail_to_new_predecessor_id, | 4449 | GDS_ROUTING_add (trail_to_new_predecessor_id, |
4419 | my_identity, | 4450 | my_identity, |
4420 | trail_to_new_predecessor[0]); | 4451 | trail_to_new_predecessor[0]); |
4421 | 4452 | ||
4422 | GNUNET_assert (NULL != (target_friend = | 4453 | GNUNET_assert (NULL != (target_friend = |
4423 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 4454 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
4424 | &trail_to_new_predecessor[0]))); | 4455 | &trail_to_new_predecessor[0]))); |
4425 | GNUNET_assert (NULL != ( | 4456 | GNUNET_assert (NULL != ( |
4426 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 4457 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
4427 | &trail[trail_length - 1]))); | 4458 | &trail[trail_length - 1]))); |
4428 | } | 4459 | } |
4429 | 4460 | ||
4430 | /* Add entry in routing table of all peers that are part of trail from me | 4461 | /* Add entry in routing table of all peers that are part of trail from me |
4431 | to finger, including finger. */ | 4462 | to finger, including finger. */ |
4432 | GDS_NEIGHBOURS_send_add_trail (my_identity, | 4463 | GDS_NEIGHBOURS_send_add_trail (my_identity, |
4433 | finger, | 4464 | finger, |
4434 | trail_to_new_predecessor_id, | 4465 | trail_to_new_predecessor_id, |
4435 | trail_to_new_predecessor, | 4466 | trail_to_new_predecessor, |
@@ -4442,32 +4473,32 @@ update_predecessor (struct GNUNET_PeerIdentity finger, | |||
4442 | } | 4473 | } |
4443 | 4474 | ||
4444 | 4475 | ||
4445 | /* | 4476 | /* |
4446 | * Check if you already have a predecessor. If not then add finger as your | 4477 | * Check if you already have a predecessor. If not then add finger as your |
4447 | * predecessor. If you have predecessor, then compare two peer identites. | 4478 | * predecessor. If you have predecessor, then compare two peer identites. |
4448 | * If finger is correct predecessor, then remove the old entry, add finger in | 4479 | * If finger is correct predecessor, then remove the old entry, add finger in |
4449 | * finger table and send add_trail message to add the trail in the routing | 4480 | * finger table and send add_trail message to add the trail in the routing |
4450 | * table of all peers which are part of trail to reach from me to finger. | 4481 | * table of all peers which are part of trail to reach from me to finger. |
4451 | * @param finger New peer which may be our predecessor. | 4482 | * @param finger New peer which may be our predecessor. |
4452 | * @param trail List of peers to reach from @finger to me. | 4483 | * @param trail List of peers to reach from @finger to me. |
4453 | * @param trail_length Total number of peer in @a trail. | 4484 | * @param trail_length Total number of peer in @a trail. |
4454 | */ | 4485 | */ |
4455 | static void | 4486 | static void |
4456 | compare_and_update_predecessor (struct GNUNET_PeerIdentity finger, | 4487 | compare_and_update_predecessor (struct GNUNET_PeerIdentity finger, |
4457 | struct GNUNET_PeerIdentity *trail, | 4488 | struct GNUNET_PeerIdentity *trail, |
4458 | unsigned int trail_length) | 4489 | unsigned int trail_length) |
4459 | { | 4490 | { |
4460 | struct FingerInfo *current_predecessor; | 4491 | struct FingerInfo *current_predecessor; |
4461 | struct GNUNET_PeerIdentity *closest_peer; | 4492 | const struct GNUNET_PeerIdentity *closest_peer; |
4462 | uint64_t predecessor_value; | 4493 | uint64_t predecessor_value; |
4463 | unsigned int is_predecessor = 1; | 4494 | unsigned int is_predecessor = 1; |
4464 | 4495 | ||
4465 | current_predecessor = &finger_table[PREDECESSOR_FINGER_ID]; | 4496 | current_predecessor = &finger_table[PREDECESSOR_FINGER_ID]; |
4466 | 4497 | ||
4467 | GNUNET_assert (0 != GNUNET_CRYPTO_cmp_peer_identity (&finger, &my_identity)); | 4498 | GNUNET_assert (0 != GNUNET_CRYPTO_cmp_peer_identity (&finger, &my_identity)); |
4468 | 4499 | ||
4469 | /* No predecessor. Add finger as your predecessor. */ | 4500 | /* No predecessor. Add finger as your predecessor. */ |
4470 | if (GNUNET_NO == current_predecessor->is_present) | 4501 | if (GNUNET_NO == current_predecessor->is_present) |
4471 | { | 4502 | { |
4472 | update_predecessor (finger, trail, trail_length); | 4503 | update_predecessor (finger, trail, trail_length); |
4473 | return; | 4504 | return; |
@@ -4480,15 +4511,15 @@ compare_and_update_predecessor (struct GNUNET_PeerIdentity finger, | |||
4480 | { | 4511 | { |
4481 | return; | 4512 | return; |
4482 | } | 4513 | } |
4483 | 4514 | ||
4484 | predecessor_value = compute_finger_identity_value (PREDECESSOR_FINGER_ID); | 4515 | predecessor_value = compute_finger_identity_value (PREDECESSOR_FINGER_ID); |
4485 | closest_peer = select_closest_peer (&finger, | 4516 | closest_peer = select_closest_peer (&finger, |
4486 | ¤t_predecessor->finger_identity, | 4517 | ¤t_predecessor->finger_identity, |
4487 | predecessor_value, is_predecessor); | 4518 | predecessor_value, is_predecessor); |
4488 | 4519 | ||
4489 | /* Finger is the closest predecessor. Remove the existing one and add the new | 4520 | /* Finger is the closest predecessor. Remove the existing one and add the new |
4490 | one. */ | 4521 | one. */ |
4491 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (closest_peer, &finger)) | 4522 | if (closest_peer == &finger) |
4492 | { | 4523 | { |
4493 | remove_existing_finger (current_predecessor, PREDECESSOR_FINGER_ID); | 4524 | remove_existing_finger (current_predecessor, PREDECESSOR_FINGER_ID); |
4494 | update_predecessor (finger, trail, trail_length); | 4525 | update_predecessor (finger, trail, trail_length); |
@@ -4498,7 +4529,7 @@ compare_and_update_predecessor (struct GNUNET_PeerIdentity finger, | |||
4498 | } | 4529 | } |
4499 | 4530 | ||
4500 | 4531 | ||
4501 | /* | 4532 | /* |
4502 | * Core handle for p2p verify successor messages. | 4533 | * Core handle for p2p verify successor messages. |
4503 | * @param cls closure | 4534 | * @param cls closure |
4504 | * @param message message | 4535 | * @param message message |
@@ -4506,7 +4537,7 @@ compare_and_update_predecessor (struct GNUNET_PeerIdentity finger, | |||
4506 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 4537 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
4507 | */ | 4538 | */ |
4508 | static int | 4539 | static int |
4509 | handle_dht_p2p_verify_successor(void *cls, | 4540 | handle_dht_p2p_verify_successor(void *cls, |
4510 | const struct GNUNET_PeerIdentity *peer, | 4541 | const struct GNUNET_PeerIdentity *peer, |
4511 | const struct GNUNET_MessageHeader *message) | 4542 | const struct GNUNET_MessageHeader *message) |
4512 | { | 4543 | { |
@@ -4522,31 +4553,31 @@ handle_dht_p2p_verify_successor(void *cls, | |||
4522 | struct GNUNET_PeerIdentity *trail_src_to_curr_pred; | 4553 | struct GNUNET_PeerIdentity *trail_src_to_curr_pred; |
4523 | size_t msize; | 4554 | size_t msize; |
4524 | unsigned int trail_length; | 4555 | unsigned int trail_length; |
4525 | 4556 | ||
4526 | msize = ntohs (message->size); | 4557 | msize = ntohs (message->size); |
4527 | 4558 | ||
4528 | if (msize < sizeof (struct PeerVerifySuccessorMessage)) | 4559 | if (msize < sizeof (struct PeerVerifySuccessorMessage)) |
4529 | { | 4560 | { |
4530 | GNUNET_break_op (0); | 4561 | GNUNET_break_op (0); |
4531 | return GNUNET_YES; | 4562 | return GNUNET_YES; |
4532 | } | 4563 | } |
4533 | 4564 | ||
4534 | vsm = (const struct PeerVerifySuccessorMessage *) message; | 4565 | vsm = (const struct PeerVerifySuccessorMessage *) message; |
4535 | trail_length = (msize - sizeof (struct PeerVerifySuccessorMessage))/ | 4566 | trail_length = (msize - sizeof (struct PeerVerifySuccessorMessage))/ |
4536 | sizeof (struct GNUNET_PeerIdentity); | 4567 | sizeof (struct GNUNET_PeerIdentity); |
4537 | if ((msize - sizeof (struct PeerVerifySuccessorMessage)) % | 4568 | if ((msize - sizeof (struct PeerVerifySuccessorMessage)) % |
4538 | sizeof (struct GNUNET_PeerIdentity) != 0) | 4569 | sizeof (struct GNUNET_PeerIdentity) != 0) |
4539 | { | 4570 | { |
4540 | GNUNET_break_op (0); | 4571 | GNUNET_break_op (0); |
4541 | return GNUNET_OK; | 4572 | return GNUNET_OK; |
4542 | } | 4573 | } |
4543 | 4574 | ||
4544 | trail_id = vsm->trail_id; | 4575 | trail_id = vsm->trail_id; |
4545 | source_peer = vsm->source_peer; | 4576 | source_peer = vsm->source_peer; |
4546 | successor = vsm->successor; | 4577 | successor = vsm->successor; |
4547 | trail = (struct GNUNET_PeerIdentity *)&vsm[1]; | 4578 | trail = (struct GNUNET_PeerIdentity *)&vsm[1]; |
4548 | 4579 | ||
4549 | 4580 | ||
4550 | /* I am NOT the successor of source_peer. Pass the message to next_hop on | 4581 | /* I am NOT the successor of source_peer. Pass the message to next_hop on |
4551 | * the trail. */ | 4582 | * the trail. */ |
4552 | if(0 != (GNUNET_CRYPTO_cmp_peer_identity (&successor, &my_identity))) | 4583 | if(0 != (GNUNET_CRYPTO_cmp_peer_identity (&successor, &my_identity))) |
@@ -4557,8 +4588,8 @@ handle_dht_p2p_verify_successor(void *cls, | |||
4557 | GNUNET_break (0); | 4588 | GNUNET_break (0); |
4558 | return GNUNET_SYSERR; | 4589 | return GNUNET_SYSERR; |
4559 | } | 4590 | } |
4560 | GNUNET_assert (NULL != | 4591 | GNUNET_assert (NULL != |
4561 | (target_friend = | 4592 | (target_friend = |
4562 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop))); | 4593 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop))); |
4563 | 4594 | ||
4564 | GDS_NEIGHBOURS_send_verify_successor_message (source_peer, successor, | 4595 | GDS_NEIGHBOURS_send_verify_successor_message (source_peer, successor, |
@@ -4566,14 +4597,14 @@ handle_dht_p2p_verify_successor(void *cls, | |||
4566 | target_friend); | 4597 | target_friend); |
4567 | return GNUNET_OK; | 4598 | return GNUNET_OK; |
4568 | } | 4599 | } |
4569 | 4600 | ||
4570 | /* I am the destination of this message. */ | 4601 | /* I am the destination of this message. */ |
4571 | 4602 | ||
4572 | /* Check if the source_peer could be our predecessor and if yes then update | 4603 | /* Check if the source_peer could be our predecessor and if yes then update |
4573 | * it. */ | 4604 | * it. */ |
4574 | compare_and_update_predecessor (source_peer, trail, trail_length); | 4605 | compare_and_update_predecessor (source_peer, trail, trail_length); |
4575 | current_predecessor = &finger_table[PREDECESSOR_FINGER_ID]; | 4606 | current_predecessor = &finger_table[PREDECESSOR_FINGER_ID]; |
4576 | 4607 | ||
4577 | /* Is source of this message NOT my predecessor. */ | 4608 | /* Is source of this message NOT my predecessor. */ |
4578 | if (0 != (GNUNET_CRYPTO_cmp_peer_identity (¤t_predecessor->finger_identity, | 4609 | if (0 != (GNUNET_CRYPTO_cmp_peer_identity (¤t_predecessor->finger_identity, |
4579 | &source_peer))) | 4610 | &source_peer))) |
@@ -4581,7 +4612,7 @@ handle_dht_p2p_verify_successor(void *cls, | |||
4581 | trail_src_to_curr_pred = get_trail_src_to_curr_pred (source_peer, | 4612 | trail_src_to_curr_pred = get_trail_src_to_curr_pred (source_peer, |
4582 | trail, | 4613 | trail, |
4583 | trail_length, | 4614 | trail_length, |
4584 | &trail_src_to_curr_pred_len); | 4615 | &trail_src_to_curr_pred_len); |
4585 | } | 4616 | } |
4586 | else | 4617 | else |
4587 | { | 4618 | { |
@@ -4594,9 +4625,9 @@ handle_dht_p2p_verify_successor(void *cls, | |||
4594 | } | 4625 | } |
4595 | 4626 | ||
4596 | } | 4627 | } |
4597 | 4628 | ||
4598 | GNUNET_assert (NULL != | 4629 | GNUNET_assert (NULL != |
4599 | (target_friend = | 4630 | (target_friend = |
4600 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer))); | 4631 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer))); |
4601 | GDS_NEIGHBOURS_send_verify_successor_result (source_peer, my_identity, | 4632 | GDS_NEIGHBOURS_send_verify_successor_result (source_peer, my_identity, |
4602 | current_predecessor->finger_identity, | 4633 | current_predecessor->finger_identity, |
@@ -4613,12 +4644,12 @@ handle_dht_p2p_verify_successor(void *cls, | |||
4613 | * If the trail from me to my probable successor contains a friend not | 4644 | * If the trail from me to my probable successor contains a friend not |
4614 | * at index 0, then we can shorten the trail. | 4645 | * at index 0, then we can shorten the trail. |
4615 | * @param probable_successor Peer which is our probable successor | 4646 | * @param probable_successor Peer which is our probable successor |
4616 | * @param trail_me_to_probable_successor Peers in path from me to my probable | 4647 | * @param trail_me_to_probable_successor Peers in path from me to my probable |
4617 | * successor, NOT including the endpoints. | 4648 | * successor, NOT including the endpoints. |
4618 | * @param trail_me_to_probable_successor_len Total number of peers in | 4649 | * @param trail_me_to_probable_successor_len Total number of peers in |
4619 | * @a trail_me_to_probable_succesor. | 4650 | * @a trail_me_to_probable_succesor. |
4620 | * @return Updated trail, if any friend found. | 4651 | * @return Updated trail, if any friend found. |
4621 | * Else the trail_me_to_probable_successor. | 4652 | * Else the trail_me_to_probable_successor. |
4622 | */ | 4653 | */ |
4623 | struct GNUNET_PeerIdentity * | 4654 | struct GNUNET_PeerIdentity * |
4624 | check_trail_me_to_probable_succ (struct GNUNET_PeerIdentity probable_successor, | 4655 | check_trail_me_to_probable_succ (struct GNUNET_PeerIdentity probable_successor, |
@@ -4629,45 +4660,45 @@ check_trail_me_to_probable_succ (struct GNUNET_PeerIdentity probable_successor, | |||
4629 | unsigned int i; | 4660 | unsigned int i; |
4630 | unsigned int j; | 4661 | unsigned int j; |
4631 | struct GNUNET_PeerIdentity *trail_to_new_successor; | 4662 | struct GNUNET_PeerIdentity *trail_to_new_successor; |
4632 | 4663 | ||
4633 | /* Probable successor is a friend */ | 4664 | /* Probable successor is a friend */ |
4634 | if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 4665 | if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
4635 | &probable_successor)) | 4666 | &probable_successor)) |
4636 | { | 4667 | { |
4637 | trail_to_new_successor = NULL; | 4668 | trail_to_new_successor = NULL; |
4638 | *trail_to_new_successor_length = 0; | 4669 | *trail_to_new_successor_length = 0; |
4639 | return trail_to_new_successor; | 4670 | return trail_to_new_successor; |
4640 | } | 4671 | } |
4641 | 4672 | ||
4642 | /* Is there any friend of yours in this trail. */ | 4673 | /* Is there any friend of yours in this trail. */ |
4643 | if(trail_me_to_probable_successor_len > 1) | 4674 | if(trail_me_to_probable_successor_len > 1) |
4644 | { | 4675 | { |
4645 | for (i = trail_me_to_probable_successor_len - 1; i > 0; i--) | 4676 | for (i = trail_me_to_probable_successor_len - 1; i > 0; i--) |
4646 | { | 4677 | { |
4647 | if (NULL == GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 4678 | if (NULL == GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
4648 | &trail_me_to_probable_successor[i])) | 4679 | &trail_me_to_probable_successor[i])) |
4649 | continue; | 4680 | continue; |
4650 | 4681 | ||
4651 | j = 0; | 4682 | j = 0; |
4652 | *trail_to_new_successor_length = (trail_me_to_probable_successor_len - i); | 4683 | *trail_to_new_successor_length = (trail_me_to_probable_successor_len - i); |
4653 | trail_to_new_successor = GNUNET_malloc (sizeof(struct GNUNET_PeerIdentity)* | 4684 | trail_to_new_successor = GNUNET_malloc (sizeof(struct GNUNET_PeerIdentity)* |
4654 | *trail_to_new_successor_length); | 4685 | *trail_to_new_successor_length); |
4655 | 4686 | ||
4656 | for(j = 0;i < trail_me_to_probable_successor_len;i++,j++) | 4687 | for(j = 0;i < trail_me_to_probable_successor_len;i++,j++) |
4657 | { | 4688 | { |
4658 | trail_to_new_successor[j] = trail_me_to_probable_successor[i]; | 4689 | trail_to_new_successor[j] = trail_me_to_probable_successor[i]; |
4659 | } | 4690 | } |
4660 | return trail_to_new_successor; | 4691 | return trail_to_new_successor; |
4661 | } | 4692 | } |
4662 | } | 4693 | } |
4663 | 4694 | ||
4664 | *trail_to_new_successor_length = trail_me_to_probable_successor_len; | 4695 | *trail_to_new_successor_length = trail_me_to_probable_successor_len; |
4665 | trail_to_new_successor = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)* | 4696 | trail_to_new_successor = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)* |
4666 | *trail_to_new_successor_length); | 4697 | *trail_to_new_successor_length); |
4667 | 4698 | ||
4668 | for(i = 0; i < *trail_to_new_successor_length; i++) | 4699 | for(i = 0; i < *trail_to_new_successor_length; i++) |
4669 | trail_to_new_successor[i] = trail_me_to_probable_successor[i]; | 4700 | trail_to_new_successor[i] = trail_me_to_probable_successor[i]; |
4670 | 4701 | ||
4671 | return trail_to_new_successor; | 4702 | return trail_to_new_successor; |
4672 | } | 4703 | } |
4673 | 4704 | ||
@@ -4677,7 +4708,7 @@ check_trail_me_to_probable_succ (struct GNUNET_PeerIdentity probable_successor, | |||
4677 | * successor or not. If not, then compare existing successor and probable successor. | 4708 | * successor or not. If not, then compare existing successor and probable successor. |
4678 | * In case probable successor is the correct successor, remove the existing | 4709 | * In case probable successor is the correct successor, remove the existing |
4679 | * successor. Add probable successor as new successor. Send notify new successor | 4710 | * successor. Add probable successor as new successor. Send notify new successor |
4680 | * message to new successor. | 4711 | * message to new successor. |
4681 | * @param curr_succ | 4712 | * @param curr_succ |
4682 | * @param probable_successor | 4713 | * @param probable_successor |
4683 | * @param trail | 4714 | * @param trail |
@@ -4690,42 +4721,44 @@ compare_and_update_successor (struct GNUNET_PeerIdentity curr_succ, | |||
4690 | unsigned int trail_length) | 4721 | unsigned int trail_length) |
4691 | { | 4722 | { |
4692 | struct FingerInfo *current_successor; | 4723 | struct FingerInfo *current_successor; |
4693 | struct GNUNET_PeerIdentity *closest_peer; | 4724 | const struct GNUNET_PeerIdentity *closest_peer; |
4694 | struct GNUNET_HashCode trail_id; | 4725 | struct GNUNET_HashCode trail_id; |
4695 | struct GNUNET_PeerIdentity *trail_me_to_probable_succ; | 4726 | struct GNUNET_PeerIdentity *trail_me_to_probable_succ; |
4696 | struct FriendInfo *target_friend; | 4727 | struct FriendInfo *target_friend; |
4697 | unsigned int trail_me_to_probable_succ_len; | 4728 | unsigned int trail_me_to_probable_succ_len; |
4698 | unsigned int is_predecessor = GNUNET_NO; | 4729 | unsigned int is_predecessor = GNUNET_NO; |
4699 | uint64_t successor_value; | 4730 | uint64_t successor_value; |
4700 | 4731 | ||
4701 | current_successor = &finger_table[0]; | 4732 | current_successor = &finger_table[0]; |
4702 | successor_value = compute_finger_identity_value(0); | 4733 | successor_value = compute_finger_identity_value(0); |
4703 | 4734 | ||
4704 | /* Have we found some other successor, while waiting for verify successor result. */ | 4735 | /* Have we found some other successor, while waiting for verify successor result |
4736 | * | ||
4737 | * FIXME closest_peer is being overwritten just after the if | ||
4738 | */ | ||
4705 | if(0 != GNUNET_CRYPTO_cmp_peer_identity(&curr_succ, ¤t_successor->finger_identity)) | 4739 | if(0 != GNUNET_CRYPTO_cmp_peer_identity(&curr_succ, ¤t_successor->finger_identity)) |
4706 | { | 4740 | { |
4707 | /* We could have added this new successor, only if it was closer the old one. */ | 4741 | /* We could have added this new successor, only if it was closer the old one. */ |
4708 | closest_peer = select_closest_peer (&curr_succ, | 4742 | closest_peer = select_closest_peer (&curr_succ, |
4709 | ¤t_successor->finger_identity, | 4743 | ¤t_successor->finger_identity, |
4710 | successor_value, is_predecessor); | 4744 | successor_value, is_predecessor); |
4711 | 4745 | ||
4712 | /* FIXME: it may fail in case we have done more number of iterations of | 4746 | /* FIXME: it may fail in case we have done more number of iterations of |
4713 | find _finger_trail_task. */ | 4747 | find _finger_trail_task. */ |
4714 | /*GNUNET_assert (0 == | 4748 | /*GNUNET_assert (0 == |
4715 | GNUNET_CRYPTO_cmp_peer_identity (closest_peer, | 4749 | GNUNET_CRYPTO_cmp_peer_identity (closest_peer, |
4716 | ¤t_successor->finger_identity));*/ | 4750 | ¤t_successor->finger_identity));*/ |
4717 | 4751 | ||
4718 | } | 4752 | } |
4719 | 4753 | ||
4720 | closest_peer = select_closest_peer (&probable_successor, | 4754 | closest_peer = select_closest_peer (&probable_successor, |
4721 | ¤t_successor->finger_identity, | 4755 | ¤t_successor->finger_identity, |
4722 | successor_value, is_predecessor); | 4756 | successor_value, is_predecessor); |
4723 | 4757 | ||
4724 | /* If the current_successor in the finger table is closest, then do nothing. */ | 4758 | /* If the current_successor in the finger table is closest, then do nothing. */ |
4725 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (closest_peer, | 4759 | if (closest_peer == ¤t_successor->finger_identity) |
4726 | ¤t_successor->finger_identity)) | ||
4727 | return; | 4760 | return; |
4728 | 4761 | ||
4729 | /* Probable successor is the closest peer.*/ | 4762 | /* Probable successor is the closest peer.*/ |
4730 | if(trail_length > 0) | 4763 | if(trail_length > 0) |
4731 | GNUNET_assert(NULL != GNUNET_CONTAINER_multipeermap_get(friend_peermap, | 4764 | GNUNET_assert(NULL != GNUNET_CONTAINER_multipeermap_get(friend_peermap, |
@@ -4733,41 +4766,41 @@ compare_and_update_successor (struct GNUNET_PeerIdentity curr_succ, | |||
4733 | else | 4766 | else |
4734 | GNUNET_assert(NULL != GNUNET_CONTAINER_multipeermap_get(friend_peermap, | 4767 | GNUNET_assert(NULL != GNUNET_CONTAINER_multipeermap_get(friend_peermap, |
4735 | &probable_successor)); | 4768 | &probable_successor)); |
4736 | 4769 | ||
4737 | trail_me_to_probable_succ_len = 0; | 4770 | trail_me_to_probable_succ_len = 0; |
4738 | /* TODO: Check if the path to reach to probable successor contains a friend. */ | 4771 | /* TODO: Check if the path to reach to probable successor contains a friend. */ |
4739 | trail_me_to_probable_succ = | 4772 | trail_me_to_probable_succ = |
4740 | check_trail_me_to_probable_succ (probable_successor, | 4773 | check_trail_me_to_probable_succ (probable_successor, |
4741 | trail, trail_length, | 4774 | trail, trail_length, |
4742 | &trail_me_to_probable_succ_len); | 4775 | &trail_me_to_probable_succ_len); |
4743 | 4776 | ||
4744 | /* Remove the existing successor. */ | 4777 | /* Remove the existing successor. */ |
4745 | remove_existing_finger (current_successor, 0); | 4778 | remove_existing_finger (current_successor, 0); |
4746 | 4779 | ||
4747 | /* Generate a new trail id to reach to your new successor. */ | 4780 | /* Generate a new trail id to reach to your new successor. */ |
4748 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, | 4781 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, |
4749 | &trail_id, sizeof (trail_id)); | 4782 | &trail_id, sizeof (trail_id)); |
4750 | 4783 | ||
4751 | if (trail_me_to_probable_succ_len > 0) | 4784 | if (trail_me_to_probable_succ_len > 0) |
4752 | { | 4785 | { |
4753 | GDS_ROUTING_add (trail_id, my_identity, trail_me_to_probable_succ[0]); | 4786 | GDS_ROUTING_add (trail_id, my_identity, trail_me_to_probable_succ[0]); |
4754 | GNUNET_assert (NULL != | 4787 | GNUNET_assert (NULL != |
4755 | (target_friend = | 4788 | (target_friend = |
4756 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 4789 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
4757 | &trail_me_to_probable_succ[0]))); | 4790 | &trail_me_to_probable_succ[0]))); |
4758 | } | 4791 | } |
4759 | else | 4792 | else |
4760 | { | 4793 | { |
4761 | GDS_ROUTING_add (trail_id, my_identity, probable_successor); | 4794 | GDS_ROUTING_add (trail_id, my_identity, probable_successor); |
4762 | GNUNET_assert (NULL != | 4795 | GNUNET_assert (NULL != |
4763 | (target_friend = | 4796 | (target_friend = |
4764 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 4797 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
4765 | &probable_successor))); | 4798 | &probable_successor))); |
4766 | } | 4799 | } |
4767 | 4800 | ||
4768 | add_new_finger (probable_successor, trail_me_to_probable_succ, | 4801 | add_new_finger (probable_successor, trail_me_to_probable_succ, |
4769 | trail_me_to_probable_succ_len, trail_id, 0); | 4802 | trail_me_to_probable_succ_len, trail_id, 0); |
4770 | 4803 | ||
4771 | GDS_NEIGHBOURS_send_notify_new_successor (my_identity, probable_successor, | 4804 | GDS_NEIGHBOURS_send_notify_new_successor (my_identity, probable_successor, |
4772 | trail_me_to_probable_succ, | 4805 | trail_me_to_probable_succ, |
4773 | trail_me_to_probable_succ_len, | 4806 | trail_me_to_probable_succ_len, |
@@ -4785,7 +4818,7 @@ compare_and_update_successor (struct GNUNET_PeerIdentity curr_succ, | |||
4785 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 4818 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
4786 | */ | 4819 | */ |
4787 | static int | 4820 | static int |
4788 | handle_dht_p2p_verify_successor_result(void *cls, | 4821 | handle_dht_p2p_verify_successor_result(void *cls, |
4789 | const struct GNUNET_PeerIdentity *peer, | 4822 | const struct GNUNET_PeerIdentity *peer, |
4790 | const struct GNUNET_MessageHeader *message) | 4823 | const struct GNUNET_MessageHeader *message) |
4791 | { | 4824 | { |
@@ -4809,18 +4842,18 @@ handle_dht_p2p_verify_successor_result(void *cls, | |||
4809 | GNUNET_break_op (0); | 4842 | GNUNET_break_op (0); |
4810 | return GNUNET_YES; | 4843 | return GNUNET_YES; |
4811 | } | 4844 | } |
4812 | 4845 | ||
4813 | vsrm = (const struct PeerVerifySuccessorResultMessage *) message; | 4846 | vsrm = (const struct PeerVerifySuccessorResultMessage *) message; |
4814 | trail_length = (msize - sizeof (struct PeerVerifySuccessorResultMessage))/ | 4847 | trail_length = (msize - sizeof (struct PeerVerifySuccessorResultMessage))/ |
4815 | sizeof (struct GNUNET_PeerIdentity); | 4848 | sizeof (struct GNUNET_PeerIdentity); |
4816 | 4849 | ||
4817 | if ((msize - sizeof (struct PeerVerifySuccessorResultMessage)) % | 4850 | if ((msize - sizeof (struct PeerVerifySuccessorResultMessage)) % |
4818 | sizeof (struct GNUNET_PeerIdentity) != 0) | 4851 | sizeof (struct GNUNET_PeerIdentity) != 0) |
4819 | { | 4852 | { |
4820 | GNUNET_break_op (0); | 4853 | GNUNET_break_op (0); |
4821 | return GNUNET_OK; | 4854 | return GNUNET_OK; |
4822 | } | 4855 | } |
4823 | 4856 | ||
4824 | trail = (const struct GNUNET_PeerIdentity *) &vsrm[1]; | 4857 | trail = (const struct GNUNET_PeerIdentity *) &vsrm[1]; |
4825 | querying_peer = vsrm->querying_peer; | 4858 | querying_peer = vsrm->querying_peer; |
4826 | trail_direction = ntohl (vsrm->trail_direction); | 4859 | trail_direction = ntohl (vsrm->trail_direction); |
@@ -4835,12 +4868,12 @@ handle_dht_p2p_verify_successor_result(void *cls, | |||
4835 | probable_successor, trail, trail_length); | 4868 | probable_successor, trail, trail_length); |
4836 | return GNUNET_OK; | 4869 | return GNUNET_OK; |
4837 | } | 4870 | } |
4838 | 4871 | ||
4839 | /*If you are not the querying peer then pass on the message */ | 4872 | /*If you are not the querying peer then pass on the message */ |
4840 | GNUNET_assert (NULL != (next_hop = | 4873 | GNUNET_assert (NULL != (next_hop = |
4841 | GDS_ROUTING_get_next_hop (trail_id, trail_direction))); | 4874 | GDS_ROUTING_get_next_hop (trail_id, trail_direction))); |
4842 | GNUNET_assert (NULL != | 4875 | GNUNET_assert (NULL != |
4843 | (target_friend = | 4876 | (target_friend = |
4844 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop))); | 4877 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop))); |
4845 | GDS_NEIGHBOURS_send_verify_successor_result (querying_peer, | 4878 | GDS_NEIGHBOURS_send_verify_successor_result (querying_peer, |
4846 | vsrm->current_successor, | 4879 | vsrm->current_successor, |
@@ -4852,7 +4885,7 @@ handle_dht_p2p_verify_successor_result(void *cls, | |||
4852 | } | 4885 | } |
4853 | 4886 | ||
4854 | 4887 | ||
4855 | /* | 4888 | /* |
4856 | * Core handle for p2p notify new successor messages. | 4889 | * Core handle for p2p notify new successor messages. |
4857 | * @param cls closure | 4890 | * @param cls closure |
4858 | * @param message message | 4891 | * @param message message |
@@ -4860,7 +4893,7 @@ handle_dht_p2p_verify_successor_result(void *cls, | |||
4860 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 4893 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
4861 | */ | 4894 | */ |
4862 | static int | 4895 | static int |
4863 | handle_dht_p2p_notify_new_successor(void *cls, | 4896 | handle_dht_p2p_notify_new_successor(void *cls, |
4864 | const struct GNUNET_PeerIdentity *peer, | 4897 | const struct GNUNET_PeerIdentity *peer, |
4865 | const struct GNUNET_MessageHeader *message) | 4898 | const struct GNUNET_MessageHeader *message) |
4866 | { | 4899 | { |
@@ -4876,7 +4909,7 @@ handle_dht_p2p_notify_new_successor(void *cls, | |||
4876 | uint32_t trail_length; | 4909 | uint32_t trail_length; |
4877 | 4910 | ||
4878 | msize = ntohs (message->size); | 4911 | msize = ntohs (message->size); |
4879 | 4912 | ||
4880 | /* We have the trail to reach from source to new successor. */ | 4913 | /* We have the trail to reach from source to new successor. */ |
4881 | if (msize < sizeof (struct PeerNotifyNewSuccessorMessage)) | 4914 | if (msize < sizeof (struct PeerNotifyNewSuccessorMessage)) |
4882 | { | 4915 | { |
@@ -4887,20 +4920,20 @@ handle_dht_p2p_notify_new_successor(void *cls, | |||
4887 | nsm = (const struct PeerNotifyNewSuccessorMessage *) message; | 4920 | nsm = (const struct PeerNotifyNewSuccessorMessage *) message; |
4888 | trail_length = (msize - sizeof (struct PeerNotifyNewSuccessorMessage))/ | 4921 | trail_length = (msize - sizeof (struct PeerNotifyNewSuccessorMessage))/ |
4889 | sizeof (struct GNUNET_PeerIdentity); | 4922 | sizeof (struct GNUNET_PeerIdentity); |
4890 | if ((msize - sizeof (struct PeerNotifyNewSuccessorMessage)) % | 4923 | if ((msize - sizeof (struct PeerNotifyNewSuccessorMessage)) % |
4891 | sizeof (struct GNUNET_PeerIdentity) != 0) | 4924 | sizeof (struct GNUNET_PeerIdentity) != 0) |
4892 | { | 4925 | { |
4893 | GNUNET_break_op (0); | 4926 | GNUNET_break_op (0); |
4894 | return GNUNET_OK; | 4927 | return GNUNET_OK; |
4895 | } | 4928 | } |
4896 | 4929 | ||
4897 | trail = (struct GNUNET_PeerIdentity *) &nsm[1]; | 4930 | trail = (struct GNUNET_PeerIdentity *) &nsm[1]; |
4898 | source = nsm->source_peer; | 4931 | source = nsm->source_peer; |
4899 | new_successor = nsm->new_successor; | 4932 | new_successor = nsm->new_successor; |
4900 | trail_id = nsm->trail_id; | 4933 | trail_id = nsm->trail_id; |
4934 | |||
4935 | //FIXME: add a check to make sure peer is correct. | ||
4901 | 4936 | ||
4902 | //FIXME: add a check to make sure peer is correct. | ||
4903 | |||
4904 | /* I am the new_successor to source_peer. */ | 4937 | /* I am the new_successor to source_peer. */ |
4905 | if ( 0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &new_successor)) | 4938 | if ( 0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &new_successor)) |
4906 | { | 4939 | { |
@@ -4908,33 +4941,33 @@ handle_dht_p2p_notify_new_successor(void *cls, | |||
4908 | compare_and_update_predecessor (source, trail, trail_length); | 4941 | compare_and_update_predecessor (source, trail, trail_length); |
4909 | return GNUNET_OK; | 4942 | return GNUNET_OK; |
4910 | } | 4943 | } |
4911 | 4944 | ||
4912 | GNUNET_assert(trail_length > 0); | 4945 | GNUNET_assert(trail_length > 0); |
4913 | /* I am part of trail to reach to successor. */ | 4946 | /* I am part of trail to reach to successor. */ |
4914 | my_index = search_my_index (trail, trail_length); | 4947 | my_index = search_my_index (trail, trail_length); |
4915 | if (-1 == my_index) | 4948 | if (-1 == my_index) |
4916 | { | 4949 | { |
4917 | GNUNET_break_op (0); | 4950 | GNUNET_break_op (0); |
4918 | return GNUNET_SYSERR; | 4951 | return GNUNET_SYSERR; |
4919 | } | 4952 | } |
4920 | 4953 | ||
4921 | if ((trail_length-1) == my_index) | 4954 | if ((trail_length-1) == my_index) |
4922 | next_hop = new_successor; | 4955 | next_hop = new_successor; |
4923 | else | 4956 | else |
4924 | next_hop = trail[my_index + 1]; | 4957 | next_hop = trail[my_index + 1]; |
4925 | 4958 | ||
4926 | 4959 | ||
4927 | /* Add an entry in routing table for trail from source to its new successor. */ | 4960 | /* Add an entry in routing table for trail from source to its new successor. */ |
4928 | GNUNET_assert (GNUNET_OK == GDS_ROUTING_add (trail_id, *peer, next_hop)); | 4961 | GNUNET_assert (GNUNET_OK == GDS_ROUTING_add (trail_id, *peer, next_hop)); |
4929 | 4962 | ||
4930 | GNUNET_assert (NULL != | 4963 | GNUNET_assert (NULL != |
4931 | (target_friend = | 4964 | (target_friend = |
4932 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop))); | 4965 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop))); |
4933 | GDS_NEIGHBOURS_send_notify_new_successor (source, new_successor, trail, | 4966 | GDS_NEIGHBOURS_send_notify_new_successor (source, new_successor, trail, |
4934 | trail_length, | 4967 | trail_length, |
4935 | trail_id, target_friend); | 4968 | trail_id, target_friend); |
4936 | return GNUNET_OK; | 4969 | return GNUNET_OK; |
4937 | 4970 | ||
4938 | } | 4971 | } |
4939 | 4972 | ||
4940 | 4973 | ||
@@ -4970,34 +5003,34 @@ handle_dht_p2p_trail_setup_rejection (void *cls, | |||
4970 | GNUNET_break_op (0); | 5003 | GNUNET_break_op (0); |
4971 | return GNUNET_YES; | 5004 | return GNUNET_YES; |
4972 | } | 5005 | } |
4973 | 5006 | ||
4974 | trail_rejection = (const struct PeerTrailRejectionMessage *) message; | 5007 | trail_rejection = (const struct PeerTrailRejectionMessage *) message; |
4975 | trail_length = (msize - sizeof (struct PeerTrailRejectionMessage))/ | 5008 | trail_length = (msize - sizeof (struct PeerTrailRejectionMessage))/ |
4976 | sizeof (struct GNUNET_PeerIdentity); | 5009 | sizeof (struct GNUNET_PeerIdentity); |
4977 | if ((msize - sizeof (struct PeerTrailRejectionMessage)) % | 5010 | if ((msize - sizeof (struct PeerTrailRejectionMessage)) % |
4978 | sizeof (struct GNUNET_PeerIdentity) != 0) | 5011 | sizeof (struct GNUNET_PeerIdentity) != 0) |
4979 | { | 5012 | { |
4980 | GNUNET_break_op (0); | 5013 | GNUNET_break_op (0); |
4981 | return GNUNET_OK; | 5014 | return GNUNET_OK; |
4982 | } | 5015 | } |
4983 | 5016 | ||
4984 | trail_peer_list = (const struct GNUNET_PeerIdentity *)&trail_rejection[1]; | 5017 | trail_peer_list = (const struct GNUNET_PeerIdentity *)&trail_rejection[1]; |
4985 | is_predecessor = ntohl (trail_rejection->is_predecessor); | 5018 | is_predecessor = ntohl (trail_rejection->is_predecessor); |
4986 | congestion_timeout = trail_rejection->congestion_time; | 5019 | congestion_timeout = trail_rejection->congestion_time; |
4987 | source = trail_rejection->source_peer; | 5020 | source = trail_rejection->source_peer; |
4988 | trail_id = trail_rejection->trail_id; | 5021 | trail_id = trail_rejection->trail_id; |
4989 | ultimate_destination_finger_value = | 5022 | ultimate_destination_finger_value = |
4990 | GNUNET_ntohll (trail_rejection->ultimate_destination_finger_value); | 5023 | GNUNET_ntohll (trail_rejection->ultimate_destination_finger_value); |
4991 | 5024 | ||
4992 | /* First set the congestion time of the friend that sent you this message. */ | 5025 | /* First set the congestion time of the friend that sent you this message. */ |
4993 | GNUNET_assert (NULL != | 5026 | GNUNET_assert (NULL != |
4994 | (target_friend = | 5027 | (target_friend = |
4995 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer))); | 5028 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer))); |
4996 | target_friend->congestion_timestamp = | 5029 | target_friend->congestion_timestamp = |
4997 | GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(), | 5030 | GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(), |
4998 | congestion_timeout); | 5031 | congestion_timeout); |
4999 | 5032 | ||
5000 | /* I am the source peer which wants to setup the trail. Do nothing. | 5033 | /* I am the source peer which wants to setup the trail. Do nothing. |
5001 | * send_find_finger_trail_task is scheduled periodically.*/ | 5034 | * send_find_finger_trail_task is scheduled periodically.*/ |
5002 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &source))) | 5035 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &source))) |
5003 | return GNUNET_OK; | 5036 | return GNUNET_OK; |
@@ -5007,7 +5040,7 @@ handle_dht_p2p_trail_setup_rejection (void *cls, | |||
5007 | { | 5040 | { |
5008 | struct GNUNET_PeerIdentity *new_trail; | 5041 | struct GNUNET_PeerIdentity *new_trail; |
5009 | unsigned int new_trail_length; | 5042 | unsigned int new_trail_length; |
5010 | 5043 | ||
5011 | /* Remove yourself from the trail setup so far. */ | 5044 | /* Remove yourself from the trail setup so far. */ |
5012 | if (trail_length == 1) | 5045 | if (trail_length == 1) |
5013 | { | 5046 | { |
@@ -5017,17 +5050,17 @@ handle_dht_p2p_trail_setup_rejection (void *cls, | |||
5017 | } | 5050 | } |
5018 | else | 5051 | else |
5019 | { | 5052 | { |
5020 | memcpy (&next_hop , &trail_peer_list[trail_length - 2], | 5053 | memcpy (&next_hop , &trail_peer_list[trail_length - 2], |
5021 | sizeof (struct GNUNET_PeerIdentity)); | 5054 | sizeof (struct GNUNET_PeerIdentity)); |
5022 | 5055 | ||
5023 | /* Remove myself from the trail. */ | 5056 | /* Remove myself from the trail. */ |
5024 | new_trail_length = trail_length -1; | 5057 | new_trail_length = trail_length -1; |
5025 | new_trail = GNUNET_malloc (new_trail_length * sizeof (struct GNUNET_PeerIdentity)); | 5058 | new_trail = GNUNET_malloc (new_trail_length * sizeof (struct GNUNET_PeerIdentity)); |
5026 | memcpy (new_trail, trail_peer_list, new_trail_length * sizeof (struct GNUNET_PeerIdentity)); | 5059 | memcpy (new_trail, trail_peer_list, new_trail_length * sizeof (struct GNUNET_PeerIdentity)); |
5027 | } | 5060 | } |
5028 | 5061 | ||
5029 | GNUNET_assert (NULL != | 5062 | GNUNET_assert (NULL != |
5030 | (target_friend = | 5063 | (target_friend = |
5031 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop))); | 5064 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop))); |
5032 | GDS_NEIGHBOURS_send_trail_rejection (source, | 5065 | GDS_NEIGHBOURS_send_trail_rejection (source, |
5033 | ultimate_destination_finger_value, | 5066 | ultimate_destination_finger_value, |
@@ -5037,28 +5070,28 @@ handle_dht_p2p_trail_setup_rejection (void *cls, | |||
5037 | GNUNET_free (new_trail); | 5070 | GNUNET_free (new_trail); |
5038 | return GNUNET_OK; | 5071 | return GNUNET_OK; |
5039 | } | 5072 | } |
5040 | 5073 | ||
5041 | struct Closest_Peer successor; | 5074 | struct Closest_Peer successor; |
5042 | successor = find_successor (ultimate_destination_finger_value, is_predecessor); | 5075 | successor = find_successor (ultimate_destination_finger_value, is_predecessor); |
5043 | 5076 | ||
5044 | /* Am I the final destination? */ | 5077 | /* Am I the final destination? */ |
5045 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&successor.best_known_destination, | 5078 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&successor.best_known_destination, |
5046 | &my_identity))) | 5079 | &my_identity))) |
5047 | { | 5080 | { |
5048 | if (0 == trail_length) | 5081 | if (0 == trail_length) |
5049 | next_peer = source; | 5082 | next_peer = source; |
5050 | else | 5083 | else |
5051 | next_peer = trail_peer_list[trail_length-1]; | 5084 | next_peer = trail_peer_list[trail_length-1]; |
5052 | 5085 | ||
5053 | GNUNET_assert (NULL != | 5086 | GNUNET_assert (NULL != |
5054 | (target_friend = | 5087 | (target_friend = |
5055 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_peer))); | 5088 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_peer))); |
5056 | 5089 | ||
5057 | GDS_NEIGHBOURS_send_trail_setup_result (source, | 5090 | GDS_NEIGHBOURS_send_trail_setup_result (source, |
5058 | my_identity, | 5091 | my_identity, |
5059 | target_friend, trail_length, | 5092 | target_friend, trail_length, |
5060 | trail_peer_list, | 5093 | trail_peer_list, |
5061 | is_predecessor, | 5094 | is_predecessor, |
5062 | ultimate_destination_finger_value, | 5095 | ultimate_destination_finger_value, |
5063 | trail_id); | 5096 | trail_id); |
5064 | } | 5097 | } |
@@ -5069,8 +5102,8 @@ handle_dht_p2p_trail_setup_rejection (void *cls, | |||
5069 | memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); | 5102 | memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); |
5070 | peer_list[trail_length] = my_identity; | 5103 | peer_list[trail_length] = my_identity; |
5071 | 5104 | ||
5072 | GNUNET_assert (NULL != | 5105 | GNUNET_assert (NULL != |
5073 | (target_friend = | 5106 | (target_friend = |
5074 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop))); | 5107 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop))); |
5075 | 5108 | ||
5076 | GDS_NEIGHBOURS_send_trail_setup (source, | 5109 | GDS_NEIGHBOURS_send_trail_setup (source, |
@@ -5108,40 +5141,40 @@ handle_dht_p2p_trail_compression (void *cls, const struct GNUNET_PeerIdentity *p | |||
5108 | GNUNET_break_op (0); | 5141 | GNUNET_break_op (0); |
5109 | return GNUNET_OK; | 5142 | return GNUNET_OK; |
5110 | } | 5143 | } |
5111 | 5144 | ||
5112 | trail_compression = (const struct PeerTrailCompressionMessage *) message; | 5145 | trail_compression = (const struct PeerTrailCompressionMessage *) message; |
5113 | trail_id = trail_compression->trail_id; | 5146 | trail_id = trail_compression->trail_id; |
5114 | 5147 | ||
5115 | /* Am I the new first friend to reach to finger of this trail. */ | 5148 | /* Am I the new first friend to reach to finger of this trail. */ |
5116 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&trail_compression->new_first_friend, | 5149 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&trail_compression->new_first_friend, |
5117 | &my_identity))) | 5150 | &my_identity))) |
5118 | { | 5151 | { |
5119 | GNUNET_assert (NULL != | 5152 | GNUNET_assert (NULL != |
5120 | (GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 5153 | (GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
5121 | &trail_compression->source_peer))); | 5154 | &trail_compression->source_peer))); |
5122 | 5155 | ||
5123 | /* Update your prev hop to source of this message. */ | 5156 | /* Update your prev hop to source of this message. */ |
5124 | GNUNET_assert (GNUNET_SYSERR != | 5157 | GNUNET_assert (GNUNET_SYSERR != |
5125 | (GDS_ROUTING_update_trail_prev_hop (trail_id, | 5158 | (GDS_ROUTING_update_trail_prev_hop (trail_id, |
5126 | trail_compression->source_peer))); | 5159 | trail_compression->source_peer))); |
5127 | return GNUNET_OK; | 5160 | return GNUNET_OK; |
5128 | } | 5161 | } |
5129 | 5162 | ||
5130 | /* Pass the message to next hop to finally reach to new_first_friend. */ | 5163 | /* Pass the message to next hop to finally reach to new_first_friend. */ |
5131 | next_hop = GDS_ROUTING_get_next_hop (trail_id, GDS_ROUTING_SRC_TO_DEST); | 5164 | next_hop = GDS_ROUTING_get_next_hop (trail_id, GDS_ROUTING_SRC_TO_DEST); |
5132 | 5165 | ||
5133 | if (NULL == next_hop) | 5166 | if (NULL == next_hop) |
5134 | { | 5167 | { |
5135 | GNUNET_break (0); | 5168 | GNUNET_break (0); |
5136 | return GNUNET_OK; | 5169 | return GNUNET_OK; |
5137 | } | 5170 | } |
5138 | 5171 | ||
5139 | GNUNET_assert (NULL != | 5172 | GNUNET_assert (NULL != |
5140 | (target_friend = | 5173 | (target_friend = |
5141 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop))); | 5174 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop))); |
5142 | 5175 | ||
5143 | GDS_ROUTING_remove_trail (trail_id); | 5176 | GDS_ROUTING_remove_trail (trail_id); |
5144 | 5177 | ||
5145 | GDS_NEIGHBOURS_send_trail_compression (trail_compression->source_peer, | 5178 | GDS_NEIGHBOURS_send_trail_compression (trail_compression->source_peer, |
5146 | trail_id, | 5179 | trail_id, |
5147 | trail_compression->new_first_friend, | 5180 | trail_compression->new_first_friend, |
@@ -5154,7 +5187,7 @@ handle_dht_p2p_trail_compression (void *cls, const struct GNUNET_PeerIdentity *p | |||
5154 | * Core handler for trail teardown message. | 5187 | * Core handler for trail teardown message. |
5155 | * @param cls closure | 5188 | * @param cls closure |
5156 | * @param message message | 5189 | * @param message message |
5157 | * @param peer sender of this messsage. | 5190 | * @param peer sender of this messsage. |
5158 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 5191 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
5159 | */ | 5192 | */ |
5160 | static int | 5193 | static int |
@@ -5166,24 +5199,24 @@ handle_dht_p2p_trail_teardown (void *cls, const struct GNUNET_PeerIdentity *peer | |||
5166 | struct GNUNET_HashCode trail_id; | 5199 | struct GNUNET_HashCode trail_id; |
5167 | struct GNUNET_PeerIdentity *next_hop; | 5200 | struct GNUNET_PeerIdentity *next_hop; |
5168 | size_t msize; | 5201 | size_t msize; |
5169 | 5202 | ||
5170 | msize = ntohs (message->size); | 5203 | msize = ntohs (message->size); |
5171 | 5204 | ||
5172 | /* Here we pass only the trail id. */ | 5205 | /* Here we pass only the trail id. */ |
5173 | if (msize != sizeof (struct PeerTrailTearDownMessage)) | 5206 | if (msize != sizeof (struct PeerTrailTearDownMessage)) |
5174 | { | 5207 | { |
5175 | GNUNET_break_op (0); | 5208 | GNUNET_break_op (0); |
5176 | return GNUNET_OK; | 5209 | return GNUNET_OK; |
5177 | } | 5210 | } |
5178 | 5211 | ||
5179 | trail_teardown = (const struct PeerTrailTearDownMessage *) message; | 5212 | trail_teardown = (const struct PeerTrailTearDownMessage *) message; |
5180 | trail_direction = ntohl (trail_teardown->trail_direction); | 5213 | trail_direction = ntohl (trail_teardown->trail_direction); |
5181 | trail_id = trail_teardown->trail_id; | 5214 | trail_id = trail_teardown->trail_id; |
5182 | 5215 | ||
5183 | /* Check if peer is the real peer from which we should get this message.*/ | 5216 | /* Check if peer is the real peer from which we should get this message.*/ |
5184 | /* Get the prev_hop for this trail by getting the next hop in opposite direction. */ | 5217 | /* Get the prev_hop for this trail by getting the next hop in opposite direction. */ |
5185 | #if 0 | 5218 | #if 0 |
5186 | GNUNET_assert (NULL != (prev_hop = | 5219 | GNUNET_assert (NULL != (prev_hop = |
5187 | GDS_ROUTING_get_next_hop (trail_id, !trail_direction))); | 5220 | GDS_ROUTING_get_next_hop (trail_id, !trail_direction))); |
5188 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (prev_hop, peer)) | 5221 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (prev_hop, peer)) |
5189 | { | 5222 | { |
@@ -5191,35 +5224,35 @@ handle_dht_p2p_trail_teardown (void *cls, const struct GNUNET_PeerIdentity *peer | |||
5191 | return GNUNET_SYSERR; | 5224 | return GNUNET_SYSERR; |
5192 | } | 5225 | } |
5193 | #endif | 5226 | #endif |
5194 | 5227 | ||
5195 | next_hop = GDS_ROUTING_get_next_hop (trail_id, trail_direction); | 5228 | next_hop = GDS_ROUTING_get_next_hop (trail_id, trail_direction); |
5196 | 5229 | ||
5197 | if (NULL == next_hop) | 5230 | if (NULL == next_hop) |
5198 | { | 5231 | { |
5199 | GNUNET_break (0); | 5232 | GNUNET_break (0); |
5200 | return GNUNET_SYSERR; | 5233 | return GNUNET_SYSERR; |
5201 | } | 5234 | } |
5202 | 5235 | ||
5203 | /* I am the next hop, which means I am the final destination. */ | 5236 | /* I am the next hop, which means I am the final destination. */ |
5204 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (next_hop, &my_identity)) | 5237 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (next_hop, &my_identity)) |
5205 | { | 5238 | { |
5206 | GNUNET_assert (GNUNET_YES == GDS_ROUTING_remove_trail (trail_id)); | 5239 | GNUNET_assert (GNUNET_YES == GDS_ROUTING_remove_trail (trail_id)); |
5207 | return GNUNET_OK; | 5240 | return GNUNET_OK; |
5208 | } | 5241 | } |
5209 | else | 5242 | else |
5210 | { | 5243 | { |
5211 | /* If not final destination, then send a trail teardown message to next hop.*/ | 5244 | /* If not final destination, then send a trail teardown message to next hop.*/ |
5212 | GNUNET_assert (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop)); | 5245 | GNUNET_assert (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop)); |
5213 | GNUNET_assert (GNUNET_YES == GDS_ROUTING_remove_trail (trail_id)); | 5246 | GNUNET_assert (GNUNET_YES == GDS_ROUTING_remove_trail (trail_id)); |
5214 | GDS_NEIGHBOURS_send_trail_teardown (trail_id, trail_direction, *next_hop); | 5247 | GDS_NEIGHBOURS_send_trail_teardown (trail_id, trail_direction, *next_hop); |
5215 | } | 5248 | } |
5216 | 5249 | ||
5217 | return GNUNET_OK; | 5250 | return GNUNET_OK; |
5218 | } | 5251 | } |
5219 | 5252 | ||
5220 | 5253 | ||
5221 | /** | 5254 | /** |
5222 | * Core handle for p2p add trail message. | 5255 | * Core handle for p2p add trail message. |
5223 | * @param cls closure | 5256 | * @param cls closure |
5224 | * @param message message | 5257 | * @param message message |
5225 | * @param peer peer identity this notification is about | 5258 | * @param peer peer identity this notification is about |
@@ -5251,12 +5284,12 @@ handle_dht_p2p_add_trail (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
5251 | add_trail = (const struct PeerAddTrailMessage *) message; | 5284 | add_trail = (const struct PeerAddTrailMessage *) message; |
5252 | trail_length = (msize - sizeof (struct PeerAddTrailMessage))/ | 5285 | trail_length = (msize - sizeof (struct PeerAddTrailMessage))/ |
5253 | sizeof (struct GNUNET_PeerIdentity); | 5286 | sizeof (struct GNUNET_PeerIdentity); |
5254 | if ((msize - sizeof (struct PeerAddTrailMessage)) % | 5287 | if ((msize - sizeof (struct PeerAddTrailMessage)) % |
5255 | sizeof (struct GNUNET_PeerIdentity) != 0) | 5288 | sizeof (struct GNUNET_PeerIdentity) != 0) |
5256 | { | 5289 | { |
5257 | GNUNET_break_op (0); | 5290 | GNUNET_break_op (0); |
5258 | return GNUNET_OK; | 5291 | return GNUNET_OK; |
5259 | } | 5292 | } |
5260 | 5293 | ||
5261 | trail = (const struct GNUNET_PeerIdentity *)&add_trail[1]; | 5294 | trail = (const struct GNUNET_PeerIdentity *)&add_trail[1]; |
5262 | destination_peer = add_trail->destination_peer; | 5295 | destination_peer = add_trail->destination_peer; |
@@ -5266,35 +5299,35 @@ handle_dht_p2p_add_trail (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
5266 | //FIXME: add a check that sender peer is not malicious. Make it a generic | 5299 | //FIXME: add a check that sender peer is not malicious. Make it a generic |
5267 | // function so that it can be used in all other functions where we need the | 5300 | // function so that it can be used in all other functions where we need the |
5268 | // same functionality. | 5301 | // same functionality. |
5269 | 5302 | ||
5270 | /* I am not the destination of the trail. */ | 5303 | /* I am not the destination of the trail. */ |
5271 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &destination_peer)) | 5304 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &destination_peer)) |
5272 | { | 5305 | { |
5273 | struct FriendInfo *target_friend; | 5306 | struct FriendInfo *target_friend; |
5274 | 5307 | ||
5275 | /* Get my location in the trail. */ | 5308 | /* Get my location in the trail. */ |
5276 | my_index = search_my_index (trail, trail_length); | 5309 | my_index = search_my_index (trail, trail_length); |
5277 | if (-1 == my_index) | 5310 | if (-1 == my_index) |
5278 | { | 5311 | { |
5279 | 5312 | ||
5280 | GNUNET_break_op (0); | 5313 | GNUNET_break_op (0); |
5281 | return GNUNET_SYSERR; | 5314 | return GNUNET_SYSERR; |
5282 | } | 5315 | } |
5283 | 5316 | ||
5284 | 5317 | ||
5285 | if ((trail_length - 1) == my_index) | 5318 | if ((trail_length - 1) == my_index) |
5286 | { | 5319 | { |
5287 | next_hop = destination_peer; | 5320 | next_hop = destination_peer; |
5288 | } | 5321 | } |
5289 | else | 5322 | else |
5290 | { | 5323 | { |
5291 | next_hop = trail[my_index + 1]; | 5324 | next_hop = trail[my_index + 1]; |
5292 | } | 5325 | } |
5293 | 5326 | ||
5294 | /* Add in your routing table. */ | 5327 | /* Add in your routing table. */ |
5295 | GNUNET_assert (GNUNET_OK == GDS_ROUTING_add (trail_id, next_hop, *peer)); | 5328 | GNUNET_assert (GNUNET_OK == GDS_ROUTING_add (trail_id, next_hop, *peer)); |
5296 | GNUNET_assert (NULL != | 5329 | GNUNET_assert (NULL != |
5297 | (target_friend = | 5330 | (target_friend = |
5298 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop))); | 5331 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop))); |
5299 | GDS_NEIGHBOURS_send_add_trail (source_peer, destination_peer, trail_id, | 5332 | GDS_NEIGHBOURS_send_add_trail (source_peer, destination_peer, trail_id, |
5300 | trail, trail_length, target_friend); | 5333 | trail, trail_length, target_friend); |
@@ -5307,11 +5340,11 @@ handle_dht_p2p_add_trail (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
5307 | 5340 | ||
5308 | 5341 | ||
5309 | /** | 5342 | /** |
5310 | * Free the finger trail in which the first friend to reach to a finger is | 5343 | * Free the finger trail in which the first friend to reach to a finger is |
5311 | * disconnected_friend. Also remove entry from routing table for that particular | 5344 | * disconnected_friend. Also remove entry from routing table for that particular |
5312 | * trail id. | 5345 | * trail id. |
5313 | * @param disconnected_friend PeerIdentity of friend which got disconnected | 5346 | * @param disconnected_friend PeerIdentity of friend which got disconnected |
5314 | * @param remove_finger Finger whose trail we need to check if it has | 5347 | * @param remove_finger Finger whose trail we need to check if it has |
5315 | * disconnected_friend as the first hop. | 5348 | * disconnected_friend as the first hop. |
5316 | * @return Total number of trails in which disconnected_friend was the first | 5349 | * @return Total number of trails in which disconnected_friend was the first |
5317 | * hop. | 5350 | * hop. |
@@ -5322,67 +5355,67 @@ remove_matching_trails (const struct GNUNET_PeerIdentity *disconnected_friend, | |||
5322 | { | 5355 | { |
5323 | unsigned int matching_trails_count; | 5356 | unsigned int matching_trails_count; |
5324 | int i; | 5357 | int i; |
5325 | 5358 | ||
5326 | /* Number of trails with disconnected_friend as the first hop in the trail | 5359 | /* Number of trails with disconnected_friend as the first hop in the trail |
5327 | * to reach from me to remove_finger, NOT including endpoints. */ | 5360 | * to reach from me to remove_finger, NOT including endpoints. */ |
5328 | matching_trails_count = 0; | 5361 | matching_trails_count = 0; |
5329 | 5362 | ||
5330 | /* Iterate over all the trails of finger. */ | 5363 | /* Iterate over all the trails of finger. */ |
5331 | for (i = 0; i < remove_finger->trails_count; i++) | 5364 | for (i = 0; i < remove_finger->trails_count; i++) |
5332 | { | 5365 | { |
5333 | struct Trail *trail; | 5366 | struct Trail *trail; |
5334 | trail = &remove_finger->trail_list[i]; | 5367 | trail = &remove_finger->trail_list[i]; |
5335 | 5368 | ||
5336 | /* This assertion is ensure that there are no gaps in the trail list. | 5369 | /* This assertion is ensure that there are no gaps in the trail list. |
5337 | REMOVE IT AFTERWARDS. */ | 5370 | REMOVE IT AFTERWARDS. */ |
5338 | GNUNET_assert (GNUNET_YES == trail->is_present); | 5371 | GNUNET_assert (GNUNET_YES == trail->is_present); |
5339 | 5372 | ||
5340 | /* First friend to reach to finger is disconnected_peer. */ | 5373 | /* First friend to reach to finger is disconnected_peer. */ |
5341 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&trail->trail_head->peer, | 5374 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&trail->trail_head->peer, |
5342 | disconnected_friend)) | 5375 | disconnected_friend)) |
5343 | { | 5376 | { |
5344 | struct GNUNET_PeerIdentity *next_hop; | 5377 | struct GNUNET_PeerIdentity *next_hop; |
5345 | struct FriendInfo *remove_friend; | 5378 | struct FriendInfo *remove_friend; |
5346 | 5379 | ||
5347 | GNUNET_assert (NULL != | 5380 | GNUNET_assert (NULL != |
5348 | (remove_friend = | 5381 | (remove_friend = |
5349 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 5382 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
5350 | disconnected_friend))); | 5383 | disconnected_friend))); |
5351 | /* FIXME: removing no but check it. */ | 5384 | /* FIXME: removing no but check it. */ |
5352 | //remove_friend->trails_count--; | 5385 | //remove_friend->trails_count--; |
5353 | next_hop = GDS_ROUTING_get_next_hop (trail->trail_id, | 5386 | next_hop = GDS_ROUTING_get_next_hop (trail->trail_id, |
5354 | GDS_ROUTING_SRC_TO_DEST); | 5387 | GDS_ROUTING_SRC_TO_DEST); |
5355 | 5388 | ||
5356 | /* Here it may happen that as all the peers got disconnected, the entry in | 5389 | /* Here it may happen that as all the peers got disconnected, the entry in |
5357 | routing table for that particular trail has been removed, because the | 5390 | routing table for that particular trail has been removed, because the |
5358 | previously disconnected peer was either a next hop or prev hop of that | 5391 | previously disconnected peer was either a next hop or prev hop of that |
5359 | peer. */ | 5392 | peer. */ |
5360 | if (NULL == next_hop) | 5393 | if (NULL == next_hop) |
5361 | continue; | 5394 | continue; |
5362 | 5395 | ||
5363 | GNUNET_assert (0 == (GNUNET_CRYPTO_cmp_peer_identity (disconnected_friend, | 5396 | GNUNET_assert (0 == (GNUNET_CRYPTO_cmp_peer_identity (disconnected_friend, |
5364 | next_hop))); | 5397 | next_hop))); |
5365 | matching_trails_count++; | 5398 | matching_trails_count++; |
5366 | GNUNET_assert (GNUNET_YES == GDS_ROUTING_remove_trail (trail->trail_id)); | 5399 | GNUNET_assert (GNUNET_YES == GDS_ROUTING_remove_trail (trail->trail_id)); |
5367 | 5400 | ||
5368 | free_trail (trail); | 5401 | free_trail (trail); |
5369 | trail->is_present = GNUNET_NO; | 5402 | trail->is_present = GNUNET_NO; |
5370 | } | 5403 | } |
5371 | } | 5404 | } |
5372 | return matching_trails_count; | 5405 | return matching_trails_count; |
5373 | } | 5406 | } |
5374 | 5407 | ||
5375 | 5408 | ||
5376 | /** | 5409 | /** |
5377 | * Iterate over finger_table entries. | 5410 | * Iterate over finger_table entries. |
5378 | * 0. Ignore finger which is my_identity or if no valid entry present at | 5411 | * 0. Ignore finger which is my_identity or if no valid entry present at |
5379 | * that finger index. | 5412 | * that finger index. |
5380 | * 1. If disconnected_friend is a finger, then remove the routing entry from | 5413 | * 1. If disconnected_friend is a finger, then remove the routing entry from |
5381 | your own table. Free the trail. | 5414 | your own table. Free the trail. |
5382 | * 2. Check if disconnected_friend is the first friend in the trail to reach to a finger. | 5415 | * 2. Check if disconnected_friend is the first friend in the trail to reach to a finger. |
5383 | * 2.1 Remove all the trails and entry from routing table in which disconnected | 5416 | * 2.1 Remove all the trails and entry from routing table in which disconnected |
5384 | * friend is the first friend in the trail. If disconnected_friend is the | 5417 | * friend is the first friend in the trail. If disconnected_friend is the |
5385 | * first friend in all the trails to reach finger, then remove the finger. | 5418 | * first friend in all the trails to reach finger, then remove the finger. |
5386 | * @param disconnected_friend Peer identity of friend which got disconnected. | 5419 | * @param disconnected_friend Peer identity of friend which got disconnected. |
5387 | */ | 5420 | */ |
5388 | static void | 5421 | static void |
@@ -5392,7 +5425,7 @@ remove_matching_fingers (const struct GNUNET_PeerIdentity *disconnected_peer) | |||
5392 | struct FriendInfo *remove_friend; | 5425 | struct FriendInfo *remove_friend; |
5393 | int removed_trails_count; | 5426 | int removed_trails_count; |
5394 | int i; | 5427 | int i; |
5395 | 5428 | ||
5396 | /* Iterate over finger table entries. */ | 5429 | /* Iterate over finger table entries. */ |
5397 | for (i = 0; i < MAX_FINGERS; i++) | 5430 | for (i = 0; i < MAX_FINGERS; i++) |
5398 | { | 5431 | { |
@@ -5401,25 +5434,25 @@ remove_matching_fingers (const struct GNUNET_PeerIdentity *disconnected_peer) | |||
5401 | /* No finger stored at this trail index. */ | 5434 | /* No finger stored at this trail index. */ |
5402 | if (GNUNET_NO == remove_finger->is_present) | 5435 | if (GNUNET_NO == remove_finger->is_present) |
5403 | continue; | 5436 | continue; |
5404 | 5437 | ||
5405 | /* I am my own finger, then ignore this finger. */ | 5438 | /* I am my own finger, then ignore this finger. */ |
5406 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&remove_finger->finger_identity, | 5439 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&remove_finger->finger_identity, |
5407 | &my_identity)) | 5440 | &my_identity)) |
5408 | continue; | 5441 | continue; |
5409 | 5442 | ||
5410 | /* Is disconnected_peer a finger? */ | 5443 | /* Is disconnected_peer a finger? */ |
5411 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (disconnected_peer, | 5444 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (disconnected_peer, |
5412 | &remove_finger->finger_identity)) | 5445 | &remove_finger->finger_identity)) |
5413 | { | 5446 | { |
5414 | struct GNUNET_PeerIdentity *next_hop; | 5447 | struct GNUNET_PeerIdentity *next_hop; |
5415 | struct GNUNET_HashCode trail_id; | 5448 | struct GNUNET_HashCode trail_id; |
5416 | 5449 | ||
5417 | 5450 | ||
5418 | GNUNET_assert (GNUNET_YES == (remove_finger->trail_list[0].is_present)); | 5451 | GNUNET_assert (GNUNET_YES == (remove_finger->trail_list[0].is_present)); |
5419 | trail_id = remove_finger->trail_list[0].trail_id; | 5452 | trail_id = remove_finger->trail_list[0].trail_id; |
5420 | 5453 | ||
5421 | if(NULL != | 5454 | if(NULL != |
5422 | (next_hop = | 5455 | (next_hop = |
5423 | GDS_ROUTING_get_next_hop (trail_id, GDS_ROUTING_SRC_TO_DEST))) | 5456 | GDS_ROUTING_get_next_hop (trail_id, GDS_ROUTING_SRC_TO_DEST))) |
5424 | { | 5457 | { |
5425 | GNUNET_assert (0 == | 5458 | GNUNET_assert (0 == |
@@ -5427,11 +5460,11 @@ remove_matching_fingers (const struct GNUNET_PeerIdentity *disconnected_peer) | |||
5427 | &remove_finger->finger_identity))); | 5460 | &remove_finger->finger_identity))); |
5428 | GNUNET_assert (GNUNET_YES == GDS_ROUTING_remove_trail (trail_id)); | 5461 | GNUNET_assert (GNUNET_YES == GDS_ROUTING_remove_trail (trail_id)); |
5429 | GNUNET_assert (NULL != | 5462 | GNUNET_assert (NULL != |
5430 | (remove_friend = | 5463 | (remove_friend = |
5431 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 5464 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
5432 | disconnected_peer))); | 5465 | disconnected_peer))); |
5433 | } | 5466 | } |
5434 | 5467 | ||
5435 | remove_finger->trail_list[0].is_present = GNUNET_NO; | 5468 | remove_finger->trail_list[0].is_present = GNUNET_NO; |
5436 | //GNUNET_assert (0 != remove_friend->trails_count); | 5469 | //GNUNET_assert (0 != remove_friend->trails_count); |
5437 | //remove_friend->trails_count--; //FIXME; CHECK WHY IT FAILS AND THEN UNCOMMENT. | 5470 | //remove_friend->trails_count--; //FIXME; CHECK WHY IT FAILS AND THEN UNCOMMENT. |
@@ -5439,17 +5472,17 @@ remove_matching_fingers (const struct GNUNET_PeerIdentity *disconnected_peer) | |||
5439 | memset ((void *)&finger_table[i], 0, sizeof (finger_table[i])); | 5472 | memset ((void *)&finger_table[i], 0, sizeof (finger_table[i])); |
5440 | continue; | 5473 | continue; |
5441 | } | 5474 | } |
5442 | 5475 | ||
5443 | /* If finger is a friend but not disconnected_friend, then continue. */ | 5476 | /* If finger is a friend but not disconnected_friend, then continue. */ |
5444 | if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 5477 | if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
5445 | &remove_finger->finger_identity)) | 5478 | &remove_finger->finger_identity)) |
5446 | continue; | 5479 | continue; |
5447 | 5480 | ||
5448 | /* Iterate over the list of trails to reach remove_finger. Check if | 5481 | /* Iterate over the list of trails to reach remove_finger. Check if |
5449 | * disconnected_friend is the first friend in any of the trail. */ | 5482 | * disconnected_friend is the first friend in any of the trail. */ |
5450 | removed_trails_count = remove_matching_trails (disconnected_peer, | 5483 | removed_trails_count = remove_matching_trails (disconnected_peer, |
5451 | remove_finger); | 5484 | remove_finger); |
5452 | remove_finger->trails_count = | 5485 | remove_finger->trails_count = |
5453 | remove_finger->trails_count - removed_trails_count; | 5486 | remove_finger->trails_count - removed_trails_count; |
5454 | /* All the finger trails had disconnected_friend as the first friend, | 5487 | /* All the finger trails had disconnected_friend as the first friend, |
5455 | * so free the finger. */ | 5488 | * so free the finger. */ |
@@ -5457,7 +5490,7 @@ remove_matching_fingers (const struct GNUNET_PeerIdentity *disconnected_peer) | |||
5457 | { | 5490 | { |
5458 | remove_finger->is_present = GNUNET_NO; | 5491 | remove_finger->is_present = GNUNET_NO; |
5459 | memset ((void *)&finger_table[i], 0, sizeof (finger_table[i])); | 5492 | memset ((void *)&finger_table[i], 0, sizeof (finger_table[i])); |
5460 | } | 5493 | } |
5461 | } | 5494 | } |
5462 | } | 5495 | } |
5463 | 5496 | ||
@@ -5483,23 +5516,23 @@ handle_core_disconnect (void *cls, | |||
5483 | 5516 | ||
5484 | /* Remove fingers with peer as first friend or if peer is a finger. */ | 5517 | /* Remove fingers with peer as first friend or if peer is a finger. */ |
5485 | remove_matching_fingers (peer); | 5518 | remove_matching_fingers (peer); |
5486 | 5519 | ||
5487 | /* Remove any trail from routing table of which peer is a part of. This function | 5520 | /* Remove any trail from routing table of which peer is a part of. This function |
5488 | * internally sends a trail teardown message in the direction of which | 5521 | * internally sends a trail teardown message in the direction of which |
5489 | * disconnected peer is not part of. */ | 5522 | * disconnected peer is not part of. */ |
5490 | GNUNET_assert (GNUNET_SYSERR != GDS_ROUTING_remove_trail_by_peer (peer)); | 5523 | GNUNET_assert (GNUNET_SYSERR != GDS_ROUTING_remove_trail_by_peer (peer)); |
5491 | 5524 | ||
5492 | //GNUNET_assert (0 == remove_friend->trails_count); //FIXME; why should this fai. | 5525 | //GNUNET_assert (0 == remove_friend->trails_count); //FIXME; why should this fai. |
5493 | 5526 | ||
5494 | /* Remove peer from friend_peermap. */ | 5527 | /* Remove peer from friend_peermap. */ |
5495 | GNUNET_assert (GNUNET_YES == | 5528 | GNUNET_assert (GNUNET_YES == |
5496 | GNUNET_CONTAINER_multipeermap_remove (friend_peermap, | 5529 | GNUNET_CONTAINER_multipeermap_remove (friend_peermap, |
5497 | peer, | 5530 | peer, |
5498 | remove_friend)); | 5531 | remove_friend)); |
5499 | 5532 | ||
5500 | if (0 != GNUNET_CONTAINER_multipeermap_size (friend_peermap)) | 5533 | if (0 != GNUNET_CONTAINER_multipeermap_size (friend_peermap)) |
5501 | return; | 5534 | return; |
5502 | 5535 | ||
5503 | if (GNUNET_SCHEDULER_NO_TASK != find_finger_trail_task) | 5536 | if (GNUNET_SCHEDULER_NO_TASK != find_finger_trail_task) |
5504 | { | 5537 | { |
5505 | GNUNET_SCHEDULER_cancel (find_finger_trail_task); | 5538 | GNUNET_SCHEDULER_cancel (find_finger_trail_task); |
@@ -5529,7 +5562,7 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer_identity) | |||
5529 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected to %s\n", GNUNET_i2s (peer_identity)); | 5562 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected to %s\n", GNUNET_i2s (peer_identity)); |
5530 | 5563 | ||
5531 | /* If peer already exists in our friend_peermap, then exit. */ | 5564 | /* If peer already exists in our friend_peermap, then exit. */ |
5532 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (friend_peermap, | 5565 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (friend_peermap, |
5533 | peer_identity)) | 5566 | peer_identity)) |
5534 | { | 5567 | { |
5535 | GNUNET_break (0); | 5568 | GNUNET_break (0); |
@@ -5548,8 +5581,8 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer_identity) | |||
5548 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 5581 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
5549 | 5582 | ||
5550 | 5583 | ||
5551 | /* got a first connection, good time to start with FIND FINGER TRAIL requests...*/ | 5584 | /* got a first connection, good time to start with FIND FINGER TRAIL requests...*/ |
5552 | if (GNUNET_SCHEDULER_NO_TASK == find_finger_trail_task) | 5585 | if (GNUNET_SCHEDULER_NO_TASK == find_finger_trail_task) |
5553 | find_finger_trail_task = GNUNET_SCHEDULER_add_now (&send_find_finger_trail_message, NULL); | 5586 | find_finger_trail_task = GNUNET_SCHEDULER_add_now (&send_find_finger_trail_message, NULL); |
5554 | } | 5587 | } |
5555 | 5588 | ||
@@ -5565,7 +5598,7 @@ core_init (void *cls, | |||
5565 | const struct GNUNET_PeerIdentity *identity) | 5598 | const struct GNUNET_PeerIdentity *identity) |
5566 | { | 5599 | { |
5567 | my_identity = *identity; | 5600 | my_identity = *identity; |
5568 | 5601 | ||
5569 | uint64_t my_id64; | 5602 | uint64_t my_id64; |
5570 | memcpy (&my_id64, &my_identity, sizeof (uint64_t)); | 5603 | memcpy (&my_id64, &my_identity, sizeof (uint64_t)); |
5571 | my_id64 = GNUNET_ntohll (my_id64); | 5604 | my_id64 = GNUNET_ntohll (my_id64); |
@@ -5581,16 +5614,7 @@ core_init (void *cls, | |||
5581 | static void | 5614 | static void |
5582 | finger_table_init () | 5615 | finger_table_init () |
5583 | { | 5616 | { |
5584 | unsigned int i; | 5617 | memset (&finger_table, 0, sizeof (finger_table)); |
5585 | unsigned int j; | ||
5586 | |||
5587 | for(i = 0; i < MAX_FINGERS; i++) | ||
5588 | { | ||
5589 | finger_table[i].is_present = GNUNET_NO; | ||
5590 | for (j = 0; j < MAXIMUM_TRAILS_PER_FINGER; j++) | ||
5591 | finger_table[i].trail_list[j].is_present = GNUNET_NO; | ||
5592 | memset ((void *)&finger_table[i], 0, sizeof (finger_table[i])); | ||
5593 | } | ||
5594 | } | 5618 | } |
5595 | 5619 | ||
5596 | 5620 | ||
@@ -5611,9 +5635,9 @@ GDS_NEIGHBOURS_init (void) | |||
5611 | {&handle_dht_p2p_verify_successor_result, GNUNET_MESSAGE_TYPE_XDHT_P2P_VERIFY_SUCCESSOR_RESULT, 0}, | 5635 | {&handle_dht_p2p_verify_successor_result, GNUNET_MESSAGE_TYPE_XDHT_P2P_VERIFY_SUCCESSOR_RESULT, 0}, |
5612 | {&handle_dht_p2p_notify_new_successor, GNUNET_MESSAGE_TYPE_XDHT_P2P_NOTIFY_NEW_SUCCESSOR, 0}, | 5636 | {&handle_dht_p2p_notify_new_successor, GNUNET_MESSAGE_TYPE_XDHT_P2P_NOTIFY_NEW_SUCCESSOR, 0}, |
5613 | {&handle_dht_p2p_trail_setup_rejection, GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_SETUP_REJECTION, 0}, | 5637 | {&handle_dht_p2p_trail_setup_rejection, GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_SETUP_REJECTION, 0}, |
5614 | {&handle_dht_p2p_trail_compression, GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_COMPRESSION, | 5638 | {&handle_dht_p2p_trail_compression, GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_COMPRESSION, |
5615 | sizeof (struct PeerTrailCompressionMessage)}, | 5639 | sizeof (struct PeerTrailCompressionMessage)}, |
5616 | {&handle_dht_p2p_trail_teardown, GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_TEARDOWN, | 5640 | {&handle_dht_p2p_trail_teardown, GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_TEARDOWN, |
5617 | sizeof (struct PeerTrailTearDownMessage)}, | 5641 | sizeof (struct PeerTrailTearDownMessage)}, |
5618 | {&handle_dht_p2p_add_trail, GNUNET_MESSAGE_TYPE_XDHT_P2P_ADD_TRAIL, 0}, | 5642 | {&handle_dht_p2p_add_trail, GNUNET_MESSAGE_TYPE_XDHT_P2P_ADD_TRAIL, 0}, |
5619 | {NULL, 0, 0} | 5643 | {NULL, 0, 0} |
@@ -5628,7 +5652,7 @@ GDS_NEIGHBOURS_init (void) | |||
5628 | 5652 | ||
5629 | friend_peermap = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_NO); | 5653 | friend_peermap = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_NO); |
5630 | finger_table_init (); | 5654 | finger_table_init (); |
5631 | 5655 | ||
5632 | return GNUNET_OK; | 5656 | return GNUNET_OK; |
5633 | } | 5657 | } |
5634 | 5658 | ||
@@ -5655,7 +5679,7 @@ GDS_NEIGHBOURS_done (void) | |||
5655 | GNUNET_SCHEDULER_cancel (find_finger_trail_task); | 5679 | GNUNET_SCHEDULER_cancel (find_finger_trail_task); |
5656 | find_finger_trail_task = GNUNET_SCHEDULER_NO_TASK; | 5680 | find_finger_trail_task = GNUNET_SCHEDULER_NO_TASK; |
5657 | } | 5681 | } |
5658 | 5682 | ||
5659 | if (GNUNET_SCHEDULER_NO_TASK != send_verify_successor_task) | 5683 | if (GNUNET_SCHEDULER_NO_TASK != send_verify_successor_task) |
5660 | { | 5684 | { |
5661 | GNUNET_SCHEDULER_cancel (send_verify_successor_task); | 5685 | GNUNET_SCHEDULER_cancel (send_verify_successor_task); |
@@ -5675,4 +5699,4 @@ GDS_NEIGHBOURS_get_my_id (void) | |||
5675 | return my_identity; | 5699 | return my_identity; |
5676 | } | 5700 | } |
5677 | 5701 | ||
5678 | /* end of gnunet-service-xdht_neighbours.c */ \ No newline at end of file | 5702 | /* end of gnunet-service-xdht_neighbours.c */ |