Skip to content

Commit

Permalink
Removed LabelSplicer_isOneHop() because it's a compatibility landmine
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdelisle committed Apr 11, 2015
1 parent 8577b7e commit 76f2fba
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 41 deletions.
17 changes: 11 additions & 6 deletions dht/dhtcore/NodeStore.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ static bool isPeer(struct Node_Two* node, struct NodeStore_pvt* store)
{
if (!Node_getBestParent(node)) { return false; }
return Node_getBestParent(node)->parent == store->pub.selfNode
&& LabelSplicer_isOneHop(Node_getBestParent(node)->cannonicalLabel);
&& EncodingScheme_isOneHop(store->pub.selfNode->encodingScheme,
Node_getBestParent(node)->cannonicalLabel);
}

static void setParentReachAndPath(struct Node_Two* node,
Expand Down Expand Up @@ -391,7 +392,7 @@ static uint32_t subReach(uint32_t reachAB, uint32_t reachAC)
static uint32_t guessReachOfChild(struct Node_Link* link)
{
uint32_t r;
if (LabelSplicer_isOneHop(link->cannonicalLabel)) {
if (EncodingScheme_isOneHop(link->parent->encodingScheme, link->cannonicalLabel)) {
// Single-hop link, so guess that it's 3/4 the parent's reach
r = (Node_getReach(link->parent) * 3) / 4;
}
Expand Down Expand Up @@ -652,7 +653,7 @@ void NodeStore_unlinkNodes(struct NodeStore* nodeStore, struct Node_Link* link)
// yuh ok
if (link == store->selfLink) { return; }

Assert_true(LabelSplicer_isOneHop(link->cannonicalLabel));
Assert_true(EncodingScheme_isOneHop(parent->encodingScheme, link->cannonicalLabel));
store->pub.peerCount--;
if (Defined(Log_INFO)) {
uint8_t addr[60];
Expand Down Expand Up @@ -811,7 +812,7 @@ static struct Node_Link* linkNodes(struct Node_Two* parent,
update(link, linkStateDiff, store);

if (parent == store->pub.selfNode && child != store->pub.selfNode) {
Assert_true(LabelSplicer_isOneHop(cannonicalLabel));
Assert_true(EncodingScheme_isOneHop(parent->encodingScheme, cannonicalLabel));
store->pub.peerCount++;
if (Defined(Log_DEBUG)) {
uint8_t addr[60];
Expand Down Expand Up @@ -994,7 +995,9 @@ static struct Node_Link* discoverLinkC(struct NodeStore_pvt* store,
Log_debug(store->logger, "discoverLinkC( [%s]->[%s] [%s] )", parentStr, childStr, pathStr);
}

if (closest == store->selfLink && !LabelSplicer_isOneHop(pathParentChild)) {
if (closest == store->selfLink &&
!EncodingScheme_isOneHop(parent->encodingScheme, pathParentChild))
{
Log_debug(store->logger, "Attempting to create a link with no parent peer");
return NULL;
}
Expand Down Expand Up @@ -1939,7 +1942,9 @@ struct NodeList* NodeStore_getPeers(uint64_t label,
struct Node_Link* next = NULL;
RB_FOREACH(next, PeerRBTree, &store->pub.selfNode->peerTree) {
uint64_t p = next->child->address.path;
if (!LabelSplicer_isOneHop(p) && p != 1) { continue; }
if (!EncodingScheme_isOneHop(store->pub.selfNode->encodingScheme, p) && p != 1) {
continue;
}
if (p < label) { continue; }
int j;
for (j = 0; j < (int)max; j++) {
Expand Down
3 changes: 2 additions & 1 deletion dht/dhtcore/RouterModule.c
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,8 @@ void RouterModule_peerIsReachable(uint64_t pathToPeer,
uint64_t lagMilliseconds,
struct RouterModule* module)
{
Assert_ifParanoid(LabelSplicer_isOneHop(pathToPeer));
Assert_ifParanoid(EncodingScheme_isOneHop(module->nodeStore->selfNode->encodingScheme,
pathToPeer));
struct Node_Two* nn = RouterModule_nodeForPath(pathToPeer, module);
for (struct Node_Link* peerLink = nn->reversePeers; peerLink; peerLink = peerLink->nextPeer) {
if (peerLink->parent != module->nodeStore->selfNode) { continue; }
Expand Down
11 changes: 0 additions & 11 deletions switch/LabelSplicer.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,6 @@ static inline uint64_t LabelSplicer_getLabelFor(uint64_t target, uint64_t whoIsA
| NumberCompress_getCompressed(targetIfaceNum, whoIsAskingBits);
}

/**
* Determine if the node at the end of the given label is one hop away.
*
* @param label the label to test in host byte order.
* @return true if the node is 1 hop away, false otherwise.
*/
static inline bool LabelSplicer_isOneHop(uint64_t label)
{
return (int)NumberCompress_bitsUsedForLabel(label) == Bits_log2x64(label);
}

/**
* Determine if the route to one node passes through another node.
* Given:
Expand Down
11 changes: 0 additions & 11 deletions switch/NumberCompress.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,4 @@ static inline uint32_t NumberCompress_v4x8_bitsUsedForNumber(const uint32_t numb
#define NumberCompress_decompress(label) \
NumberCompress_getDecompressed(label, NumberCompress_bitsUsedForLabel(label))

/**
* Determine if the node at the end of the given label is one hop away.
*
* @param label the label to test in host byte order.
* @return true if the node is 1 hop away, false otherwise.
*/
static inline bool NumberCompress_isOneHop(uint64_t label)
{
return (int)NumberCompress_bitsUsedForLabel(label) == Bits_log2x64(label);
}

#endif
12 changes: 0 additions & 12 deletions switch/test/LabelSplicer_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,6 @@ static void splice()
Assert_true(expected == out);
}

static uint64_t routeToInterface(uint32_t number)
{
uint32_t bits = NumberCompress_bitsUsedForNumber(number);
return (1 << bits) | NumberCompress_getCompressed(number, bits);
}

static void isOneHop()
{
Assert_true(LabelSplicer_isOneHop(routeToInterface(0)));
}

static void routesThrough()
{
uint64_t dst = Constant_base2(0000000000000000100100000000101011101010100101011100101001010101);
Expand All @@ -61,7 +50,6 @@ static void routesThrough()
int main()
{
splice();
isOneHop();
routesThrough();
unsplice();
return 0;
Expand Down

0 comments on commit 76f2fba

Please sign in to comment.