Skip to content

Commit

Permalink
Assume nodes are protocol v1 by default and ignore v1 nodes' version …
Browse files Browse the repository at this point in the history
…hints because they're wrong.
  • Loading branch information
Caleb James DeLisle committed Feb 22, 2013
1 parent f138d9d commit b12fc89
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
12 changes: 10 additions & 2 deletions dht/dhtcore/RouterModule.c
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,14 @@ static inline int handleReply(struct DHTMessage* message, struct RouterModule* m
String* versionsStr = Dict_getString(message->asDict, CJDHTConstants_NODE_PROTOCOLS);
if (versionsStr) {
versions = VersionList_parse(versionsStr, message->allocator);
#ifdef Version_1_COMPAT
// Version 1 lies about the versions of other nodes, assume they're all v1.
if (version < 2) {
for (int i = 0; i < (int)versions->length; i++) {
versions->versions[i] = 1;
}
}
#endif
}

// If this node has sent us any entries which are further from the target than it is,
Expand Down Expand Up @@ -867,8 +875,8 @@ static inline int handleReply(struct DHTMessage* message, struct RouterModule* m
break;
}

// Nodes we are told about are inserted with 0 reach.
uint32_t version = (versions) ? versions->versions[i / Address_SERIALIZED_SIZE] : 0;
// Nodes we are told about are inserted with 0 reach and assumed version 1.
uint32_t version = (versions) ? versions->versions[i / Address_SERIALIZED_SIZE] : 1;
NodeStore_addNode(module->nodeStore, &addr, 0, version);

if ((newNodePrefix ^ targetPrefix) >= parentDistance
Expand Down
1 change: 1 addition & 0 deletions util/version/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
*/
#define Version_CURRENT_PROTOCOL 1
#define Version_0_COMPAT
#define Version_1_COMPAT


/**
Expand Down

0 comments on commit b12fc89

Please sign in to comment.