Exemple #1
0
    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)
Exemple #2
0
    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
Exemple #3
0
    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
Exemple #4
0
    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)
Exemple #5
0
    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
Exemple #6
0
    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
Exemple #7
0
    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"
Exemple #8
0
    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
Exemple #9
0
import pyccn
from pyccn import _pyccn

e = pyccn.ExclusionFilter()
e.add_any()
e.add_names([pyccn.Name('/one'), pyccn.Name('/two'), pyccn.Name('/three'), pyccn.Name('/four')])
e.add_any()
e.add_name(pyccn.Name('/forty/two'))

str(e)
d = _pyccn.ExclusionFilter_obj_from_ccn(e.ccn_data)
str(d)

# I believe separation of /forty/two into /forty and /two is a correct behavior
# since it doesn't make sense to have more than one level in exclusions
result = ['<any>', '/one', '/two', '/four', '/three', '<any>', '/forty', '/two']

for a,b in zip(d.components, result):
	if str(a) == b:
		continue
	else:
		raise AssertionError("%s != %s" % (str(a), b))
Exemple #10
0
 def __init__(self, root, handle=None):
     self.root = pyccn.Name(root)
     self.exclusions = pyccn.ExclusionFilter()
     self.handle = handle or pyccn.CCN()
Exemple #11
0
    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