def fetch_seek_query(self, ns): index = self.ts2index_add_1(ns) #debug(self, "Fetching segment number before %s" % index) interest = pyccn.Interest(publisherPublicKeyDigest=self.publisher_id, childSelector=1, answerOriginKind=pyccn.AOK_NONE) interest.exclude = pyccn.ExclusionFilter() interest.exclude.add_name(pyccn.Name([index])) interest.exclude.add_any() #debug(self, "Sending interest to %s" % self._name_frames) #debug(self, "Exclusion list %s" % interest.exclude) while True: co = self._get_handle.get(self._name_frames, interest) if co: break debug(self, "Timeout while seeking %d, retrying ..." % (ns)) debug(self, "Got segment: %s" % co.content) index = co.name[-1] segment = int(co.content) return (self.index2ts(index), segment)
def getLatestVersion(self, name): try: return self.m_keyCache[str(name)] except: pass base_len = len(name) excludeList = [] version = 0 co = None while True: interestName = pyccn.Name(name) exclude1 = pyccn.ExclusionFilter() exclude1.add_names([pyccn.Name().append(n) for n in excludeList]) interest_tmpl = pyccn.Interest(exclude=exclude1, interestLifetime=self.args.timeout, minSuffixComponents=1, maxSuffixComponents=100, scope=self.args.scope) class Slurp(pyccn.Closure): def __init__(self): self.finished = False self.done = False def upcall(self, kind, upcallInfo): if kind == pyccn.UPCALL_CONTENT or kind == pyccn.UPCALL_CONTENT_UNVERIFIED: self.co = upcallInfo.ContentObject if len(self.co.name) == base_len: self.done = True else: excludeList.append(self.co.name[base_len]) elif kind == pyccn.UPCALL_INTEREST_TIMED_OUT: self.done = True self.finished = True return pyccn.RESULT_OK slurp = Slurp() self.ccn.expressInterest(interestName, slurp, interest_tmpl) while not slurp.finished: # print slurp.finished self.ccn.run(1) if slurp.done: # print "Done with %s" % interestName break try: newversion = pyccn.Name.seg2num(slurp.co.name[len(name)]) if newversion > version: version = newversion co = slurp.co except: print "ERROR: Unversioned content object: %s" % interestName return None self.m_keyCache[str(name)] = co return co
def check_duration_initial(self): global packet_hdr, packethdr_len, segment_hdr, segment_hdr_len last_duration, duration = 0, 0 interest = pyccn.Interest(publisherPublicKeyDigest=self.publisher_id, childSelector=1, answerOriginKind=pyccn.AOK_DEFAULT) exclude = interest.exclude = pyccn.ExclusionFilter() while True: t_start = time.time() co = self._get_handle.get(self._name_frames, interest, 4200) t_end = time.time() if co is None: # break continue # packet = co.content # header = packet[:packet_hdr_len] # offset, count = struct.unpack(packet_hdr, header) # if count == 0 or len(packet) < packet_hdr_len + offset + segment_hdr_len: # continue # # offset += packet_hdr_len # header = packet[offset:offset + segment_hdr_len] # duration = struct.unpack(segment_hdr, header)[1] name = co.name[-1:] duration = pyccn.Name.seg2num(co.name[-1]) duration_s = duration / float(gst.SECOND) #t_packet = co.signedInfo.py_timestamp rtt = t_end - t_start #t_diff = t_start - t_packet print "Duration:", datetime.timedelta(seconds=duration_s) print "Duration diff:", duration_s - last_duration print "Rtt:", rtt print "Rtt diff", duration_s - last_duration - rtt #print "Packet timestamp:", time.ctime(t_packet) #print "Time difference:", datetime.timedelta(seconds = t_diff), t_diff if duration_s - last_duration - rtt < 0.001: break print "Excluding %r" % name exclude.reset() exclude.add_any() exclude.add_name(name) last_duration = duration_s return duration
def check_duration(self): interest = pyccn.Interest(childSelector=1) if self._duration_last: interest.exclude = pyccn.ExclusionFilter() interest.exclude.add_any() interest.exclude.add_name(pyccn.Name([self._duration_last])) self._handle.expressInterest(self._name_frames, self._duration_callback, interest)
def get_latest_version(name): n = pyccn.Name(name) i = pyccn.Interest(childSelector=1, answerOriginKind=pyccn.AOK_NONE) handle = pyccn.CCN() co = handle.get(n, i) if co is None: return None return co.name[:len(n) + 1]
def issue_interest(self, segment): name = self._name_segments.appendSegment(segment) #debug(self, "Issuing an interest for: %s" % name) self._tmp_retry_requests[str(name[-1])] = (self.interest_retries, time.time()) interest = pyccn.Interest(interestLifetime=self.interest_lifetime) self._handle.expressInterest(name, self, interest) return True
def fetch_start_time(self): name = self._name_segments.appendSegment(0) co = self._get_handle.get( name, pyccn.Interest(publisherPublicKeyDigest=self.publisher_id)) if not co: debug(self, "Unable to fetch %s" % name) exit(10) ts = co.signedInfo.py_timestamp debug(self, "Got timestamp: %s %f" % (time.ctime(ts), ts)) self._start_time = ts
def get_latest_version(name, publisher_id): n = pyccn.Name(name) i = pyccn.Interest(publisherPublicKeyDigest=publisher_id, childSelector=1, answerOriginKind=pyccn.AOK_NONE) handle = pyccn.CCN() co = handle.get(n, i) if co is None: return None, None return co.name[:len(n) + 1], co.signedInfo.publisherPublicKeyDigest
def issue_interest(self, segment): name = self._name_segments.appendSegment(segment) #debug(self, "Issuing an interest for: %s" % name) self.interest_lifetime = min( 2.0, self._stats['srtt'] + 3 * self._stats['rttvar']) self._tmp_retry_requests[str(name[-1])] = (self.interest_retries, time.time(), self.interest_lifetime) interest = pyccn.Interest(publisherPublicKeyDigest=self.publisher_id, interestLifetime=self.interest_lifetime) self._handle.expressInterest(name, self, interest) return True
def build_interest(self, latest): if self.start_with_latest: latest = True self.start_with_latest = False excl = pyccn.ExclusionFilter() excl.add_any() excl.add_name(pyccn.Name([self.latest_version])) # expected result should be between those two names excl.add_name(pyccn.Name([self.last_version_marker])) excl.add_any() interest = pyccn.Interest(name = self.base_name, exclude = excl, \ minSuffixComponents = 3, maxSuffixComponents = 3) interest.childSelector = 1 if latest else 0 return interest
def fetch_stream_info(self): name = self._uri.append('stream_info') debug(self, "Fetching stream_info from %s ..." % name) co = self._get_handle.get( name, pyccn.Interest(publisherPublicKeyDigest=self.publisher_id)) if not co: debug(self, "Unable to fetch %s" % name) exit(10) ts = co.signedInfo.py_timestamp debug(self, "Got timestamp: %s %f" % (time.ctime(ts), ts)) self._start_time = ts self._caps = gst.caps_from_string(co.content) debug(self, "Stream caps: %s" % self._caps) self.post_fetch_stream_info(self._caps) if self._start_time is None: self.fetch_start_time()
def fetch_last_frame(self): assert (self.frame_rate) interest = pyccn.Interest(childSelector=1) if self._duration_last: interest.exclude = pyccn.ExclusionFilter() interest.exclude.add_any() interest.exclude.add_name(pyccn.Name([self._duration_last])) co = self._get_handle.get(self._name_frames, interest) if co: print ">%s<" % co.name self._duration_last = co.name[-1] print ">%s<" % self._duration_last if self._duration_last: self.last_frame = pytimecode.PyTimeCode( self.frame_rate, start_timecode=self._duration_last) else: self.last_frame = "00:00:00:00"
def fetch_seek_query(self, tc): debug("Fetching segment number for %s" % tc) interest = pyccn.Interest(childSelector=1) interest.exclude = pyccn.ExclusionFilter() exc_tc = tc + 1 interest.exclude.add_name(pyccn.Name([exc_tc.make_timecode()])) interest.exclude.add_any() #debug("Sending interest to %s" % self._name_frames) #debug("Interest: %s" % interest) co = self._get_handle.get(self._name_frames, interest) if not co: raise Exception("Some bullshit exception") debug("Got segment: %s" % co.content) tc = pytimecode.PyTimeCode(exc_tc.framerate, start_timecode=co.name[-1]) segment = int(co.content) return tc, segment
def check_duration_initial(self): duration = None interest = pyccn.Interest(childSelector=1, answerOriginKind=pyccn.AOK_DEFAULT) exclude = interest.exclude = pyccn.ExclusionFilter() while True: res = self.__check_duration(interest) if res is None: break duration, t_packet, t_diff, rtt, name = res print "Excluding %r" % name exclude.reset() exclude.add_any() exclude.add_name(name) return duration
def __init__(self, handle, prefix, repo_loc=None): self._sequence = 0 self.handle = handle if not repo_loc: if not os.environ.has_key('CCNR_DIRECTORY'): raise Exception( "CCNR_DIRECTORY not defined and no repo location specified" ) dir = os.environ['CCNR_DIRECTORY'] dir = os.path.expanduser(dir) repo_loc = os.path.expandvars(dir) self.import_loc = os.path.join(repo_loc, "import") self.prefix = "%s_%d_%d_" % (prefix, os.getpid(), random.randrange(2**64)) self.name = "/%C1.R.af~" self.interest_tpl = pyccn.Interest(scope=1)
def getMetaInfo(self, name, key_digest, spaces): class KeyInfoClosure(pyccn.Closure): def __init__(self): self.co = None self.finished = False def upcall(self, kind, upcallInfo): if kind == pyccn.UPCALL_CONTENT_UNVERIFIED or kind == pyccn.UPCALL_CONTENT: self.co = upcallInfo.ContentObject self.finished = True return pyccn.RESULT_OK closure = KeyInfoClosure() info_name = pyccn.Name(name[:-3]).append("info").append( name[-3]).append(name[-2]).append(name[-1]) self.ccn.expressInterest( info_name, closure, pyccn.Interest(interestLifetime=self.args.timeout, scope=self.args.scope)) while not closure.finished: self.ccn.run(1) if closure.co == None: if self.args.verbose: print "%s%s [FAIL META] No META info for the key%s" % ( spaces, bcolors.FAIL, bcolors.ENDC) return None if closure.co.signedInfo.publisherPublicKeyDigest != key_digest: if self.args.verbose: print "%s%s [FAIL META] PublisherPublicKeyDigest is invalid%s" % ( spaces, bcolors.FAIL, bcolors.ENDC) return None return closure.co
def enumerateKeysFromNamespace(self, name): keys = [] if self.args.verbose: # print ">>> %s" % name import sys sys.stdout.write('.') sys.stdout.flush() base_len = len(name) excludeList = [] while True: interestName = pyccn.Name(name) exclude1 = pyccn.ExclusionFilter() exclude1.add_names([pyccn.Name().append(n) for n in excludeList]) interest_tmpl = pyccn.Interest(exclude=exclude1, interestLifetime=self.args.timeout, minSuffixComponents=1, maxSuffixComponents=100, scope=self.args.scope) class Slurp(pyccn.Closure): def __init__(self): self.finished = False self.done = False def upcall(self, kind, upcallInfo): if kind == pyccn.UPCALL_CONTENT or kind == pyccn.UPCALL_CONTENT_UNVERIFIED: co = upcallInfo.ContentObject self.name = co.name # print co.name if len(co.name) == base_len: self.done = True else: excludeList.append(co.name[base_len]) elif kind == pyccn.UPCALL_INTEREST_TIMED_OUT: self.done = True self.finished = True return pyccn.RESULT_OK slurp = Slurp() self.ccn.expressInterest(interestName, slurp, interest_tmpl) while not slurp.finished: # print slurp.finished self.ccn.run(1) if slurp.done: # print "Done with %s" % interestName break keyFound = False if slurp.name[base_len][0:5] == '\xc1.M.K': if slurp.name[base_len - 1] != "info": # if it is not a real key, but just meta keyname = slurp.name[0:base_len + 1] keys.append(pyccn.Name(keyname)) keyFound = True if not keyFound: if len(slurp.name) == base_len + 2 and slurp.name[ base_len + 1][0] == '\x00': # skip legacy stuff continue if len(slurp.name) == base_len + 4 and slurp.name[ base_len] == "info" and slurp.name[base_len + 3][0] == '\x00': # skip metadata continue # recursive step higherName = slurp.name[base_len] newName = pyccn.Name(interestName).append(higherName) keys += self.enumerateKeysFromNamespace(newName) return keys
import pyccn import pyccn._pyccn as _pyccn k = pyccn.CCN.getDefaultKey() kl = pyccn.KeyLocator(k) i = pyccn.Interest() i.name = pyccn.Name('/chat') i.minSuffixComponents = 3 i.maxSuffixComponents = 3 i.childSelector = 1 co = pyccn.ContentObject() co.name = pyccn.Name('/chat/%FD%04%E6%93.%18K/%00') co.content = "number 0" co.signedInfo.publisherPublicKeyDigest = k.publicKeyID co.signedInfo.finalBlockID = b'\x00' co.sign(k) print(str(co)) co2 = _pyccn.ContentObject_obj_from_ccn(co.ccn_data) print(str(co2)) print(str(i)) print(co.matchesInterest(i))
def __init__(self, handle, repo_loc): self.handle = handle self.import_loc = os.path.join(repo_loc, "import") self.name = "/%C1.R.af~" self.interest_tpl = pyccn.Interest(scope=1)
help='''Disable checking meta data (e.g., certificate expiration)''') args = aparser.parse_args() seq_num = 1 kv = verify.key_verifier(args) ccn = pyccn.CCN() while (seq_num > 0): raw_input("Press Enter to send an Interest") #interestName = pyccn.Name (args.c + "/" + repr(seq_num)) interestName = pyccn.Name(args.c) interest_tmpl = pyccn.Interest(exclude=None, interestLifetime=4.0, minSuffixComponents=1, maxSuffixComponents=100, scope=args.scope) class Slurp(pyccn.Closure): def __init__(self): self.finished = False self.done = False self.co = None self.seq_num = 1 def upcall(self, kind, upcallInfo): if kind == pyccn.UPCALL_CONTENT or kind == pyccn.UPCALL_CONTENT_UNVERIFIED: co = upcallInfo.ContentObject self.name = co.name print co.name
# from time import gmtime, strftime from threading import Thread import threading import json import struct import random import kds from pyccn import _pyccn import binascii from Crypto.Cipher import AES from Crypto import Random from pyccn import AOK_NONE import hashlib interest_tmpl = pyccn.Interest(scope=2, childSelector=1, answerOriginKind=AOK_NONE, interestLifetime=1000.0) interest_tmpl0 = pyccn.Interest(scope=2) handler0 = pyccn.CCN() flag_terminate0 = 0 BS = 16 pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS) unpad = lambda s: s[0:-ord(s[-1])] keyFile = "./keychain/keys/boelter4809.pem" key = binascii.unhexlify( '14fe923dd3ac6e8945ea02e892db6b3192f2081cbab26b44147d308af58f5609') time_s = None ksk = pyccn.Key()
print "Total number of retransmission: " + str(self.retrans) return pyccn.RESULT_OK nextname = self.name.appendSegment(self.segnum + 1) # print nextname handler.expressInterest(nextname, self, tmpl) elif kind == pyccn.UPCALL_INTEREST_TIMED_OUT: # print "Timeout" # print "Total segments fetched: " + str(self.segnum) # print "Total size fetched: " + str(self.totalsize) # return pyccn.RESULT_OK self.retrans = self.retrans + 1 return pyccn.RESULT_REEXPRESS return pyccn.RESULT_OK if len(sys.argv) != 2: print "Error: need to specify prefix of the file (without trailing '/')" exit(-1) file = sys.argv[1] closure = DataClosure(file) tmpl = pyccn.Interest(answerOriginKind=0, interestLifetime=1000.0) handler = pyccn.CCN() start = time.time() print start handler.expressInterest(closure.name, closure, tmpl) handler.run(20000)
def express_my_interest(self): templ = pyccn.Interest(exclude=self.exclusions) self.handle.expressInterest(self.root, self, templ)
import kds from pyccn import _pyccn import binascii from Crypto.Cipher import AES from Crypto import Random from device_info import device from pyccn import AOK_NONE import hashlib from user_list import usrlist BS = 16 pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS) unpad = lambda s: s[0:-ord(s[-1])] handler = pyccn.CCN() interest_tmpl = pyccn.Interest(scope=2, answerOriginKind=AOK_NONE) class RepoSocketPublisher(pyccn.Closure): def __init__(self, repo_port): self.repo_dest = ('127.0.0.1', int(repo_port)) self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock.connect(self.repo_dest) def put(self, content): self.sock.send(_pyccn.dump_charbuf(content.ccn_data)) class ConfigManager(): def __init__(self):
#import user_list from threading import Thread import struct import socket import binascii from Crypto.Cipher import PKCS1_v1_5 from Crypto.PublicKey import RSA import re handler = pyccn.CCN() interest_tmpl = pyccn.Interest(scope=2) flag_terminate = 0 class RepoSocketPublisher: def __init__(self, repo_port): self.repo_dest = ('127.0.0.1', int(repo_port)) self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock.connect(self.repo_dest) def put(self, content): self.sock.send(_pyccn.dump_charbuf(content.ccn_data))