public override long expressInterest(Interest interest, OnData onData,
                                                 OnTimeout onTimeout, OnNetworkNack onNetworkNack,
                                                 WireFormat wireFormat)
            {
                try {
                    Assert.AssertEquals(3, interest.getLink().getDelegations().size());
                } catch (EncodingException ex) {
                    Assert.Fail("Error in getLink: " + ex);
                }

                if (interest.matchesName(contentData_.getName()))
                {
                    contentCount_[0] = 1;
                    onData.onData(interest, contentData_);
                }
                else if (interest.matchesName(cKeyData_.getName()))
                {
                    cKeyCount_[0] = 1;
                    onData.onData(interest, cKeyData_);
                }
                else if (interest.matchesName(dKeyData_.getName()))
                {
                    dKeyCount_[0] = 1;
                    onData.onData(interest, dKeyData_);
                }
                else
                {
                    onTimeout.onTimeout(interest);
                }

                return(0);
            }
            public override long expressInterest(Interest interest, OnData onData,
                                                 OnTimeout onTimeout, OnNetworkNack onNetworkNack,
                                                 WireFormat wireFormat)
            {
                if (interest.matchesName(contentData_.getName()))
                {
                    contentCount_[0] = 1;
                    onData.onData(interest, contentData_);
                }
                else if (interest.matchesName(cKeyData_.getName()))
                {
                    cKeyCount_[0] = 1;
                    onData.onData(interest, cKeyData_);
                }
                else if (interest.matchesName(dKeyData_.getName()))
                {
                    dKeyCount_[0] = 1;
                    onData.onData(interest, dKeyData_);
                }
                else
                {
                    onTimeout.onTimeout(interest);
                }

                return(0);
            }
Beispiel #3
0
            public override long expressInterest(Interest interest, OnData onData,
                                                 OnTimeout onTimeout, OnNetworkNack onNetworkNack,
                                                 WireFormat wireFormat)
            {
                Assert.AssertEquals(expectedInterest_, interest.getName());

                bool gotInterestName = false;
                Name interestName    = null;

                for (int i = 0; i < 3; ++i)
                {
                    interestName = new Name(interest.getName());
                    if (i == 0)
                    {
                        interestName.append(timeMarkerFirstHop_);
                    }
                    else if (i == 1)
                    {
                        interestName.append(timeMarkerSecondHop_);
                    }
                    else if (i == 2)
                    {
                        interestName.append(timeMarkerThirdHop_);
                    }

                    // matchesName will check the Exclude.
                    if (interest.matchesName(interestName))
                    {
                        gotInterestName = true;
                        ++requestCount_[0];
                        break;
                    }
                }

                if (gotInterestName)
                {
                    onData.onData(interest,
                                  (Data)ILOG.J2CsMapping.Collections.Collections.Get(outer_TestProducer.encryptionKeys, interestName));
                }

                return(0);
            }
Beispiel #4
0
        public void onInterest(Name prefix, Interest interest, Face face,
                               long interestFilterId, InterestFilter filter)
        {
            logger_.log(ILOG.J2CsMapping.Util.Logging.Level.INFO, "MemoryContentCache:  Received Interest {0}",
                        interest.toUri());

            double nowMilliseconds = net.named_data.jndn.util.Common.getNowMilliseconds();

            doCleanup(nowMilliseconds);

            Name.Component selectedComponent = null;
            Blob           selectedEncoding  = null;
            // We need to iterate over both arrays.
            int totalSize = staleTimeCache_.Count + noStaleTimeCache_.Count;

            for (int i = 0; i < totalSize; ++i)
            {
                MemoryContentCache.Content content;
                bool isFresh = true;
                if (i < staleTimeCache_.Count)
                {
                    MemoryContentCache.StaleTimeContent staleTimeContent = staleTimeCache_[i];
                    content = staleTimeContent;
                    isFresh = staleTimeContent.isFresh(nowMilliseconds);
                }
                else
                {
                    // We have iterated over the first array. Get from the second.
                    content = noStaleTimeCache_[i - staleTimeCache_.Count];
                }

                if (interest.matchesName(content.getName()) &&
                    !(interest.getMustBeFresh() && !isFresh))
                {
                    if (interest.getChildSelector() < 0)
                    {
                        // No child selector, so send the first match that we have found.
                        logger_.log(ILOG.J2CsMapping.Util.Logging.Level.INFO,
                                    "MemoryContentCache:         Reply Data {0}",
                                    content.getName());
                        try {
                            face.send(content.getDataEncoding());
                        } catch (IOException ex) {
                            logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, null, ex);
                        }
                        return;
                    }
                    else
                    {
                        // Update selectedEncoding based on the child selector.
                        Name.Component component;
                        if (content.getName().size() > interest.getName().size())
                        {
                            component = content.getName().get(
                                interest.getName().size());
                        }
                        else
                        {
                            component = emptyComponent_;
                        }

                        bool gotBetterMatch = false;
                        if (selectedEncoding == null)
                        {
                            // Save the first match.
                            gotBetterMatch = true;
                        }
                        else
                        {
                            if (interest.getChildSelector() == 0)
                            {
                                // Leftmost child.
                                if (component.compare(selectedComponent) < 0)
                                {
                                    gotBetterMatch = true;
                                }
                            }
                            else
                            {
                                // Rightmost child.
                                if (component.compare(selectedComponent) > 0)
                                {
                                    gotBetterMatch = true;
                                }
                            }
                        }

                        if (gotBetterMatch)
                        {
                            selectedComponent = component;
                            selectedEncoding  = content.getDataEncoding();
                        }
                    }
                }
            }

            if (selectedEncoding != null)
            {
                // We found the leftmost or rightmost child.
                try {
                    logger_.log(ILOG.J2CsMapping.Util.Logging.Level.INFO,
                                "MemoryContentCache: Reply Data to Interest {0}",
                                interest.toUri());
                    face.send(selectedEncoding);
                } catch (IOException ex_0) {
                    logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, null, ex_0);
                }
            }
            else
            {
                logger_.log(ILOG.J2CsMapping.Util.Logging.Level.INFO,
                            "MemoryContentCache: onDataNotFound for {0}",
                            interest.toUri());
                // Call the onDataNotFound callback (if defined).
                Object onDataNotFound = ILOG.J2CsMapping.Collections.Collections.Get(onDataNotFoundForPrefix_, prefix.toUri());
                if (onDataNotFound != null)
                {
                    try {
                        ((OnInterestCallback)onDataNotFound).onInterest(prefix,
                                                                        interest, face, interestFilterId, filter);
                    } catch (Exception ex_1) {
                        logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onDataNotFound", ex_1);
                    }
                }
            }
        }