Skip to content

Commit

Permalink
Move getLabelFor to NumberCompress since it's EncodingScheme specific
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdelisle committed Apr 11, 2015
1 parent 286d9e3 commit a2d5c34
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
2 changes: 1 addition & 1 deletion dht/dhtcore/RouterModule.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ static inline int sendNodes(struct NodeList* nodeList,
struct Address addr;
Bits_memcpyConst(&addr, &nodeList->nodes[i]->address, sizeof(struct Address));

addr.path = LabelSplicer_getLabelFor(addr.path, query->address->path);
addr.path = NumberCompress_getLabelFor(addr.path, query->address->path);

Address_serialize(&nodes->bytes[i * Address_SERIALIZED_SIZE], &addr);

Expand Down
26 changes: 0 additions & 26 deletions switch/LabelSplicer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#ifndef LabelSplicer_H
#define LabelSplicer_H

#include "switch/NumberCompress.h"
#include "util/Bits.h"

#include <stdint.h>
Expand Down Expand Up @@ -50,31 +49,6 @@ static inline uint64_t LabelSplicer_splice(uint64_t goHere, uint64_t viaHere)
return ((goHere ^ 1) << log2ViaHere) ^ viaHere;
}

/**
* Get the label for a particular destination from a given source.
* This needs to be called before handing out a label because if a source interface is
* represented using more bits than the destination interface, the destination interface
* must be padded out so that the switch will find the source and destination labels compatable.
*
* @param target the label for the location to send to in host byte order.
* @param whoIsAsking the label for the node which we are sending the target to in host byte order.
* @return the modified target for that node in host byte order.
*/
static inline uint64_t LabelSplicer_getLabelFor(uint64_t target, uint64_t whoIsAsking)
{
uint32_t targetBits = NumberCompress_bitsUsedForLabel(target);
uint32_t whoIsAskingBits = NumberCompress_bitsUsedForLabel(whoIsAsking);

if (targetBits >= whoIsAskingBits) {
return target;
}

uint32_t targetIfaceNum = NumberCompress_getDecompressed(target, targetBits);

return ((target & (UINT64_MAX << targetBits)) << (whoIsAskingBits - targetBits))
| NumberCompress_getCompressed(targetIfaceNum, whoIsAskingBits);
}

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

/**
* Get the label for a particular destination from a given source.
* This needs to be called before handing out a label because if a source interface is
* represented using more bits than the destination interface, the destination interface
* must be padded out so that the switch will find the source and destination labels compatable.
*
* @param target the label for the location to send to in host byte order.
* @param whoIsAsking the label for the node which we are sending the target to in host byte order.
* @return the modified target for that node in host byte order.
*/
static inline uint64_t NumberCompress_getLabelFor(uint64_t target, uint64_t whoIsAsking)
{
uint32_t targetBits = NumberCompress_bitsUsedForLabel(target);
uint32_t whoIsAskingBits = NumberCompress_bitsUsedForLabel(whoIsAsking);

if (targetBits >= whoIsAskingBits) {
return target;
}

uint32_t targetIfaceNum = NumberCompress_getDecompressed(target, targetBits);

return ((target & (UINT64_MAX << targetBits)) << (whoIsAskingBits - targetBits))
| NumberCompress_getCompressed(targetIfaceNum, whoIsAskingBits);
}

#endif

0 comments on commit a2d5c34

Please sign in to comment.