diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-10-14 08:03:02 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-10-14 08:03:02 +0000 |
commit | 70f9bcf894b28799df078330d204860e7ea7bae8 (patch) | |
tree | 1ddea2775a875e840ab93e637b6f05b8678fc057 | |
parent | 1bab64147e7b113051dcd41ae18fa0e9537b7fd9 (diff) | |
download | gnunet-70f9bcf894b28799df078330d204860e7ea7bae8.tar.gz gnunet-70f9bcf894b28799df078330d204860e7ea7bae8.zip |
more ATS implementation: message parsing and generation:
-rw-r--r-- | src/ats/gnunet-service-ats.c | 18 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 18 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.h | 18 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_performance.c | 5 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_performance.h | 5 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_scheduling.c | 212 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_scheduling.h | 82 |
7 files changed, 333 insertions, 25 deletions
diff --git a/src/ats/gnunet-service-ats.c b/src/ats/gnunet-service-ats.c index 19a5d4380..91ffd9c9d 100644 --- a/src/ats/gnunet-service-ats.c +++ b/src/ats/gnunet-service-ats.c | |||
@@ -22,6 +22,7 @@ | |||
22 | * @file ats/gnunet-service-ats.c | 22 | * @file ats/gnunet-service-ats.c |
23 | * @brief ats service | 23 | * @brief ats service |
24 | * @author Matthias Wachs | 24 | * @author Matthias Wachs |
25 | * @author Christian Grothoff | ||
25 | */ | 26 | */ |
26 | #include "platform.h" | 27 | #include "platform.h" |
27 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
@@ -32,6 +33,13 @@ | |||
32 | #include "ats.h" | 33 | #include "ats.h" |
33 | 34 | ||
34 | 35 | ||
36 | /** | ||
37 | * We have received a 'ClientStartMessage' from a client. Find out which | ||
38 | * type of client it is and notify the respective subsystem. | ||
39 | * | ||
40 | * @param client handle to the client | ||
41 | * @param message the start message | ||
42 | */ | ||
35 | static void | 43 | static void |
36 | handle_ats_start (void *cls, struct GNUNET_SERVER_Client *client, | 44 | handle_ats_start (void *cls, struct GNUNET_SERVER_Client *client, |
37 | const struct GNUNET_MessageHeader *message) | 45 | const struct GNUNET_MessageHeader *message) |
@@ -44,10 +52,10 @@ handle_ats_start (void *cls, struct GNUNET_SERVER_Client *client, | |||
44 | switch (ntohl (msg->start_flag)) | 52 | switch (ntohl (msg->start_flag)) |
45 | { | 53 | { |
46 | case START_FLAG_SCHEDULING: | 54 | case START_FLAG_SCHEDULING: |
47 | GAS_add_scheduling_client (client); | 55 | GAS_scheduling_add_client (client); |
48 | break; | 56 | break; |
49 | case START_FLAG_PERFORMANCE_WITH_PIC: | 57 | case START_FLAG_PERFORMANCE_WITH_PIC: |
50 | GAS_add_performance_client (client); | 58 | GAS_performance_add_client (client); |
51 | break; | 59 | break; |
52 | case START_FLAG_PERFORMANCE_NO_PIC: | 60 | case START_FLAG_PERFORMANCE_NO_PIC: |
53 | break; | 61 | break; |
@@ -70,8 +78,8 @@ handle_ats_start (void *cls, struct GNUNET_SERVER_Client *client, | |||
70 | static void | 78 | static void |
71 | client_disconnect_handler (void *cls, struct GNUNET_SERVER_Client *client) | 79 | client_disconnect_handler (void *cls, struct GNUNET_SERVER_Client *client) |
72 | { | 80 | { |
73 | GAS_remove_scheduling_client (client); | 81 | GAS_scheduling_remove_client (client); |
74 | GAS_remove_performance_client (client); | 82 | GAS_performance_remove_client (client); |
75 | } | 83 | } |
76 | 84 | ||
77 | 85 | ||
@@ -85,6 +93,7 @@ static void | |||
85 | cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 93 | cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
86 | { | 94 | { |
87 | GAS_addresses_done (); | 95 | GAS_addresses_done (); |
96 | GAS_scheduling_done (); | ||
88 | } | 97 | } |
89 | 98 | ||
90 | 99 | ||
@@ -114,6 +123,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
114 | GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE, 0}, | 123 | GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE, 0}, |
115 | {NULL, NULL, 0, 0} | 124 | {NULL, NULL, 0, 0} |
116 | }; | 125 | }; |
126 | GAS_scheduling_init (server); | ||
117 | GAS_addresses_init (); | 127 | GAS_addresses_init (); |
118 | GNUNET_SERVER_disconnect_notify (server, | 128 | GNUNET_SERVER_disconnect_notify (server, |
119 | &client_disconnect_handler, | 129 | &client_disconnect_handler, |
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 4f9f877a5..48a1b305d 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c | |||
@@ -22,6 +22,7 @@ | |||
22 | * @file ats/gnunet-service-ats_addresses.c | 22 | * @file ats/gnunet-service-ats_addresses.c |
23 | * @brief ats service address management | 23 | * @brief ats service address management |
24 | * @author Matthias Wachs | 24 | * @author Matthias Wachs |
25 | * @author Christian Grothoff | ||
25 | */ | 26 | */ |
26 | #include "platform.h" | 27 | #include "platform.h" |
27 | #include "gnunet-service-ats_addresses.h" | 28 | #include "gnunet-service-ats_addresses.h" |
@@ -82,10 +83,10 @@ free_address_it (void *cls, | |||
82 | 83 | ||
83 | 84 | ||
84 | void | 85 | void |
85 | GAS_address_update (struct GNUNET_SERVER_Client *client, | 86 | GAS_address_update (const struct GNUNET_PeerIdentity *peer, |
86 | const struct GNUNET_PeerIdentity *peer, | ||
87 | const char *plugin_name, | 87 | const char *plugin_name, |
88 | const void *plugin_addr, size_t plugin_addr_len, | 88 | const void *plugin_addr, size_t plugin_addr_len, |
89 | struct GNUNET_SERVER_Client *session_client, | ||
89 | uint32_t session_id, | 90 | uint32_t session_id, |
90 | const struct GNUNET_TRANSPORT_ATS_Information *atsi, | 91 | const struct GNUNET_TRANSPORT_ATS_Information *atsi, |
91 | uint32_t atsi_count) | 92 | uint32_t atsi_count) |
@@ -113,8 +114,11 @@ GAS_address_update (struct GNUNET_SERVER_Client *client, | |||
113 | 114 | ||
114 | 115 | ||
115 | void | 116 | void |
116 | GAS_address_destroyed (struct GNUNET_SERVER_Client *client, | 117 | GAS_address_destroyed (const struct GNUNET_PeerIdentity *peer, |
117 | ...) | 118 | const char *plugin_name, |
119 | const void *plugin_addr, size_t plugin_addr_len, | ||
120 | struct GNUNET_SERVER_Client *session_client, | ||
121 | uint32_t session_id) | ||
118 | { | 122 | { |
119 | #if 0 | 123 | #if 0 |
120 | // struct AddressDestroyedMessage * msg = (struct AddressDestroyedMessage *) message; | 124 | // struct AddressDestroyedMessage * msg = (struct AddressDestroyedMessage *) message; |
@@ -127,6 +131,12 @@ GAS_address_destroyed (struct GNUNET_SERVER_Client *client, | |||
127 | } | 131 | } |
128 | 132 | ||
129 | 133 | ||
134 | void | ||
135 | GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer) | ||
136 | { | ||
137 | } | ||
138 | |||
139 | |||
130 | /** | 140 | /** |
131 | */ | 141 | */ |
132 | void | 142 | void |
diff --git a/src/ats/gnunet-service-ats_addresses.h b/src/ats/gnunet-service-ats_addresses.h index 299619c6f..4e27b96d2 100644 --- a/src/ats/gnunet-service-ats_addresses.h +++ b/src/ats/gnunet-service-ats_addresses.h | |||
@@ -22,6 +22,7 @@ | |||
22 | * @file ats/gnunet-service-ats_addresses.c | 22 | * @file ats/gnunet-service-ats_addresses.c |
23 | * @brief ats service address management | 23 | * @brief ats service address management |
24 | * @author Matthias Wachs | 24 | * @author Matthias Wachs |
25 | * @author Christian Grothoff | ||
25 | */ | 26 | */ |
26 | #ifndef GNUNET_SERVICE_ATS_ADDRESSES_H | 27 | #ifndef GNUNET_SERVICE_ATS_ADDRESSES_H |
27 | #define GNUNET_SERVICE_ATS_ADDRESSES_H | 28 | #define GNUNET_SERVICE_ATS_ADDRESSES_H |
@@ -42,12 +43,25 @@ GAS_addresses_done (void); | |||
42 | 43 | ||
43 | 44 | ||
44 | void | 45 | void |
45 | GAS_address_update (struct GNUNET_SERVER_Client *client, | 46 | GAS_address_update (const struct GNUNET_PeerIdentity *peer, |
46 | const struct GNUNET_PeerIdentity *peer, | ||
47 | const char *plugin_name, | 47 | const char *plugin_name, |
48 | const void *plugin_addr, size_t plugin_addr_len, | 48 | const void *plugin_addr, size_t plugin_addr_len, |
49 | struct GNUNET_SERVER_Client *session_client, | ||
49 | uint32_t session_id, | 50 | uint32_t session_id, |
50 | const struct GNUNET_TRANSPORT_ATS_Information *atsi, | 51 | const struct GNUNET_TRANSPORT_ATS_Information *atsi, |
51 | uint32_t atsi_count); | 52 | uint32_t atsi_count); |
52 | 53 | ||
54 | |||
55 | void | ||
56 | GAS_address_destroyed (const struct GNUNET_PeerIdentity *peer, | ||
57 | const char *plugin_name, | ||
58 | const void *plugin_addr, size_t plugin_addr_len, | ||
59 | struct GNUNET_SERVER_Client *session_client, | ||
60 | uint32_t session_id); | ||
61 | |||
62 | |||
63 | void | ||
64 | GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer); | ||
65 | |||
66 | |||
53 | #endif | 67 | #endif |
diff --git a/src/ats/gnunet-service-ats_performance.c b/src/ats/gnunet-service-ats_performance.c index edad22512..a0062ab7a 100644 --- a/src/ats/gnunet-service-ats_performance.c +++ b/src/ats/gnunet-service-ats_performance.c | |||
@@ -22,6 +22,7 @@ | |||
22 | * @file ats/gnunet-service-ats_performance.c | 22 | * @file ats/gnunet-service-ats_performance.c |
23 | * @brief ats service, interaction with 'performance' API | 23 | * @brief ats service, interaction with 'performance' API |
24 | * @author Matthias Wachs | 24 | * @author Matthias Wachs |
25 | * @author Christian Grothoff | ||
25 | */ | 26 | */ |
26 | #include "platform.h" | 27 | #include "platform.h" |
27 | #include "gnunet-service-ats_performance.h" | 28 | #include "gnunet-service-ats_performance.h" |
@@ -63,7 +64,7 @@ find_client (struct GNUNET_SERVER_Client *client) | |||
63 | 64 | ||
64 | 65 | ||
65 | void | 66 | void |
66 | GAS_add_performance_client (struct GNUNET_SERVER_Client *client) | 67 | GAS_performance_add_client (struct GNUNET_SERVER_Client *client) |
67 | { | 68 | { |
68 | struct PerformanceClient * pc; | 69 | struct PerformanceClient * pc; |
69 | 70 | ||
@@ -75,7 +76,7 @@ GAS_add_performance_client (struct GNUNET_SERVER_Client *client) | |||
75 | 76 | ||
76 | 77 | ||
77 | void | 78 | void |
78 | GAS_remove_performance_client (struct GNUNET_SERVER_Client *client) | 79 | GAS_performance_remove_client (struct GNUNET_SERVER_Client *client) |
79 | { | 80 | { |
80 | struct PerformanceClient * pc; | 81 | struct PerformanceClient * pc; |
81 | 82 | ||
diff --git a/src/ats/gnunet-service-ats_performance.h b/src/ats/gnunet-service-ats_performance.h index 45bc39c35..cb6677f5b 100644 --- a/src/ats/gnunet-service-ats_performance.h +++ b/src/ats/gnunet-service-ats_performance.h | |||
@@ -22,6 +22,7 @@ | |||
22 | * @file ats/gnunet-service-ats_performance.h | 22 | * @file ats/gnunet-service-ats_performance.h |
23 | * @brief ats service, interaction with 'performance' API | 23 | * @brief ats service, interaction with 'performance' API |
24 | * @author Matthias Wachs | 24 | * @author Matthias Wachs |
25 | * @author Christian Grothoff | ||
25 | */ | 26 | */ |
26 | #ifndef GNUNET_SERVICE_ATS_PERFORMANCE_H | 27 | #ifndef GNUNET_SERVICE_ATS_PERFORMANCE_H |
27 | #define GNUNET_SERVICE_ATS_PERFORMANCE_H | 28 | #define GNUNET_SERVICE_ATS_PERFORMANCE_H |
@@ -29,11 +30,11 @@ | |||
29 | #include "gnunet_util_lib.h" | 30 | #include "gnunet_util_lib.h" |
30 | 31 | ||
31 | void | 32 | void |
32 | GAS_add_performance_client (struct GNUNET_SERVER_Client *client); | 33 | GAS_performance_add_client (struct GNUNET_SERVER_Client *client); |
33 | 34 | ||
34 | 35 | ||
35 | void | 36 | void |
36 | GAS_remove_performance_client (struct GNUNET_SERVER_Client *client); | 37 | GAS_performance_remove_client (struct GNUNET_SERVER_Client *client); |
37 | 38 | ||
38 | 39 | ||
39 | void | 40 | void |
diff --git a/src/ats/gnunet-service-ats_scheduling.c b/src/ats/gnunet-service-ats_scheduling.c index 60305bac9..9a16269d9 100644 --- a/src/ats/gnunet-service-ats_scheduling.c +++ b/src/ats/gnunet-service-ats_scheduling.c | |||
@@ -22,6 +22,7 @@ | |||
22 | * @file ats/gnunet-service-ats_scheduling.c | 22 | * @file ats/gnunet-service-ats_scheduling.c |
23 | * @brief ats service, interaction with 'scheduling' API | 23 | * @brief ats service, interaction with 'scheduling' API |
24 | * @author Matthias Wachs | 24 | * @author Matthias Wachs |
25 | * @author Christian Grothoff | ||
25 | */ | 26 | */ |
26 | #include "platform.h" | 27 | #include "platform.h" |
27 | #include "gnunet-service-ats_addresses.h" | 28 | #include "gnunet-service-ats_addresses.h" |
@@ -29,12 +30,29 @@ | |||
29 | #include "ats.h" | 30 | #include "ats.h" |
30 | 31 | ||
31 | 32 | ||
33 | /** | ||
34 | * We keep clients that are interested in scheduling in a linked list. | ||
35 | * This list typically has only one entry (for the | ||
36 | * gnunet-service-transport process); however, it is possible that | ||
37 | * there is more than one (at least briefly) because after a crash a | ||
38 | * new one may connect before we've been notified to clean up the old | ||
39 | * process. | ||
40 | */ | ||
32 | struct SchedulingClient | 41 | struct SchedulingClient |
33 | { | 42 | { |
43 | /** | ||
44 | * Next in doubly-linked list. | ||
45 | */ | ||
34 | struct SchedulingClient * next; | 46 | struct SchedulingClient * next; |
35 | 47 | ||
48 | /** | ||
49 | * Previous in doubly-linked list. | ||
50 | */ | ||
36 | struct SchedulingClient * prev; | 51 | struct SchedulingClient * prev; |
37 | 52 | ||
53 | /** | ||
54 | * Actual handle to the client. | ||
55 | */ | ||
38 | struct GNUNET_SERVER_Client *client; | 56 | struct GNUNET_SERVER_Client *client; |
39 | 57 | ||
40 | }; | 58 | }; |
@@ -50,7 +68,19 @@ static struct SchedulingClient *sc_head; | |||
50 | */ | 68 | */ |
51 | static struct SchedulingClient *sc_tail; | 69 | static struct SchedulingClient *sc_tail; |
52 | 70 | ||
71 | /** | ||
72 | * Context for sending messages to clients. | ||
73 | */ | ||
74 | static struct GNUNET_SERVER_NotificationContext *nc; | ||
75 | |||
53 | 76 | ||
77 | /** | ||
78 | * Find the scheduling client associated with the given | ||
79 | * handle. | ||
80 | * | ||
81 | * @param client server handle | ||
82 | * @return internal handle | ||
83 | */ | ||
54 | static struct SchedulingClient * | 84 | static struct SchedulingClient * |
55 | find_client (struct GNUNET_SERVER_Client *client) | 85 | find_client (struct GNUNET_SERVER_Client *client) |
56 | { | 86 | { |
@@ -63,21 +93,33 @@ find_client (struct GNUNET_SERVER_Client *client) | |||
63 | } | 93 | } |
64 | 94 | ||
65 | 95 | ||
96 | /** | ||
97 | * Register a new scheduling client. | ||
98 | * | ||
99 | * @param client handle of the new client | ||
100 | */ | ||
66 | void | 101 | void |
67 | GAS_add_scheduling_client (struct GNUNET_SERVER_Client *client) | 102 | GAS_scheduling_add_client (struct GNUNET_SERVER_Client *client) |
68 | { | 103 | { |
69 | struct SchedulingClient *sc; | 104 | struct SchedulingClient *sc; |
70 | 105 | ||
71 | GNUNET_break (NULL == find_client (client)); | 106 | GNUNET_break (NULL == find_client (client)); |
72 | sc = GNUNET_malloc (sizeof (struct SchedulingClient)); | 107 | sc = GNUNET_malloc (sizeof (struct SchedulingClient)); |
73 | sc->client = client; | 108 | sc->client = client; |
109 | GNUNET_SERVER_notification_context_add (nc, client); | ||
74 | GNUNET_SERVER_client_keep (client); | 110 | GNUNET_SERVER_client_keep (client); |
75 | GNUNET_CONTAINER_DLL_insert(sc_head, sc_tail, sc); | 111 | GNUNET_CONTAINER_DLL_insert(sc_head, sc_tail, sc); |
76 | } | 112 | } |
77 | 113 | ||
78 | 114 | ||
115 | /** | ||
116 | * Unregister a client (which may have been a scheduling client, | ||
117 | * but this is not assured). | ||
118 | * | ||
119 | * @param client handle of the (now dead) client | ||
120 | */ | ||
79 | void | 121 | void |
80 | GAS_remove_scheduling_client (struct GNUNET_SERVER_Client *client) | 122 | GAS_scheduling_remove_client (struct GNUNET_SERVER_Client *client) |
81 | { | 123 | { |
82 | struct SchedulingClient * sc; | 124 | struct SchedulingClient * sc; |
83 | 125 | ||
@@ -90,17 +132,100 @@ GAS_remove_scheduling_client (struct GNUNET_SERVER_Client *client) | |||
90 | } | 132 | } |
91 | 133 | ||
92 | 134 | ||
135 | /** | ||
136 | * Transmit the given address suggestion and bandwidth update to all scheduling | ||
137 | * clients. | ||
138 | * | ||
139 | * @param peer peer for which this is an address suggestion | ||
140 | * @param plugin_name 0-termintated string specifying the transport plugin | ||
141 | * @param plugin_addr binary address for the plugin to use | ||
142 | * @param plugin_addr_len number of bytes in plugin_addr | ||
143 | * @param session_client which client gave us this session_id? | ||
144 | * @param session_id session ID to use for the given client (other clients will see 0) | ||
145 | * @param atsi performance data for the address | ||
146 | * @param atsi_count number of performance records in 'ats' | ||
147 | * @param bandwidth_out assigned outbound bandwidth | ||
148 | * @param bandwidth_in assigned inbound bandwidth | ||
149 | */ | ||
150 | void | ||
151 | GAS_scheduling_transmit_address_update (const struct GNUNET_PeerIdentity *peer, | ||
152 | const char *plugin_name, | ||
153 | const void *plugin_addr, size_t plugin_addr_len, | ||
154 | struct GNUNET_SERVER_Client *session_client, | ||
155 | uint32_t session_id, | ||
156 | const struct GNUNET_TRANSPORT_ATS_Information *atsi, | ||
157 | uint32_t atsi_count, | ||
158 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
159 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | ||
160 | { | ||
161 | struct SchedulingClient *sc; | ||
162 | struct AddressSuggestionMessage *msg; | ||
163 | size_t plugin_name_length = strlen (plugin_name) + 1; | ||
164 | size_t msize = sizeof (struct AddressSuggestionMessage) + atsi_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) | ||
165 | + plugin_addr_len + plugin_name_length; | ||
166 | char buf[msize]; | ||
167 | struct GNUNET_TRANSPORT_ATS_Information *atsp; | ||
168 | char *addrp; | ||
169 | |||
170 | GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE); | ||
171 | GNUNET_assert (atsi_count < GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_TRANSPORT_ATS_Information)); | ||
172 | msg = (struct AddressSuggestionMessage*) buf; | ||
173 | msg->header.size = htons (msize); | ||
174 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION); | ||
175 | msg->ats_count = htonl (atsi_count); | ||
176 | msg->peer = *peer; | ||
177 | msg->address_length = htons (plugin_addr_len); | ||
178 | msg->plugin_name_length = htons (plugin_name_length); | ||
179 | /* session ID is set only if 'client' is the same... */ | ||
180 | msg->bandwidth_out = bandwidth_out; | ||
181 | msg->bandwidth_in = bandwidth_in; | ||
182 | atsp = (struct GNUNET_TRANSPORT_ATS_Information* ) &msg[1]; | ||
183 | memcpy (atsp, atsi, sizeof (struct GNUNET_TRANSPORT_ATS_Information) * atsi_count); | ||
184 | addrp = (char*) &atsp[atsi_count]; | ||
185 | memcpy (addrp, plugin_addr, plugin_addr_len); | ||
186 | strcpy (&addrp[plugin_addr_len], plugin_name); | ||
187 | for (sc = sc_head; sc != NULL; sc = sc->next) | ||
188 | { | ||
189 | if (sc->client == session_client) | ||
190 | msg->session_id = htonl (session_id); | ||
191 | else | ||
192 | msg->session_id = htonl (0); | ||
193 | GNUNET_SERVER_notification_context_unicast (nc, | ||
194 | sc->client, | ||
195 | &msg->header, | ||
196 | GNUNET_YES); | ||
197 | } | ||
198 | } | ||
199 | |||
200 | |||
201 | /** | ||
202 | * Handle 'request address' messages from clients. | ||
203 | * | ||
204 | * @param cls unused, NULL | ||
205 | * @param client client that sent the request | ||
206 | * @param message the request message | ||
207 | */ | ||
93 | void | 208 | void |
94 | GAS_handle_request_address (void *cls, struct GNUNET_SERVER_Client *client, | 209 | GAS_handle_request_address (void *cls, struct GNUNET_SERVER_Client *client, |
95 | const struct GNUNET_MessageHeader *message) | 210 | const struct GNUNET_MessageHeader *message) |
96 | 211 | ||
97 | { | 212 | { |
98 | // struct RequestAddressMessage * msg = (struct RequestAddressMessage *) message; | 213 | const struct RequestAddressMessage * msg = (const struct RequestAddressMessage *) message; |
99 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "REQUEST_ADDRESS"); | ||
100 | 214 | ||
215 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "REQUEST_ADDRESS"); | ||
216 | GNUNET_break (0 == ntohl (msg->reserved)); | ||
217 | GAS_addresses_request_address (&msg->peer); | ||
218 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
101 | } | 219 | } |
102 | 220 | ||
103 | 221 | ||
222 | /** | ||
223 | * Handle 'address update' messages from clients. | ||
224 | * | ||
225 | * @param cls unused, NULL | ||
226 | * @param client client that sent the request | ||
227 | * @param message the request message | ||
228 | */ | ||
104 | void | 229 | void |
105 | GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client, | 230 | GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client, |
106 | const struct GNUNET_MessageHeader *message) | 231 | const struct GNUNET_MessageHeader *message) |
@@ -143,11 +268,11 @@ GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client, | |||
143 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 268 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
144 | return; | 269 | return; |
145 | } | 270 | } |
146 | GAS_address_update (client, | 271 | GAS_address_update (&m->peer, |
147 | &m->peer, | ||
148 | plugin_name, | 272 | plugin_name, |
149 | address, | 273 | address, |
150 | address_length, | 274 | address_length, |
275 | client, | ||
151 | ntohl (m->session_id), | 276 | ntohl (m->session_id), |
152 | atsi, | 277 | atsi, |
153 | ats_count); | 278 | ats_count); |
@@ -155,12 +280,81 @@ GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client, | |||
155 | } | 280 | } |
156 | 281 | ||
157 | 282 | ||
283 | /** | ||
284 | * Handle 'address destroyed' messages from clients. | ||
285 | * | ||
286 | * @param cls unused, NULL | ||
287 | * @param client client that sent the request | ||
288 | * @param message the request message | ||
289 | */ | ||
158 | void | 290 | void |
159 | GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client, | 291 | GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client, |
160 | const struct GNUNET_MessageHeader *message) | 292 | const struct GNUNET_MessageHeader *message) |
293 | |||
294 | { | ||
295 | const struct AddressDestroyedMessage * m; | ||
296 | const char *address; | ||
297 | const char *plugin_name; | ||
298 | uint16_t address_length; | ||
299 | uint16_t plugin_name_length; | ||
300 | uint16_t size; | ||
301 | |||
302 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
303 | "Received `%s' message\n", | ||
304 | "ADDRESS_DESTROYED"); | ||
305 | size = ntohs (message->size); | ||
306 | if (size <= sizeof (struct AddressDestroyedMessage)) | ||
307 | { | ||
308 | GNUNET_break (0); | ||
309 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
310 | return; | ||
311 | } | ||
312 | m = (const struct AddressDestroyedMessage*) message; | ||
313 | GNUNET_break (0 == ntohl (m->reserved)); | ||
314 | address_length = ntohs (m->address_length); | ||
315 | plugin_name_length = ntohs (m->plugin_name_length); | ||
316 | address = (const char*) &m[1]; | ||
317 | plugin_name = &address[address_length]; | ||
318 | if ( (address_length + | ||
319 | plugin_name_length + | ||
320 | sizeof (struct AddressSuggestionMessage) != ntohs (message->size)) || | ||
321 | (plugin_name[plugin_name_length - 1] != '\0') ) | ||
322 | { | ||
323 | GNUNET_break (0); | ||
324 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
325 | return; | ||
326 | } | ||
327 | GAS_address_destroyed (&m->peer, | ||
328 | plugin_name, | ||
329 | address, | ||
330 | address_length, | ||
331 | client, | ||
332 | ntohl (m->session_id)); | ||
333 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
334 | } | ||
335 | |||
336 | |||
337 | /** | ||
338 | * Initialize scheduling subsystem. | ||
339 | * | ||
340 | * @param server handle to our server | ||
341 | */ | ||
342 | void | ||
343 | GAS_scheduling_init (struct GNUNET_SERVER_Handle *server) | ||
344 | { | ||
345 | nc = GNUNET_SERVER_notification_context_create (server, 128); | ||
346 | } | ||
347 | |||
161 | 348 | ||
349 | /** | ||
350 | * Shutdown scheduling subsystem. | ||
351 | */ | ||
352 | void | ||
353 | GAS_scheduling_done () | ||
162 | { | 354 | { |
163 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ADDRESS_DESTROYED"); | 355 | GNUNET_SERVER_notification_context_destroy (nc); |
356 | nc = NULL; | ||
164 | } | 357 | } |
165 | 358 | ||
359 | |||
166 | /* end of gnunet-service-ats_scheduling.c */ | 360 | /* end of gnunet-service-ats_scheduling.c */ |
diff --git a/src/ats/gnunet-service-ats_scheduling.h b/src/ats/gnunet-service-ats_scheduling.h index 5c8f77ed8..d2506de6a 100644 --- a/src/ats/gnunet-service-ats_scheduling.h +++ b/src/ats/gnunet-service-ats_scheduling.h | |||
@@ -22,34 +22,112 @@ | |||
22 | * @file ats/gnunet-service-ats_scheduling.h | 22 | * @file ats/gnunet-service-ats_scheduling.h |
23 | * @brief ats service, interaction with 'scheduling' API | 23 | * @brief ats service, interaction with 'scheduling' API |
24 | * @author Matthias Wachs | 24 | * @author Matthias Wachs |
25 | * @author Christian Grothoff | ||
25 | */ | 26 | */ |
26 | #ifndef GNUNET_SERVICE_ATS_SCHEDULING_H | 27 | #ifndef GNUNET_SERVICE_ATS_SCHEDULING_H |
27 | #define GNUNET_SERVICE_ATS_SCHEDULING_H | 28 | #define GNUNET_SERVICE_ATS_SCHEDULING_H |
28 | 29 | ||
29 | #include "gnunet_util_lib.h" | 30 | #include "gnunet_util_lib.h" |
30 | 31 | ||
32 | |||
33 | /** | ||
34 | * Register a new scheduling client. | ||
35 | * | ||
36 | * @param client handle of the new client | ||
37 | */ | ||
38 | void | ||
39 | GAS_scheduling_add_client (struct GNUNET_SERVER_Client *client); | ||
40 | |||
41 | |||
42 | /** | ||
43 | * Unregister a client (which may have been a scheduling client, | ||
44 | * but this is not assured). | ||
45 | * | ||
46 | * @param client handle of the (now dead) client | ||
47 | */ | ||
31 | void | 48 | void |
32 | GAS_add_scheduling_client (struct GNUNET_SERVER_Client *client); | 49 | GAS_scheduling_remove_client (struct GNUNET_SERVER_Client *client); |
33 | 50 | ||
34 | 51 | ||
52 | /** | ||
53 | * Transmit the given address suggestion and bandwidth update to all scheduling | ||
54 | * clients. | ||
55 | * | ||
56 | * @param peer peer for which this is an address suggestion | ||
57 | * @param plugin_name 0-termintated string specifying the transport plugin | ||
58 | * @param plugin_addr binary address for the plugin to use | ||
59 | * @param plugin_addr_len number of bytes in plugin_addr | ||
60 | * @param session_client which client gave us this session_id? | ||
61 | * @param session_id session ID to use for the given client (other clients will see 0) | ||
62 | * @param atsi performance data for the address | ||
63 | * @param atsi_count number of performance records in 'ats' | ||
64 | * @param bandwidth_out assigned outbound bandwidth | ||
65 | * @param bandwidth_in assigned inbound bandwidth | ||
66 | */ | ||
35 | void | 67 | void |
36 | GAS_remove_scheduling_client (struct GNUNET_SERVER_Client *client); | 68 | GAS_scheduling_transmit_address_update (const struct GNUNET_PeerIdentity *peer, |
69 | const char *plugin_name, | ||
70 | const void *plugin_addr, size_t plugin_addr_len, | ||
71 | struct GNUNET_SERVER_Client *session_client, | ||
72 | uint32_t session_id, | ||
73 | const struct GNUNET_TRANSPORT_ATS_Information *atsi, | ||
74 | uint32_t atsi_count, | ||
75 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
76 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in); | ||
37 | 77 | ||
38 | 78 | ||
79 | /** | ||
80 | * Handle 'request address' messages from clients. | ||
81 | * | ||
82 | * @param cls unused, NULL | ||
83 | * @param client client that sent the request | ||
84 | * @param message the request message | ||
85 | */ | ||
39 | void | 86 | void |
40 | GAS_handle_request_address (void *cls, struct GNUNET_SERVER_Client *client, | 87 | GAS_handle_request_address (void *cls, struct GNUNET_SERVER_Client *client, |
41 | const struct GNUNET_MessageHeader *message); | 88 | const struct GNUNET_MessageHeader *message); |
42 | 89 | ||
43 | 90 | ||
91 | |||
92 | /** | ||
93 | * Handle 'address update' messages from clients. | ||
94 | * | ||
95 | * @param cls unused, NULL | ||
96 | * @param client client that sent the request | ||
97 | * @param message the request message | ||
98 | */ | ||
44 | void | 99 | void |
45 | GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client, | 100 | GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client, |
46 | const struct GNUNET_MessageHeader *message); | 101 | const struct GNUNET_MessageHeader *message); |
47 | 102 | ||
48 | 103 | ||
104 | /** | ||
105 | * Handle 'address destroyed' messages from clients. | ||
106 | * | ||
107 | * @param cls unused, NULL | ||
108 | * @param client client that sent the request | ||
109 | * @param message the request message | ||
110 | */ | ||
49 | void | 111 | void |
50 | GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client, | 112 | GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client, |
51 | const struct GNUNET_MessageHeader *message); | 113 | const struct GNUNET_MessageHeader *message); |
52 | 114 | ||
53 | 115 | ||
116 | /** | ||
117 | * Initialize scheduling subsystem. | ||
118 | * | ||
119 | * @param server handle to our server | ||
120 | */ | ||
121 | void | ||
122 | GAS_scheduling_init (struct GNUNET_SERVER_Handle *server); | ||
123 | |||
124 | |||
125 | /** | ||
126 | * Shutdown scheduling subsystem. | ||
127 | */ | ||
128 | void | ||
129 | GAS_scheduling_done (void); | ||
130 | |||
131 | |||
54 | #endif | 132 | #endif |
55 | /* end of gnunet-service-ats_scheduling.h */ | 133 | /* end of gnunet-service-ats_scheduling.h */ |