diff options
author | Bart Polot <bart@net.in.tum.de> | 2014-10-15 00:55:38 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2014-10-15 00:55:38 +0000 |
commit | 3dfe0b93bba61ca11519adca8a901fd07563612c (patch) | |
tree | 9ed9a368c72832c646cb39b08de59a5cfcd66e89 /src/cadet/gnunet-service-cadet_dht.c | |
parent | f00081f2abb7dd098f6c4433ca6117ce90c1adc7 (diff) | |
download | gnunet-3dfe0b93bba61ca11519adca8a901fd07563612c.tar.gz gnunet-3dfe0b93bba61ca11519adca8a901fd07563612c.zip |
Use optimizaiton of paths on store from DHT as well as on receipt from CONN_CREATE
Diffstat (limited to 'src/cadet/gnunet-service-cadet_dht.c')
-rw-r--r-- | src/cadet/gnunet-service-cadet_dht.c | 78 |
1 files changed, 14 insertions, 64 deletions
diff --git a/src/cadet/gnunet-service-cadet_dht.c b/src/cadet/gnunet-service-cadet_dht.c index 7d31603df..f18e868e3 100644 --- a/src/cadet/gnunet-service-cadet_dht.c +++ b/src/cadet/gnunet-service-cadet_dht.c | |||
@@ -119,77 +119,27 @@ path_build_from_dht (const struct GNUNET_PeerIdentity *get_path, | |||
119 | const struct GNUNET_PeerIdentity *put_path, | 119 | const struct GNUNET_PeerIdentity *put_path, |
120 | unsigned int put_path_length) | 120 | unsigned int put_path_length) |
121 | { | 121 | { |
122 | size_t size = get_path_length + put_path_length; | ||
123 | struct GNUNET_PeerIdentity peers[size]; | ||
124 | const struct GNUNET_PeerIdentity *peer; | ||
122 | struct CadetPeerPath *p; | 125 | struct CadetPeerPath *p; |
123 | GNUNET_PEER_Id id; | 126 | unsigned int own_pos; |
124 | int i; | 127 | int i; |
125 | 128 | ||
126 | p = path_new (1); | 129 | LOG (GNUNET_ERROR_TYPE_DEBUG, " GET has %d hops.\n", get_path_length); |
127 | p->peers[0] = myid; | 130 | for (i = 0 ; i < get_path_length; i++) |
128 | GNUNET_PEER_change_rc (myid, 1); | ||
129 | i = get_path_length; | ||
130 | LOG (GNUNET_ERROR_TYPE_DEBUG, " GET has %d hops.\n", i); | ||
131 | for (i--; i >= 0; i--) | ||
132 | { | 131 | { |
133 | id = GNUNET_PEER_intern (&get_path[i]); | 132 | peer = &get_path[get_path_length - i - 1]; |
134 | if (p->length > 0 && id == p->peers[p->length - 1]) | 133 | LOG (GNUNET_ERROR_TYPE_DEBUG, " From GET: %s\n", GNUNET_i2s (peer)); |
135 | { | 134 | peers[i] = *peer; |
136 | LOG (GNUNET_ERROR_TYPE_DEBUG, " Optimizing 1 hop out.\n"); | ||
137 | GNUNET_PEER_change_rc (id, -1); | ||
138 | } | ||
139 | else | ||
140 | { | ||
141 | LOG (GNUNET_ERROR_TYPE_DEBUG, " Adding from GET: %s.\n", | ||
142 | GNUNET_i2s (&get_path[i])); | ||
143 | p->length++; | ||
144 | p->peers = GNUNET_realloc (p->peers, sizeof (GNUNET_PEER_Id) * p->length); | ||
145 | p->peers[p->length - 1] = id; | ||
146 | } | ||
147 | } | 135 | } |
148 | i = put_path_length; | 136 | for (i = 0 ; i < put_path_length; i++) |
149 | LOG (GNUNET_ERROR_TYPE_DEBUG, " PUT has %d hops.\n", i); | ||
150 | for (i--; i >= 0; i--) | ||
151 | { | 137 | { |
152 | id = GNUNET_PEER_intern (&put_path[i]); | 138 | peer = &put_path[put_path_length - i - 1]; |
153 | if (id == myid) | 139 | LOG (GNUNET_ERROR_TYPE_DEBUG, " From PUT: %s\n", GNUNET_i2s (peer)); |
154 | { | 140 | peers[i + get_path_length] = *peer; |
155 | /* PUT path went through us, so discard the path up until now and start | ||
156 | * from here to get a much shorter (and loop-free) path. | ||
157 | */ | ||
158 | path_destroy (p); | ||
159 | p = path_new (0); | ||
160 | } | ||
161 | if (p->length > 0 && id == p->peers[p->length - 1]) | ||
162 | { | ||
163 | LOG (GNUNET_ERROR_TYPE_DEBUG, " Optimizing 1 hop out.\n"); | ||
164 | GNUNET_PEER_change_rc (id, -1); | ||
165 | } | ||
166 | else | ||
167 | { | ||
168 | LOG (GNUNET_ERROR_TYPE_DEBUG, " Adding from PUT: %s.\n", | ||
169 | GNUNET_i2s (&put_path[i])); | ||
170 | p->length++; | ||
171 | p->peers = GNUNET_realloc (p->peers, sizeof (GNUNET_PEER_Id) * p->length); | ||
172 | p->peers[p->length - 1] = id; | ||
173 | } | ||
174 | } | 141 | } |
175 | #if CADET_DEBUG | 142 | p = path_build_from_peer_ids (peers, size, myid, &own_pos); |
176 | if (get_path_length > 0) | ||
177 | LOG (GNUNET_ERROR_TYPE_DEBUG, " (first of GET: %s)\n", | ||
178 | GNUNET_i2s (&get_path[0])); | ||
179 | if (put_path_length > 0) | ||
180 | LOG (GNUNET_ERROR_TYPE_DEBUG, " (first of PUT: %s)\n", | ||
181 | GNUNET_i2s (&put_path[0])); | ||
182 | LOG (GNUNET_ERROR_TYPE_DEBUG, " In total: %d hops\n", | ||
183 | p->length); | ||
184 | for (i = 0; i < p->length; i++) | ||
185 | { | ||
186 | struct GNUNET_PeerIdentity peer_id; | ||
187 | |||
188 | GNUNET_PEER_resolve (p->peers[i], &peer_id); | ||
189 | LOG (GNUNET_ERROR_TYPE_DEBUG, " %u: %s\n", p->peers[i], | ||
190 | GNUNET_i2s (&peer_id)); | ||
191 | } | ||
192 | #endif | ||
193 | return p; | 143 | return p; |
194 | } | 144 | } |
195 | 145 | ||