aboutsummaryrefslogtreecommitdiff
path: root/src/ats
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-10-13 21:16:04 +0000
committerChristian Grothoff <christian@grothoff.org>2011-10-13 21:16:04 +0000
commit2e92874cdda169f6337669d1bff9a5772aeae163 (patch)
treed563a7c4a1fcecf5d1a726805fc2fc95926836f5 /src/ats
parent0b66a17293953e905668cc5b5764068b65b9f4c1 (diff)
downloadgnunet-2e92874cdda169f6337669d1bff9a5772aeae163.tar.gz
gnunet-2e92874cdda169f6337669d1bff9a5772aeae163.zip
more refactoring
Diffstat (limited to 'src/ats')
-rw-r--r--src/ats/ats.h7
-rw-r--r--src/ats/gnunet-service-ats_addresses.c46
-rw-r--r--src/ats/gnunet-service-ats_addresses.h11
-rw-r--r--src/ats/gnunet-service-ats_scheduling.c87
4 files changed, 97 insertions, 54 deletions
diff --git a/src/ats/ats.h b/src/ats/ats.h
index 2bf16b125..bef63553e 100644
--- a/src/ats/ats.h
+++ b/src/ats/ats.h
@@ -41,7 +41,6 @@ enum StartFlag
41}; 41};
42 42
43 43
44
45struct ClientStartMessage 44struct ClientStartMessage
46{ 45{
47 struct GNUNET_MessageHeader header; 46 struct GNUNET_MessageHeader header;
@@ -53,7 +52,6 @@ struct ClientStartMessage
53}; 52};
54 53
55 54
56
57struct RequestAddressMessage 55struct RequestAddressMessage
58{ 56{
59 struct GNUNET_MessageHeader header; 57 struct GNUNET_MessageHeader header;
@@ -63,6 +61,7 @@ struct RequestAddressMessage
63 struct GNUNET_PeerIdentity peer; 61 struct GNUNET_PeerIdentity peer;
64}; 62};
65 63
64
66struct AddressUpdateMessage 65struct AddressUpdateMessage
67{ 66{
68 struct GNUNET_MessageHeader header; 67 struct GNUNET_MessageHeader header;
@@ -85,6 +84,7 @@ struct AddressUpdateMessage
85 84
86}; 85};
87 86
87
88struct AddressDestroyedMessage 88struct AddressDestroyedMessage
89{ 89{
90 struct GNUNET_MessageHeader header; 90 struct GNUNET_MessageHeader header;
@@ -134,7 +134,6 @@ struct AddressSuggestionMessage
134}; 134};
135 135
136 136
137
138struct PeerInformationMessage 137struct PeerInformationMessage
139{ 138{
140 struct GNUNET_MessageHeader header; 139 struct GNUNET_MessageHeader header;
@@ -160,8 +159,6 @@ struct PeerInformationMessage
160}; 159};
161 160
162 161
163
164
165struct ReservationRequestMessage 162struct ReservationRequestMessage
166{ 163{
167 struct GNUNET_MessageHeader header; 164 struct GNUNET_MessageHeader header;
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c
index ff83f4fd8..4f9f877a5 100644
--- a/src/ats/gnunet-service-ats_addresses.c
+++ b/src/ats/gnunet-service-ats_addresses.c
@@ -81,6 +81,52 @@ free_address_it (void *cls,
81} 81}
82 82
83 83
84void
85GAS_address_update (struct GNUNET_SERVER_Client *client,
86 const struct GNUNET_PeerIdentity *peer,
87 const char *plugin_name,
88 const void *plugin_addr, size_t plugin_addr_len,
89 uint32_t session_id,
90 const struct GNUNET_TRANSPORT_ATS_Information *atsi,
91 uint32_t atsi_count)
92{
93 struct ATS_Address * aa;
94
95 aa = GNUNET_malloc (sizeof (struct ATS_Address) +
96 atsi_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) +
97 plugin_addr_len);
98 aa->peer = *peer;
99 aa->addr_len = plugin_addr_len;
100 aa->ats_count = atsi_count;
101 aa->ats = (struct GNUNET_TRANSPORT_ATS_Information *) &aa[1];
102 memcpy (&aa->ats, atsi, atsi_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
103 memcpy (aa->addr, plugin_addr, plugin_addr_len);
104 aa->plugin = GNUNET_strdup (plugin_name);
105 aa->session_id = session_id;
106
107 GNUNET_assert (GNUNET_OK ==
108 GNUNET_CONTAINER_multihashmap_put(addresses,
109 &peer->hashPubKey,
110 aa,
111 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
112}
113
114
115void
116GAS_address_destroyed (struct GNUNET_SERVER_Client *client,
117 ...)
118{
119#if 0
120 // struct AddressDestroyedMessage * msg = (struct AddressDestroyedMessage *) message;
121/*
122 struct GNUNET_PeerIdentity *peer = &msg->peer;
123 struct ATS_Address * aa = find_address_by_addr (peer);
124 GNUNET_CONTAINER_multihashmap_remove(addresses, peer, aa);
125 GNUNET_free (aa);*/
126#endif
127}
128
129
84/** 130/**
85 */ 131 */
86void 132void
diff --git a/src/ats/gnunet-service-ats_addresses.h b/src/ats/gnunet-service-ats_addresses.h
index 1bc6b65c2..299619c6f 100644
--- a/src/ats/gnunet-service-ats_addresses.h
+++ b/src/ats/gnunet-service-ats_addresses.h
@@ -27,7 +27,7 @@
27#define GNUNET_SERVICE_ATS_ADDRESSES_H 27#define GNUNET_SERVICE_ATS_ADDRESSES_H
28 28
29#include "gnunet_util_lib.h" 29#include "gnunet_util_lib.h"
30 30#include "gnunet_transport_service.h" // FIXME...
31 31
32/** 32/**
33 */ 33 */
@@ -41,4 +41,13 @@ void
41GAS_addresses_done (void); 41GAS_addresses_done (void);
42 42
43 43
44void
45GAS_address_update (struct GNUNET_SERVER_Client *client,
46 const struct GNUNET_PeerIdentity *peer,
47 const char *plugin_name,
48 const void *plugin_addr, size_t plugin_addr_len,
49 uint32_t session_id,
50 const struct GNUNET_TRANSPORT_ATS_Information *atsi,
51 uint32_t atsi_count);
52
44#endif 53#endif
diff --git a/src/ats/gnunet-service-ats_scheduling.c b/src/ats/gnunet-service-ats_scheduling.c
index bf2c6187a..60305bac9 100644
--- a/src/ats/gnunet-service-ats_scheduling.c
+++ b/src/ats/gnunet-service-ats_scheduling.c
@@ -24,6 +24,7 @@
24 * @author Matthias Wachs 24 * @author Matthias Wachs
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27#include "gnunet-service-ats_addresses.h"
27#include "gnunet-service-ats_scheduling.h" 28#include "gnunet-service-ats_scheduling.h"
28#include "ats.h" 29#include "ats.h"
29 30
@@ -105,54 +106,52 @@ GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client,
105 const struct GNUNET_MessageHeader *message) 106 const struct GNUNET_MessageHeader *message)
106 107
107{ 108{
108#if 0 109 const struct AddressUpdateMessage * m;
109 struct AddressUpdateMessage * msg = (struct AddressUpdateMessage *) message; 110 const struct GNUNET_TRANSPORT_ATS_Information *atsi;
110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ADDRESS_UPDATE"); 111 const char *address;
111 112 const char *plugin_name;
112 struct GNUNET_TRANSPORT_ATS_Information *am; 113 uint16_t address_length;
113 char *pm; 114 uint16_t plugin_name_length;
114 115 uint32_t ats_count;
115 size_t size = ntohs (msg->header.size); 116 uint16_t size;
116 if ((size <= sizeof (struct AddressUpdateMessage)) || (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)) 117
118 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
119 "Received `%s' message\n",
120 "ADDRESS_UPDATE");
121 size = ntohs (message->size);
122 if (size <= sizeof (struct AddressUpdateMessage))
117 { 123 {
118 GNUNET_break (0); 124 GNUNET_break (0);
125 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
119 return; 126 return;
120 } 127 }
121 128 m = (const struct AddressUpdateMessage*) message;
122 size_t ats_count = ntohs (msg->ats_count); 129 ats_count = ntohl (m->ats_count);
123 size_t addr_len = ntohs (msg->address_length); 130 address_length = ntohs (m->address_length);
124 size_t plugin_len = ntohs (msg->plugin_name_length) + 1 ; 131 plugin_name_length = ntohs (m->plugin_name_length);
125 132 atsi = (const struct GNUNET_TRANSPORT_ATS_Information*) &m[1];
126 if ( 133 address = (const char*) &atsi[ats_count];
127 (plugin_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 134 plugin_name = &address[address_length];
128 (addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 135 if ( (address_length +
129 (addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_TRANSPORT_ATS_Information)) ) 136 plugin_name_length +
137 ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) +
138 sizeof (struct AddressSuggestionMessage) != ntohs (message->size)) ||
139 (ats_count > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_TRANSPORT_ATS_Information)) ||
140 (plugin_name[plugin_name_length - 1] != '\0') )
130 { 141 {
131 GNUNET_break (0); 142 GNUNET_break (0);
143 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
132 return; 144 return;
133 } 145 }
134 146 GAS_address_update (client,
135 struct ATS_Address * aa = GNUNET_malloc (sizeof (struct ATS_Address) + 147 &m->peer,
136 ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) + 148 plugin_name,
137 addr_len + 149 address,
138 plugin_len); 150 address_length,
139 151 ntohl (m->session_id),
140 152 atsi,
141 153 ats_count);
142 memcpy (&aa->peer, &msg->peer, sizeof (struct GNUNET_PeerIdentity)); 154 GNUNET_SERVER_receive_done (client, GNUNET_OK);
143 aa->addr_len = addr_len;
144 aa->ats_count = ats_count;
145 aa->ats = (struct GNUNET_TRANSPORT_ATS_Information *) &aa[1];
146
147 am = (struct GNUNET_TRANSPORT_ATS_Information*) &msg[1];
148 memcpy (&aa->ats, am, ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
149 pm = (char *) &am[ats_count];
150 memcpy (aa->addr, pm, addr_len);
151 memcpy (aa->plugin, &pm[plugin_len], plugin_len);
152 aa->session_id = ntohl(msg->session_id);
153
154 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(addresses, &aa->peer.hashPubKey, aa, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
155#endif
156} 155}
157 156
158 157
@@ -161,15 +160,7 @@ GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client,
161 const struct GNUNET_MessageHeader *message) 160 const struct GNUNET_MessageHeader *message)
162 161
163{ 162{
164#if 0
165 // struct AddressDestroyedMessage * msg = (struct AddressDestroyedMessage *) message;
166 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ADDRESS_DESTROYED"); 163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ADDRESS_DESTROYED");
167/*
168 struct GNUNET_PeerIdentity *peer = &msg->peer;
169 struct ATS_Address * aa = find_address_by_addr (peer);
170 GNUNET_CONTAINER_multihashmap_remove(addresses, peer, aa);
171 GNUNET_free (aa);*/
172#endif
173} 164}
174 165
175/* end of gnunet-service-ats_scheduling.c */ 166/* end of gnunet-service-ats_scheduling.c */