Просмотр исходного кода

Move getLabelFor to NumberCompress since it's EncodingScheme specific

Caleb James DeLisle 9 лет назад
Родитель
Сommit
a2d5c34ca8
3 измененных файлов с 26 добавлено и 27 удалено
  1. 1 1
      dht/dhtcore/RouterModule.c
  2. 0 26
      switch/LabelSplicer.h
  3. 25 0
      switch/NumberCompress.h

+ 1 - 1
dht/dhtcore/RouterModule.c

@@ -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);
 

+ 0 - 26
switch/LabelSplicer.h

@@ -15,7 +15,6 @@
 #ifndef LabelSplicer_H
 #define LabelSplicer_H
 
-#include "switch/NumberCompress.h"
 #include "util/Bits.h"
 
 #include <stdint.h>
@@ -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:

+ 25 - 0
switch/NumberCompress.h

@@ -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