public void testUnicode()
 {
     Name.Component comp1 = new Name.Component("entr\u00E9e");
     String expected = "entr%C3%A9e";
     Assert.AssertEquals("Unicode URI not decoded correctly", expected,
             comp1.toEscapedString());
 }
Exemple #2
0
 /// <summary>
 /// Create a new MetaInfo with default values.
 /// </summary>
 ///
 public MetaInfo()
 {
     this.type_ = net.named_data.jndn.ContentType.BLOB;
     this.otherTypeCode_ = -1;
     this.freshnessPeriod_ = -1;
     this.finalBlockId_ = new Name.Component();
     this.changeCount_ = 0;
 }
Exemple #3
0
 /// <summary>
 /// Create a new MetaInfo with a copy of the fields in the given metaInfo.
 /// </summary>
 ///
 /// <param name="metaInfo">The MetaInfo to copy.</param>
 public MetaInfo(MetaInfo metaInfo)
 {
     this.type_ = net.named_data.jndn.ContentType.BLOB;
     this.otherTypeCode_ = -1;
     this.freshnessPeriod_ = -1;
     this.finalBlockId_ = new Name.Component();
     this.changeCount_ = 0;
     type_ = metaInfo.type_;
     freshnessPeriod_ = metaInfo.freshnessPeriod_;
     // Name.Component is read-only, so we don't need a deep copy.
     finalBlockId_ = metaInfo.finalBlockId_;
 }
 /// <summary>
 /// Create a new MemoryContentCache to use the given Face.
 /// </summary>
 ///
 /// <param name="face"></param>
 /// <param name="cleanupIntervalMilliseconds">large number, then effectively the stale content will not be removed from the cache.</param>
 public MemoryContentCache(Face face, double cleanupIntervalMilliseconds)
 {
     this.onDataNotFoundForPrefix_ = new Hashtable();
     this.interestFilterIdList_ = new ArrayList<Int64>();
     this.registeredPrefixIdList_ = new ArrayList<Int64>();
     this.noStaleTimeCache_ = new ArrayList<Content>();
     this.staleTimeCache_ = new ArrayList<StaleTimeContent>();
     this.emptyComponent_ = new Name.Component();
     this.pendingInterestTable_ = new ArrayList<PendingInterest>();
     face_ = face;
     cleanupIntervalMilliseconds_ = cleanupIntervalMilliseconds;
     construct();
 }
        public void testHashCode()
        {
            Name.Component foo1 = new Name.Component("foo");
            Name.Component foo2 = new Name.Component("foo");

            Assert.AssertEquals("Hash codes for same strings are not equal",
                    foo1.GetHashCode(), foo2.GetHashCode());

            Name.Component bar = new Name.Component("bar");
            // Strictly speaking, it is possible for a hash collision, but unlikely.
            Assert.AssertTrue("Hash codes for different strings are not different",
                    foo1.GetHashCode() != bar.GetHashCode());
        }
Exemple #6
0
        public void set(String uri)
        {
            clear();

            uri = uri.trim();
            if (uri.Length == 0)
                return;

            int iColon = uri.indexOf(':');
            if (iColon >= 0) {
                // Make sure the colon came before a '/'.
                int iFirstSlash = uri.indexOf('/');
                if (iFirstSlash < 0 || iColon < iFirstSlash)
                    // Omit the leading protocol such as ndn:
                    uri = uri.Substring(iColon + 1).trim();
            }

            // Trim the leading slash and possibly the authority.
            if (uri[0] == '/') {
                if (uri.Length >= 2 && uri[1] == '/') {
                    // Strip the authority following "//".
                    int iAfterAuthority = uri.indexOf('/', 2);
                    if (iAfterAuthority < 0)
                        // Unusual case: there was only an authority.
                        return;
                    else
                        uri = uri.Substring(iAfterAuthority + 1).trim();
                } else
                    uri = uri.Substring(1).trim();
            }

            int iComponentStart = 0;

            // Unescape the components.
            String sha256digestPrefix = "sha256digest=";
            while (iComponentStart < uri.Length) {
                int iComponentEnd = ILOG.J2CsMapping.Util.StringUtil.IndexOf(uri,"/",iComponentStart);
                if (iComponentEnd < 0)
                    iComponentEnd = uri.Length;

                Name.Component  component;
                if (sha256digestPrefix.regionMatches(0, uri, iComponentStart,
                        sha256digestPrefix.Length)) {
                    try {
                        component = net.named_data.jndn.Name.Component.fromImplicitSha256Digest(fromHex(uri,
                                iComponentStart + sha256digestPrefix.Length,
                                iComponentEnd));
                    } catch (EncodingException ex) {
                        throw new Exception(ex.Message);
                    }
                } else
                    component = new Name.Component (fromEscapedString(uri,
                            iComponentStart, iComponentEnd));

                // Ignore illegal components.  This also gets rid of a trailing '/'.
                if (!component.getValue().isNull())
                    append(component);

                iComponentStart = iComponentEnd + 1;
            }
        }
Exemple #7
0
            /// <summary>
            /// Create a component of type ImplicitSha256DigestComponent, so that
            /// isImplicitSha256Digest() is true.
            /// </summary>
            ///
            /// <param name="digest">The SHA-256 digest value.</param>
            /// <returns>The new Component.</returns>
            /// <exception cref="EncodingException">If the digest length is not 32 bytes.</exception>
            public static Name.Component fromImplicitSha256Digest(Blob digest)
            {
                if (digest.size() != 32)
                    throw new EncodingException(
                            "Name.Component.fromImplicitSha256Digest: The digest length must be 32 bytes");

                Name.Component  result = new Name.Component (digest);
                result.type_ = net.named_data.jndn.Name.Component.ComponentType.IMPLICIT_SHA256_DIGEST;
                return result;
            }
 public void setUp()
 {
     expectedURI = "/entr%C3%A9e/..../%00%01%02%03";
     comp2 = new Name.Component(new Blob(
             new int[] { 0x00, 0x01, 0x02, 0x03 }));
 }
Exemple #9
0
 /// <summary>
 /// Create an Exclude.Entry of type COMPONENT.
 /// </summary>
 ///
 /// <param name="component">The component value.</param>
 public Entry(Name.Component component)
 {
     type_ = net.named_data.jndn.Exclude.Type.COMPONENT;
     component_ = component;
 }
Exemple #10
0
 /// <summary>
 /// Create an Exclude.Entry of type ANY
 /// </summary>
 ///
 public Entry()
 {
     type_ = net.named_data.jndn.Exclude.Type.ANY;
     component_ = null;
 }
        /**
         * Loop to encode a data packet nIterations times.
         * @param nIterations The number of iterations.
         * @param useComplex If true, use a large name, large content and all fields.
         * If false, use a small name, small content
         * and only required fields.
         * @param useCrypto If true, sign the data packet.  If false, use a blank
         * signature.
         * @param keyType KeyType.RSA or EC, used if useCrypto is true.
         * @param encoding Set encoding[0] to the wire encoding.
         * @return The number of seconds for all iterations.
         */
        private static double benchmarkEncodeDataSeconds(int nIterations, bool useComplex, bool useCrypto, KeyType keyType,
        Blob[] encoding)
        {
            Name name;
              Blob content;
              if (useComplex) {
            // Use a large name and content.
            name = new Name
              ("/ndn/ucla.edu/apps/lwndn-test/numbers.txt/%FD%05%05%E8%0C%CE%1D/%00");

            StringBuilder contentStream = new StringBuilder();
            int count = 1;
            contentStream.append(count++);
            while (contentStream.toString().Length < 1115)
              contentStream.append(" ").append(count++);
            content = new Blob(contentStream.toString());
              }
              else {
            // Use a small name and content.
            name = new Name("/test");
            content = new Blob("abc");
              }
              Name.Component finalBlockId =
            new Name.Component(new Blob(new byte[] { (byte)0 }));

              // Initialize the KeyChain storage in case useCrypto is true.
              MemoryIdentityStorage identityStorage = new MemoryIdentityStorage();
              MemoryPrivateKeyStorage privateKeyStorage = new MemoryPrivateKeyStorage();
              KeyChain keyChain = new KeyChain
            (new IdentityManager(identityStorage, privateKeyStorage),
              new SelfVerifyPolicyManager(identityStorage));
              Name keyName = new Name("/testname/DSK-123");
              Name certificateName = keyName.getSubName(0, keyName.size() - 1).append
            ("KEY").append(keyName.get(-1)).append("ID-CERT").append("0");
              privateKeyStorage.setKeyPairForKeyName
              (keyName, KeyType.RSA, new ByteBuffer(DEFAULT_RSA_PUBLIC_KEY_DER),
            new ByteBuffer(DEFAULT_RSA_PRIVATE_KEY_DER));

              Blob signatureBits = new Blob(new byte[256]);
              Blob emptyBlob = new Blob(new byte[0]);

              double start = getNowSeconds();
              for (int i = 0; i < nIterations; ++i) {
            Data data = new Data(name);
            data.setContent(content);
            if (useComplex) {
              data.getMetaInfo().setFreshnessPeriod(30000);
              data.getMetaInfo().setFinalBlockId(finalBlockId);
            }

            if (useCrypto)
              // This sets the signature fields.
              keyChain.sign(data, certificateName);
            else {
              // Imitate IdentityManager.signByCertificate to set up the signature
              //   fields, but don't sign.
              KeyLocator keyLocator = new KeyLocator();
              keyLocator.setType(KeyLocatorType.KEYNAME);
              keyLocator.setKeyName(certificateName);
              Sha256WithRsaSignature sha256Signature =
            (Sha256WithRsaSignature)data.getSignature();
              sha256Signature.setKeyLocator(keyLocator);
              sha256Signature.setSignature(signatureBits);
            }

            encoding[0] = data.wireEncode();
              }
              double finish = getNowSeconds();

              return finish - start;
        }
Exemple #12
0
 public void setFinalBlockId(Name.Component finalBlockId)
 {
     finalBlockId_ = ((finalBlockId == null) ? new Name.Component()
             : finalBlockId);
     ++changeCount_;
 }
Exemple #13
0
            public ExcludeEntry(Name.Component component,
					bool anyFollowsComponent)
            {
                component_ = component;
                anyFollowsComponent_ = anyFollowsComponent;
            }