def onInterest(self, prefix, interest, *k): print >> sys.stderr, "<< PyNDN %s" % interest.name intrestUri = interest.name.toUri() prefixUri = prefix.toUri() parameters = '' if intrestUri != prefixUri: parameters = intrestUri[len(prefixUri) + 1:] print prefixUri += "/%3Cdata%3E" d = self.a[prefixUri] if self.methods[prefixUri] == "POST": content = json.dumps( d(interest.getContent().toRawStr().decode('string_escape'))) else: if parameters: content = json.dumps(d(parameters)) else: content = json.dumps(d()) self.counter += 1 data = ndn.Data(interest.getName()) meta = ndn.MetaInfo() meta.setFreshnessPeriod(5000) data.setMetaInfo(meta) data.setContent(content) self.keyChain.sign(data, self.keyChain.getDefaultCertificateName()) self.face.putData(data)
def _onInterest(self, prefix, interest, *k): print >> sys.stderr, "<< PyNDN %s" % interest.name content = "PyNDN LINE #%d\n" % self.counter self.counter += 1 data = ndn.Data(interest.getName()) meta = ndn.MetaInfo() meta.setFreshnessPeriod(5000) data.setMetaInfo(meta) data.setContent(content) self.keyChain.sign(data, self.keyChain.getDefaultCertificateName()) self.face.putData(data)
def onInterest(self, prefix, interest, *k): print >> sys.stderr, "<< PyNDN %s" % interest.name print prefix d = self.a[prefix] if self.methods[prefix] == "POST": content = json.dumps( d(interest.getContent().toRawStr().decode('string_escape'))) else: content = json.dumps(d()) self.counter += 1 #print interest.getContent().toRawStr().decode('string_escape') data = ndn.Data(interest.getName()) meta = ndn.MetaInfo() meta.setFreshnessPeriod(5000) data.setMetaInfo(meta) data.setContent(content) self.keyChain.sign(data, self.keyChain.getDefaultCertificateName()) self.face.putData(data)
def setup(self, name): self.apk, self.ask = self.abs.authSetup() self.self_attributes = [b'self', name.toUri().encode('utf-8')] self.db.save('apk', utils.serialize(self.apk, self.abs.group)) self.db.save('ask', utils.serialize(self.ask, self.abs.group)) data = pyndn.Data( pyndn.Name(name).append("ABS").appendVersion( datetime.timestamp(datetime.now()))) meta = pyndn.MetaInfo() meta.setType(pyndn.ContentType.KEY) meta.setFreshnessPeriod(86400 * 1000.0) # 1 day data.setMetaInfo(meta) data.setContent(self.db.load('apk')) signer = Signer(self.db) signer._install_pk(self.db.load('apk')) signer.install_secret(self.gen_attr_keys(self.self_attributes)) signer.sign(data, self.self_attributes, selfSign=True) signer.install_public_params( base64.b64encode(data.wireEncode().toBytes()))