def build_interest(self, latest): if self.start_with_latest: latest=True self.start_with_latest = False excl = Interest.ExclusionFilter() excl.add_any() excl.add_name(Name.Name([self.latest_version])) # expected result should be between those two names excl.add_name(Name.Name([self.last_version_marker])) excl.add_any() interest = Interest.Interest(name=self.base_name, exclude=excl, \ minSuffixComponents=3, maxSuffixComponents=3) interest.childSelector = 1 if latest else 0 return interest
def fetch_media(self): '''Fetch remote media and control data. Check every 10 ms. If the remote user is not Stopped, probe for its media and control; Otherwise, if it's Streaming, send the media Interest if the number of outstanding Interests is less than pipe_size ''' if self.factory.has_local_client(): for remote_user in self.factory.roster.values(): if remote_user.streaming_state == RemoteUser.Stopped: name = remote_user.get_media_prefix() template = Interest(childSelector = 1) self.ccnx_int_socket.send_interest(name, self.probe_closure, template) self.__class__.__logger.debug('RTP-INT:%s', name) remote_user.streaming_state = RemoteUser.Probing # also fetch ctrl messages ctrl_name = remote_user.get_ctrl_prefix() + '/' + self.factory.client.local_user.uid self.ccnx_int_socket.send_interest(ctrl_name, self.ctrl_probe_closure, template) self.__class__.__logger.debug('CTRL-INT:%s', ctrl_name) elif remote_user.streaming_state == RemoteUser.Streaming: while remote_user.requested_seq - remote_user.fetched_seq < self.pipe_size: name = remote_user.get_media_prefix() + '/' + str(remote_user.requested_seq + 1) remote_user.requested_seq += 1 self.ccnx_int_socket.send_interest(name, self.stream_closure) self.__class__.__logger.debug('RTP-INT:%s', name) else: pass
def start(self): self.handle.setInterestFilter(self.name, self) interest = Interest.Interest(name=Name.Name(self.name)) interest.name += '\xC1.R.sw' interest.name.appendNonce() print("Expressing interest: ccnx:%s" % interest.name) self.handle.expressInterest(interest.name, self, interest) self.handle.run(-1)
from pyccn import Interest, Name, Key, CCN, _pyccn import datetime k = CCN.getDefaultKey() i = Interest() i.name = Name('/hello/world') i.minSuffixComponents = 2 i.maxSuffixComponents = 4 i.publisherPublicKeyDigest = k.publicKeyID i.exclude = None i.childSelector = 1 i.answerOriginKind = 4 i.scope = 2 i.interestLifetime = 30.0 i.nonce = b'abababa' print(i) print(i.ccn_data) i2 = _pyccn.Interest_obj_from_ccn(i.ccn_data) print(i2) assert (i.name == i2.name) assert (i.minSuffixComponents == i2.minSuffixComponents) assert (i.maxSuffixComponents == i2.maxSuffixComponents) assert (i.publisherPublicKeyDigest == i2.publisherPublicKeyDigest) assert (i.exclude == i2.exclude) assert (i.childSelector == i2.childSelector) assert (i.scope == i2.scope) assert (i.interestLifetime == i2.interestLifetime)
import pyccn from pyccn import CCN, Name, Interest, Key, ContentObject, Closure, KeyLocator, ExclusionFilter from Tyzx import CompositeObject, BaseObject prefix = "ccnx:/ndn/ucla.edu/apps/tv1/occupants" DISCOVER_INTEREST_PERIOD = 0.250 # How often UPDATE_INTEREST_PERIOD = 0.250 CCN_WAIT_TIME_MS = 1 tyzxObjects = {} oldObjects = set() # still may be in the content store ccn = CCN() interestDiscover = Interest() interestDiscover.name = Name(prefix) interestDiscover.minSuffixComponents = 2 # occupant id + the implicit digest at a minimum interestUpdate = Interest() interestUpdate.minSuffixComponents = 2 # time (version) + the implicit digest interestUpdate.childSelector = 1 # rightmost child #interestUpdate.interestLifetime = ???? lastdiscovertime = 0 def versionFromTime(t): bintime = struct.pack("!Q", int(t * 4096 + 0.5)) version = bintime.lstrip(b'\x00') return b'\xfd' + version
event_loop.stop() return pyccn.RESULT_OK senderclosure = SenderClosure() receiverclosure = ReceiverClosure() sender_handle = CCN() receiver_handle = CCN() #Looks like the CCNx API doesn't deliver messages #that we sent to ourselves, so we just push it sender_handle.setInterestFilter(n, senderclosure) #senderclosure.upcall(1, None) i = Interest() receiver_handle.expressInterest(n, receiverclosure, i) upcall_called = False print("Running loops") #So sender closure is called #sender_handle.run(500) #So receiver closure is called #receiver_handle.run(500) # New way of doing this event_loop = pyccn.EventLoop(sender_handle, receiver_handle) event_loop.run()
from pyccn import Interest, Name, Key, CCN, _pyccn import datetime k = CCN.getDefaultKey() i = Interest() i.name = Name('/hello/world') i.minSuffixComponents = 2 i.maxSuffixComponents = 4 i.publisherPublicKeyDigest = k.publicKeyID i.exclude = None i.childSelector = 1 i.answerOriginKind = 4 i.scope = 2 i.interestLifetime = 30.0 i.nonce = b'abababa' print(i) print(i.ccn_data) i2 = _pyccn.Interest_obj_from_ccn(i.ccn_data) print(i2) assert(i.name == i2.name) assert(i.minSuffixComponents == i2.minSuffixComponents) assert(i.maxSuffixComponents == i2.maxSuffixComponents) assert(i.publisherPublicKeyDigest == i2.publisherPublicKeyDigest) assert(i.exclude == i2.exclude) assert(i.childSelector == i2.childSelector) assert(i.scope == i2.scope) assert(i.interestLifetime == i2.interestLifetime)
import pyccn from pyccn import CCN, Name, Interest, Key, ContentObject, Closure, KeyLocator, ExclusionFilter from Tyzx import CompositeObject, BaseObject prefix = "ccnx:/ndn/ucla.edu/apps/tv1/occupants" DISCOVER_INTEREST_PERIOD = 0.250 # How often UPDATE_INTEREST_PERIOD = 0.250 CCN_WAIT_TIME_MS = 1 tyzxObjects = {} oldObjects = set() # still may be in the content store ccn = CCN() interestDiscover = Interest() interestDiscover.name = Name(prefix) interestDiscover.minSuffixComponents = 2 # occupant id + the implicit digest at a minimum interestUpdate = Interest() interestUpdate.minSuffixComponents = 2 # time (version) + the implicit digest interestUpdate.childSelector = 1 # rightmost child #interestUpdate.interestLifetime = ???? lastdiscovertime = 0 def versionFromTime(t): bintime = struct.pack("!Q", int(t * 4096 + 0.5)) version = bintime.lstrip(b'\x00') return b'\xfd' + version last_version_marker = '\xfe\x00\x00\x00\x00\x00\x00'