diff options
author | Nathan S. Evans <evans@in.tum.de> | 2010-08-02 14:19:28 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2010-08-02 14:19:28 +0000 |
commit | 0b1207500e87f664ac45f1bdea94e99e2c68cf4d (patch) | |
tree | c6511a3e3ba23e41c75536e5d504bcde72dc6c0f /src | |
parent | 37bec3a36d6e49ff881cc3a52a587d5df131999e (diff) | |
download | gnunet-0b1207500e87f664ac45f1bdea94e99e2c68cf4d.tar.gz gnunet-0b1207500e87f664ac45f1bdea94e99e2c68cf4d.zip |
don't try to connect to all peers, but only those advantageous for routing
Diffstat (limited to 'src')
-rw-r--r-- | src/dht/dht.h | 2 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht.c | 39 |
2 files changed, 36 insertions, 5 deletions
diff --git a/src/dht/dht.h b/src/dht/dht.h index 82554dbaf..041949795 100644 --- a/src/dht/dht.h +++ b/src/dht/dht.h | |||
@@ -214,7 +214,7 @@ struct GNUNET_DHT_P2PRouteMessage | |||
214 | * route message, what should it do? It can either drop the message | 214 | * route message, what should it do? It can either drop the message |
215 | * or try to forward it towards the original peer... However, for | 215 | * or try to forward it towards the original peer... However, for |
216 | * that to work we would need to include the original peer identity | 216 | * that to work we would need to include the original peer identity |
217 | * in the GET request, which adds even more data to the message. | 217 | * in the GET request, which adds more data to the message. |
218 | */ | 218 | */ |
219 | struct GNUNET_DHT_P2PRouteResultMessage | 219 | struct GNUNET_DHT_P2PRouteResultMessage |
220 | { | 220 | { |
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c index ba4aea2ae..f28e39932 100644 --- a/src/dht/gnunet-service-dht.c +++ b/src/dht/gnunet-service-dht.c | |||
@@ -1112,6 +1112,32 @@ send_reply_to_client (struct ClientList *client, | |||
1112 | add_pending_message (client, pending_message); | 1112 | add_pending_message (client, pending_message); |
1113 | } | 1113 | } |
1114 | 1114 | ||
1115 | /** | ||
1116 | * Consider whether or not we would like to have this peer added to | ||
1117 | * our routing table. Check whether bucket for this peer is full, | ||
1118 | * if so return negative; if not return positive. Since peers are | ||
1119 | * only added on CORE level connect, this doesn't actually add the | ||
1120 | * peer to the routing table. | ||
1121 | * | ||
1122 | * @param peer the peer we are considering adding | ||
1123 | * | ||
1124 | * @return GNUNET_YES if we want this peer, GNUNET_NO if not (bucket | ||
1125 | * already full) | ||
1126 | * | ||
1127 | * FIXME: Think about making a context for this call so that we can | ||
1128 | * ping the oldest peer in the current bucket and consider | ||
1129 | * removing it in lieu of the new peer. | ||
1130 | */ | ||
1131 | static int consider_peer (struct GNUNET_PeerIdentity *peer) | ||
1132 | { | ||
1133 | int bucket; | ||
1134 | |||
1135 | bucket = find_current_bucket(&peer->hashPubKey); | ||
1136 | if ((k_buckets[bucket].peers_size < bucket_size) || ((bucket == lowest_bucket) && (lowest_bucket > 0))) | ||
1137 | return GNUNET_YES; | ||
1138 | |||
1139 | return GNUNET_NO; | ||
1140 | } | ||
1115 | 1141 | ||
1116 | /** | 1142 | /** |
1117 | * Main function that handles whether or not to route a result | 1143 | * Main function that handles whether or not to route a result |
@@ -1125,6 +1151,7 @@ static int route_result_message(void *cls, | |||
1125 | struct GNUNET_MessageHeader *msg, | 1151 | struct GNUNET_MessageHeader *msg, |
1126 | struct DHT_MessageContext *message_context) | 1152 | struct DHT_MessageContext *message_context) |
1127 | { | 1153 | { |
1154 | struct GNUNET_PeerIdentity new_peer; | ||
1128 | struct DHTQueryRecord *record; | 1155 | struct DHTQueryRecord *record; |
1129 | struct DHTRouteSource *pos; | 1156 | struct DHTRouteSource *pos; |
1130 | struct PeerInfo *peer_info; | 1157 | struct PeerInfo *peer_info; |
@@ -1145,15 +1172,19 @@ static int route_result_message(void *cls, | |||
1145 | GNUNET_break_op(0); | 1172 | GNUNET_break_op(0); |
1146 | 1173 | ||
1147 | hello_msg = &msg[1]; | 1174 | hello_msg = &msg[1]; |
1148 | if (ntohs(hello_msg->type) != GNUNET_MESSAGE_TYPE_HELLO) | 1175 | if ((ntohs(hello_msg->type) != GNUNET_MESSAGE_TYPE_HELLO) || (GNUNET_SYSERR == GNUNET_HELLO_get_id(hello_msg, &new_peer))) |
1149 | { | 1176 | { |
1150 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s:%s Received non-HELLO message type in find peer result message!\n", my_short_id, "DHT"); | 1177 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s:%s Received non-HELLO message type in find peer result message!\n", my_short_id, "DHT"); |
1151 | GNUNET_break_op(0); | 1178 | GNUNET_break_op(0); |
1152 | } | 1179 | } |
1153 | else | 1180 | else /* We have a valid hello, and peer id stored in new_peer */ |
1154 | { | 1181 | { |
1155 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s:%s Received HELLO message for another peer, offering to transport!\n", my_short_id, "DHT"); | 1182 | if (GNUNET_YES == consider_peer(&new_peer)) |
1156 | GNUNET_TRANSPORT_offer_hello(transport_handle, hello_msg); | 1183 | { |
1184 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s:%s Received HELLO message for another peer, offering to transport!\n", my_short_id, "DHT"); | ||
1185 | GNUNET_TRANSPORT_offer_hello(transport_handle, hello_msg); | ||
1186 | GNUNET_CORE_peer_request_connect(sched, cfg, GNUNET_TIME_UNIT_FOREVER_REL, &new_peer, NULL, NULL); /* FIXME: Do we need this??? */ | ||
1187 | } | ||
1157 | } | 1188 | } |
1158 | 1189 | ||
1159 | } | 1190 | } |