diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-04-14 12:12:13 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-04-14 12:12:13 +0000 |
commit | 81c9bad6197621eddc27d885827ca47f31cf9704 (patch) | |
tree | e641aec30731610cdac31d5ce434e7bf8e55c9f7 /src/hostlist/hostlist-client.c | |
parent | 57479e3227639e2e7a6eda9c31ca6b65528d3739 (diff) | |
download | gnunet-81c9bad6197621eddc27d885827ca47f31cf9704.tar.gz gnunet-81c9bad6197621eddc27d885827ca47f31cf9704.zip |
Diffstat (limited to 'src/hostlist/hostlist-client.c')
-rw-r--r-- | src/hostlist/hostlist-client.c | 47 |
1 files changed, 36 insertions, 11 deletions
diff --git a/src/hostlist/hostlist-client.c b/src/hostlist/hostlist-client.c index e11595352..a496588db 100644 --- a/src/hostlist/hostlist-client.c +++ b/src/hostlist/hostlist-client.c | |||
@@ -759,12 +759,24 @@ advertisement_handler (void *cls, | |||
759 | "Hostlist client recieved advertisement from '%s' containing URI %s\n", GNUNET_i2s (peer), uri ); | 759 | "Hostlist client recieved advertisement from '%s' containing URI %s\n", GNUNET_i2s (peer), uri ); |
760 | 760 | ||
761 | /* search in map for peer identity */ | 761 | /* search in map for peer identity */ |
762 | hostlist = GNUNET_malloc ( sizeof (struct GNUNET_Hostlist) ); | ||
763 | hostlist = GNUNET_malloc ( sizeof (struct GNUNET_Hostlist) ); | ||
764 | hostlist->peer = (*peer); | ||
765 | hostlist->hello_count = 0; | ||
766 | hostlist->hostlist_uri = GNUNET_malloc ( uri_size); | ||
767 | memcpy ( hostlist->hostlist_uri, &incoming[1], uri_size ); | ||
768 | hostlist->time_creation = GNUNET_TIME_absolute_get(); | ||
769 | hostlist->time_last_usage = GNUNET_TIME_absolute_get_zero(); | ||
770 | |||
762 | GNUNET_HashCode * peer_ident_hash = (GNUNET_HashCode * ) &(peer->hashPubKey); | 771 | GNUNET_HashCode * peer_ident_hash = (GNUNET_HashCode * ) &(peer->hashPubKey); |
763 | if ( GNUNET_YES != GNUNET_CONTAINER_multihashmap_contains (hostlist_hashmap, peer_ident_hash) ) | 772 | if ( GNUNET_YES != GNUNET_CONTAINER_multihashmap_contains (hostlist_hashmap, peer_ident_hash) ) |
764 | { | 773 | { |
765 | if ( MAX_NUMBER_HOSTLISTS > GNUNET_CONTAINER_multihashmap_size (hostlist_hashmap) ) | 774 | if ( MAX_NUMBER_HOSTLISTS > GNUNET_CONTAINER_multihashmap_size (hostlist_hashmap) ) |
766 | { | 775 | { |
767 | /* Entries available, add hostlist to hashmap */ | 776 | /* Entries available, add hostlist to hashmap */ |
777 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
778 | "Adding peer '%s' to hashmap %s\n", GNUNET_i2s (peer), uri ); | ||
779 | GNUNET_CONTAINER_multihashmap_put ( hostlist_hashmap, peer_ident_hash, hostlist, GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE ); | ||
768 | } | 780 | } |
769 | else | 781 | else |
770 | { | 782 | { |
@@ -778,16 +790,6 @@ advertisement_handler (void *cls, | |||
778 | /* update recieved date (vs using last download time to check reachability)? */ | 790 | /* update recieved date (vs using last download time to check reachability)? */ |
779 | } | 791 | } |
780 | 792 | ||
781 | /* GNUNET_CONTAINER_multihashmap_contains( hostlist_hashmap, )*/ | ||
782 | /* if it is not existing in map, create new a hostlist */ | ||
783 | hostlist = GNUNET_malloc ( sizeof (struct GNUNET_Hostlist) ); | ||
784 | hostlist->peer = (*peer); | ||
785 | hostlist->hello_count = 0; | ||
786 | hostlist->hostlist_uri = GNUNET_malloc ( uri_size); | ||
787 | memcpy ( hostlist->hostlist_uri, &incoming[1], uri_size ); | ||
788 | hostlist->time_creation = GNUNET_TIME_absolute_get(); | ||
789 | hostlist->time_last_usage = GNUNET_TIME_absolute_get_zero(); | ||
790 | |||
791 | return GNUNET_YES; | 793 | return GNUNET_YES; |
792 | } | 794 | } |
793 | 795 | ||
@@ -866,6 +868,23 @@ static int load_hostlist_file () | |||
866 | return GNUNET_OK; | 868 | return GNUNET_OK; |
867 | } | 869 | } |
868 | 870 | ||
871 | |||
872 | static int iterate_hashmap(void *cls, const GNUNET_HashCode *key, void *value) | ||
873 | { | ||
874 | /* add code to process hostlist entries */ | ||
875 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
876 | ("Now iterating over peer entry: %s\n"), GNUNET_i2s ( (const struct GNUNET_PeerIdentity *) key)); | ||
877 | |||
878 | /* Testing */ | ||
879 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
880 | ("Entry url: %s \n"), ((struct GNUNET_Hostlist *) value)->hostlist_uri ); | ||
881 | |||
882 | if ( NULL != value ) | ||
883 | GNUNET_free ( value ); | ||
884 | |||
885 | return GNUNET_YES; | ||
886 | } | ||
887 | |||
869 | /** | 888 | /** |
870 | * Method to load persistent hostlist file during hostlist client shutdown | 889 | * Method to load persistent hostlist file during hostlist client shutdown |
871 | * param c configuration to use | 890 | * param c configuration to use |
@@ -896,7 +915,13 @@ static int save_hostlist_file () | |||
896 | } | 915 | } |
897 | 916 | ||
898 | /* add code to write hostlists to file using bio */ | 917 | /* add code to write hostlists to file using bio */ |
899 | GNUNET_BIO_write_string ( wh, "DUMMY TEXT"); | 918 | |
919 | /* iterate over all entries in hashmap */ | ||
920 | GNUNET_CONTAINER_multihashmap_iterate ( hostlist_hashmap, | ||
921 | &iterate_hashmap, | ||
922 | NULL ); | ||
923 | |||
924 | GNUNET_BIO_write_string ( wh, "DUMMY TEXT" ); | ||
900 | 925 | ||
901 | if ( GNUNET_OK != GNUNET_BIO_write_close ( wh ) ) | 926 | if ( GNUNET_OK != GNUNET_BIO_write_close ( wh ) ) |
902 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 927 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |