Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPUtils.java')
-rw-r--r--protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPUtils.java46
1 files changed, 46 insertions, 0 deletions
diff --git a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPUtils.java b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPUtils.java
index cc9a9398b..afe39785e 100644
--- a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPUtils.java
+++ b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPUtils.java
@@ -9,6 +9,8 @@
* Contributors:
* Jan S. Rellermeyer - initial API and implementation
* Markus Alexander Kuppe - enhancements and bug fixes
+ * Md.Jamal MohiUddin (Ubiquitous Computing, C-DAC Hyderabad) - IPv6 support
+ * P Sowjanya (Ubiquitous Computing, C-DAC Hyderabad) - IPv6 support
*
*****************************************************************************/
package ch.ethz.iks.slp.impl;
@@ -23,6 +25,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import ch.ethz.iks.slp.ServiceType;
+
/**
* Utility class.
*
@@ -244,4 +248,46 @@ final class SLPUtils {
: equalsWithWildcard(val, ++valIndex, attr, ++attrIndex);
}
}
+
+ static String hash(ServiceType aType) {
+ String service = extractService(aType.toString());
+ return hash(service);
+ }
+
+ /* Hash Algorithm for SLP Service Type String(RFC 3111) */
+ private static String hash(String pc) {
+ String ip = "FF02::1:1";
+
+ /*
+ * An unsigned 32-bit value v is initialized to 0.Each byte of the
+ * character is considered consecutively
+ */
+ int h = 0;
+
+ for (int i = 0; i < pc.length(); i++) {
+ /*
+ * The current value v is multiplied by 33.then the value of the
+ * current string byte is added ,Each byte in the service type
+ * string is processed in this manner
+ */
+ h *= 33;
+ h += pc.charAt(i);
+ }
+ /* The result is contained in the low order 10 bits of v */
+ int j = (0x3ff & h);
+ // Concatenating the value with the IP
+ return ip + Integer.toHexString(j);
+ }
+
+ private static String extractService(String url) {
+ int position = url.indexOf(':', 0);
+ if (position == -1) {
+ return url;
+ }
+ position = url.indexOf(':', position + 1);
+ if (position == -1) {
+ return url;
+ }
+ return url.substring(0, position);
+ }
}

Back to the top