diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-06-05 13:26:22 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-06-05 13:26:22 +0000 |
commit | ab1bf63f1ed7637297c90b5b284f40a797f44805 (patch) | |
tree | 64bedd1cc5620f690d6ad099c2fb4b45a9a41f03 /src/core/gnunet-service-core.c | |
parent | 446dcf7697ebdd7c78a48573a5c73fbf25448c74 (diff) | |
download | gnunet-ab1bf63f1ed7637297c90b5b284f40a797f44805.tar.gz gnunet-ab1bf63f1ed7637297c90b5b284f40a797f44805.zip |
use new transport API, minor core API change
Diffstat (limited to 'src/core/gnunet-service-core.c')
-rw-r--r-- | src/core/gnunet-service-core.c | 125 |
1 files changed, 20 insertions, 105 deletions
diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c index 7053cc603..37960f76a 100644 --- a/src/core/gnunet-service-core.c +++ b/src/core/gnunet-service-core.c | |||
@@ -2937,59 +2937,6 @@ handle_client_send (void *cls, | |||
2937 | 2937 | ||
2938 | 2938 | ||
2939 | /** | 2939 | /** |
2940 | * Function called when the transport service is ready to | ||
2941 | * receive a message. Only resets 'n->th' to NULL. | ||
2942 | * | ||
2943 | * @param cls neighbour to use message from | ||
2944 | * @param size number of bytes we can transmit | ||
2945 | * @param buf where to copy the message | ||
2946 | * @return number of bytes transmitted | ||
2947 | */ | ||
2948 | static size_t | ||
2949 | notify_transport_connect_done (void *cls, | ||
2950 | size_t size, | ||
2951 | void *buf) | ||
2952 | { | ||
2953 | struct Neighbour *n = cls; | ||
2954 | |||
2955 | n->th = NULL; | ||
2956 | if (GNUNET_YES != n->is_connected) | ||
2957 | { | ||
2958 | /* transport should only call us to transmit a message after | ||
2959 | * telling us about a successful connection to the respective peer */ | ||
2960 | #if DEBUG_CORE | ||
2961 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2962 | "Timeout on notify connect!\n"); | ||
2963 | #endif | ||
2964 | GNUNET_STATISTICS_update (stats, | ||
2965 | gettext_noop ("# connection requests timed out in transport"), | ||
2966 | 1, | ||
2967 | GNUNET_NO); | ||
2968 | return 0; | ||
2969 | } | ||
2970 | if (buf == NULL) | ||
2971 | { | ||
2972 | GNUNET_STATISTICS_update (stats, | ||
2973 | gettext_noop ("# connection requests timed out in transport"), | ||
2974 | 1, | ||
2975 | GNUNET_NO); | ||
2976 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
2977 | _("Failed to connect to `%4s': transport failed to connect\n"), | ||
2978 | GNUNET_i2s (&n->peer)); | ||
2979 | return 0; | ||
2980 | } | ||
2981 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
2982 | _("TRANSPORT connection to peer `%4s' is up, trying to establish CORE connection\n"), | ||
2983 | GNUNET_i2s (&n->peer)); | ||
2984 | if (n->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK) | ||
2985 | GNUNET_SCHEDULER_cancel (n->retry_set_key_task); | ||
2986 | n->retry_set_key_task = GNUNET_SCHEDULER_add_now (&set_key_retry_task, | ||
2987 | n); | ||
2988 | return 0; | ||
2989 | } | ||
2990 | |||
2991 | |||
2992 | /** | ||
2993 | * Handle CORE_REQUEST_CONNECT request. | 2940 | * Handle CORE_REQUEST_CONNECT request. |
2994 | * | 2941 | * |
2995 | * @param cls unused | 2942 | * @param cls unused |
@@ -3003,7 +2950,6 @@ handle_client_request_connect (void *cls, | |||
3003 | { | 2950 | { |
3004 | const struct ConnectMessage *cm = (const struct ConnectMessage*) message; | 2951 | const struct ConnectMessage *cm = (const struct ConnectMessage*) message; |
3005 | struct Neighbour *n; | 2952 | struct Neighbour *n; |
3006 | struct GNUNET_TIME_Relative timeout; | ||
3007 | 2953 | ||
3008 | if (0 == memcmp (&cm->peer, | 2954 | if (0 == memcmp (&cm->peer, |
3009 | &my_identity, | 2955 | &my_identity, |
@@ -3012,64 +2958,33 @@ handle_client_request_connect (void *cls, | |||
3012 | /* In this case a client has asked us to connect to ourselves, not really an error! */ | 2958 | /* In this case a client has asked us to connect to ourselves, not really an error! */ |
3013 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 2959 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
3014 | return; | 2960 | return; |
3015 | } | 2961 | } |
3016 | timeout = GNUNET_TIME_relative_ntoh (cm->timeout); | ||
3017 | GNUNET_break (ntohl (cm->reserved) == 0); | 2962 | GNUNET_break (ntohl (cm->reserved) == 0); |
3018 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
3019 | n = find_neighbour (&cm->peer); | ||
3020 | if (n == NULL) | ||
3021 | n = create_neighbour (&cm->peer); | ||
3022 | if ( (GNUNET_YES == n->is_connected) || | ||
3023 | (n->th != NULL) ) | ||
3024 | { | ||
3025 | if (GNUNET_YES == n->is_connected) | ||
3026 | { | ||
3027 | GNUNET_STATISTICS_update (stats, | ||
3028 | gettext_noop ("# connection requests ignored (already connected)"), | ||
3029 | 1, | ||
3030 | GNUNET_NO); | ||
3031 | } | ||
3032 | else | ||
3033 | { | ||
3034 | if (NULL != n->th) | ||
3035 | { | ||
3036 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (n->th); | ||
3037 | n->th = NULL; | ||
3038 | } | ||
3039 | n->th = GNUNET_TRANSPORT_notify_transmit_ready (transport, | ||
3040 | &cm->peer, | ||
3041 | sizeof (struct GNUNET_MessageHeader), 0, | ||
3042 | timeout, | ||
3043 | ¬ify_transport_connect_done, | ||
3044 | n); | ||
3045 | GNUNET_break (NULL != n->th); | ||
3046 | GNUNET_STATISTICS_update (stats, | ||
3047 | gettext_noop ("# connection requests retried (due to repeat request connect)"), | ||
3048 | 1, | ||
3049 | GNUNET_NO); | ||
3050 | } | ||
3051 | return; /* already connected, or at least trying */ | ||
3052 | } | ||
3053 | GNUNET_STATISTICS_update (stats, | ||
3054 | gettext_noop ("# connection requests received"), | ||
3055 | 1, | ||
3056 | GNUNET_NO); | ||
3057 | |||
3058 | #if DEBUG_CORE | 2963 | #if DEBUG_CORE |
3059 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2964 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3060 | "Core received `%s' request for `%4s', will try to establish connection\n", | 2965 | "Core received `%s' request for `%4s', will try to establish connection\n", |
3061 | "REQUEST_CONNECT", | 2966 | "REQUEST_CONNECT", |
3062 | GNUNET_i2s (&cm->peer)); | 2967 | GNUNET_i2s (&cm->peer)); |
3063 | #endif | 2968 | #endif |
3064 | 2969 | GNUNET_STATISTICS_update (stats, | |
3065 | /* ask transport to connect to the peer */ | 2970 | gettext_noop ("# connection requests received"), |
3066 | n->th = GNUNET_TRANSPORT_notify_transmit_ready (transport, | 2971 | 1, |
3067 | &cm->peer, | 2972 | GNUNET_NO); |
3068 | sizeof (struct GNUNET_MessageHeader), 0, | 2973 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
3069 | timeout, | 2974 | n = find_neighbour (&cm->peer); |
3070 | ¬ify_transport_connect_done, | 2975 | if ( (n == NULL) || |
3071 | n); | 2976 | (GNUNET_YES != n->is_connected) ) |
3072 | GNUNET_break (NULL != n->th); | 2977 | { |
2978 | GNUNET_TRANSPORT_try_connect (transport, | ||
2979 | &cm->peer); | ||
2980 | } | ||
2981 | else | ||
2982 | { | ||
2983 | GNUNET_STATISTICS_update (stats, | ||
2984 | gettext_noop ("# connection requests ignored (already connected)"), | ||
2985 | 1, | ||
2986 | GNUNET_NO); | ||
2987 | } | ||
3073 | } | 2988 | } |
3074 | 2989 | ||
3075 | 2990 | ||