Project

General

Profile

Task #3290

Updated by Qiuhan Ding about 9 years ago

One module of the new Validator framework is `KeyManager` which manages trust anchors, verified keys, unverified keys, and key retrieval. 
 This issue designs KeyManager abstraction. 

     class KeyManager  
     { 
     public: 
       // create a KeyManager with @p face. 
       KeyManager(Face* face); 
      
       shared_ptr<const Data> void 
       retrieveTrustedCert(const Interest& interest); retrieve(const KeyRequest& req)  
       { 
         auto anchor anchorIt = m_anchors.find(interest); m_anchors.find(req.getInterest()); 
         if (anchor (anchorIt != nullptr) m_anchors.end()) { 
           return anchor; req.validationSuccessCallback(anchorIt->getData()); 
         } 

         auto key keyIt = m_verfiedKeyCache.find(interest); m_verfiedKeyCache.find(req.getInterest()); 
         if (keyIt != m_verfiedKeyCache.end()) { 
           return key; 
       req.validationSuccessCallback(keyIt->getData()); 
         } 

       // Retrieve unverified certificate 
       void 
       retrieveCertificate(shared_ptr<KeyRequest>& req, 
                           const RetrievalSuccessCallback& onRetrieval, 
                           const RetrievalFailureCallback& onFailure) 
       { 
         

         auto uKey uKeyIt = m_unverfiedKeyCache.find(req->interest); m_unverfiedKeyCache.find(req.getInterest()); 
         if (uKey (uKeyIt != nullptr) m_unverfiedKeyCache.end()) { 
           return onRetrieval(uKey, req); req.retrivalSuccessCallback(uKeyIt->getData()); 
         } 
        
         if (m_face != nullptr) 
           fetchKeyFromNetwork(req, onRetrieval, onFailure); 
         else 
           onFailure(req->interest, req); fetchKeyFromNetwork(req); 
       } 
      
       void  
       fetchKeyFromNetwork(shared_ptr<KeyRequest>& req, 
                           const RetrievalSuccessCallback& onRetrieval, 
                           const RetrievalFailureCallback& onFailure) fetchKeyFromNetwork(const KeyRequest& req) 
       { 
         preProcess(const_cast<KeyRequest&> req); 
         m_face->expressInterest(req.interest. onRetrieval, onFailure, onTimeout); m_face->expressInterest(req.getInterest(). res.retrivalSuccessCallback, res.retrivalTimeoutCallback); 
       } 

       void 
       loadAnchor(...); 
      
       void 
       loadVerifiedKey(...); 
    
       void 
       loadUnverifiedKey(...); 

       // call back when interest times out, will retry @p remainRetries times before falure 
       void 
       onTimeout(const Interest& interest, int remainRetries, 
                 shared_ptr<KeyRequest>& req, 
                 const RetrievalSuccessCallback& onRetrieval, 
                 const RetrievalFailureCallback& onFailure); 

     private: 
       virtual 
       preProcess(KeyRequest& req) = 0; 
      
     private: 
       Face* m_face; 
       TrustAnchorContainer m_anchors;             // trust anchors 
       CertificateCache       m_verfiedKeyCache;     // cache of verified keys. 
       DataCache              m_unverfiedKeyCache; // cache of unverified keys. 
     };

Back