def __init__(self, prefix, callback): self.gui_callback = callback self.friendly_names = {} self.handle = pyndn.NDN() self.chat_uri = pyndn.Name(prefix) self.members_uri = self.chat_uri + "members" self.net_pull = VersionedPull(self.chat_uri, None, handle=self.handle) self.default_key = self.handle.getDefaultKey() digest = fix_digest(self.default_key.publicKeyID) self.friendly_names[digest] = getpass.getuser()
def __init__(self, name, mydata, **kwargs): self.name = pyndn.Name(name) #not include segment number and version number self.handle = pyndn.NDN() self.exclusions = pyndn.ExclusionFilter() self.interest_schema = kwargs.get("interest_schema", "id") self.mod = kwargs.get("mod", "non-adatpive") self.default_block_size = kwargs.get("default_block_size", DEFAULT_BLOCK_SIZE) self.mydata = mydata s = os.path.basename(name) if os.path.exists(s): log.info("file %s will be replaced " %(s)) self.file_out = open(s, "w") self.chunkinfo = None
def __init__(self, prefix, nick=getpass.getuser()): self.handle = pyndn.NDN() self.flow = FlowController(prefix, self.handle) #XXX: temporary, until we allow fetching key from key storage self.key = self.handle.getDefaultKey() self.keylocator = pyndn.KeyLocator(self.key) self.prefix = pyndn.Name(prefix) self.members_uri = self.prefix + "members" member_name = self.members_uri.appendKeyID( fix_digest(self.key.publicKeyID)) self.member_message = self.publish(member_name, nick) self.flow.put(self.member_message)
def main(args): if len(sys.argv) != 2: usage() name = pyndn.Name(sys.argv[1]) data = ndnb_enumerate(generate_names()) key = pyndn.NDN.getDefaultKey() name = name.append('\xc1.E.be').appendKeyID(key).appendVersion() wrapper = Wrapper(name, key) sgmtr = segmenter(data, wrapper) handle = pyndn.NDN() for seg in sgmtr: handle.put(seg) return 0
def __init__(self, base_name, callback, handle=None, version=None, latest=True): handle = handle or pyndn.NDN() # some constants self.version_marker = '\xfd' self.first_version_marker = self.version_marker self.last_version_marker = '\xfe\x00\x00\x00\x00\x00\x00' self.base_name = pyndn.Name(base_name) self.callback = callback self.handle = handle self.latest_version = version or self.first_version_marker self.start_with_latest = latest
def __init__(self, name, mydata, content_path=None, **kwargs): self.name = pyndn.Name( name) #not include segment number and version number self.handle = pyndn.NDN() self.exclusions = pyndn.ExclusionFilter() self.mod = kwargs.get("mod", "non-adatpive") self.default_block_size = kwargs.get("default_block_size", DEFAULT_BLOCK_SIZE) self.mydata = mydata s = content_path if s == None: s = os.path.basename(name) if os.path.exists(s): log.info("file %s will be published with name %s " % (s, name)) else: log.error("%s is not exist under %s directory" % (s, "current" if content_path == None else "the")) exit(0) self.file_in = open(s, "rb") self.file_size = os.path.getsize(s)
return bytes(x) class sendMessage(threading.Thread): def run(self): po = Popen(['ndnput', '-x', '5', '-t', 'ENCR', 'ndn:/messages/hello'], stdin=PIPE) po.communicate(arrgh("Hello everyone")) # po.stdin.close() po.wait() thread = sendMessage() name = pyndn.Name("ndn:/messages/hello") handle = pyndn.NDN() thread.start() co = handle.get(name) thread.join() print(co) print(co.content) print(type(co.content)) assert co.content == bytearray(b"Hello everyone") print(co.name) assert str(co.name) == "/messages/hello" signedinfo = co.signedInfo assert signedinfo.type == pyndn.CONTENT_ENCR
def __init__(self, root, handle=None): self.root = pyndn.Name(root) self.exclusions = pyndn.ExclusionFilter() self.handle = handle or pyndn.NDN()
def __init__(self, name, content): self.handle = pyndn.NDN() self.name = pyndn.Name(name) self.content = self.prepareContent(content, self.handle.getDefaultKey())
# SignedInfo si = pyndn.SignedInfo() si.type = pyndn.CONTENT_DATA si.finalBlockID = pyndn.Name.num2seg(0) si.publisherPublicKeyDigest = key.publicKeyID si.keyLocator = keylocator # ContentObject co = pyndn.ContentObject() co.content = content co.name = co_name co.signedInfo = si co.sign(key) return co def callback(kind, info): print(info.ContentObject.content) fc = FlowController("/test", pyndn.NDN()) fc.put(publish('/test/1', 'one')) fc.put(publish('/test/2', 'two')) fc.put(publish('/test/3', 'three')) vp = VersionedPull("/chat", callback) el = pyndn.EventLoop(fc.handle, vp.handle) while True: vp.requestNext() el.run_once() time.sleep(1)