def _handleTimeout(self, interest, timeSlot, onEncryptedKeys, onError): """ This is called from an expressInterest timeout to update the state of keyRequest. :param Interest interest: The timed-out interest. :param float timeSlot: The time slot as milliseconds since Jan 1, 1970 UTC. :param onEncryptedKeys: When there are no more interests to process, this calls onEncryptedKeys(keys) where keys is a list of encrypted content key Data packets. If onEncryptedKeys is None, this does not use it. :type onEncryptedKeys: function object :param onError: This calls onError(errorCode, message) for an error. :type onError: function object """ timeCount = round(timeSlot) keyRequest = self._keyRequests[timeCount] interestName = interest.getName() if keyRequest.repeatAttempts[interestName] < self._maxRepeatAttempts: # Increase the retrial count. keyRequest.repeatAttempts[interestName] += 1 self._sendKeyInterest(interest, timeSlot, onEncryptedKeys, onError) else: # Treat an eventual timeout as a network Nack. self._handleNetworkNack(interest, NetworkNack(), timeSlot, onEncryptedKeys, onError)
def onReceivedElement(self, element): """ This is called by the transport's ElementReader to process an entire received Data or Interest element. :param element: The bytes of the incoming element. :type element: An array type with int elements """ lpPacket = None if element[0] == Tlv.LpPacket_LpPacket: # Decode the LpPacket and replace element with the fragment. lpPacket = LpPacket() # Set copy False so that the fragment is a slice which will be # copied below. The header fields are all integers and don't need to # be copied. TlvWireFormat.get().decodeLpPacket(lpPacket, element, False) element = lpPacket.getFragmentWireEncoding().buf() # First, decode as Interest or Data. interest = None data = None decoder = TlvDecoder(element) if decoder.peekType(Tlv.Interest, len(element)): interest = Interest() interest.wireDecode(element, TlvWireFormat.get()) if lpPacket != None: interest.setLpPacket(lpPacket) elif decoder.peekType(Tlv.Data, len(element)): data = Data() data.wireDecode(element, TlvWireFormat.get()) if lpPacket != None: data.setLpPacket(lpPacket) if lpPacket != None: # We have decoded the fragment, so remove the wire encoding to save # memory. lpPacket.setFragmentWireEncoding(Blob()) networkNack = NetworkNack.getFirstHeader(lpPacket) if networkNack != None: if interest == None: # We got a Nack but not for an Interest, so drop the packet. return pendingInterests = [] self._pendingInterestTable.extractEntriesForNackInterest( interest, pendingInterests) for pendingInterest in pendingInterests: try: pendingInterest.getOnNetworkNack()( pendingInterest.getInterest(), networkNack) except: logging.exception("Error in onNetworkNack") # We have processed the network Nack packet. return # Now process as Interest or Data. if interest != None: # Call all interest filter callbacks which match. matchedFilters = [] self._interestFilterTable.getMatchedFilters( interest, matchedFilters) for i in range(len(matchedFilters)): entry = matchedFilters[i] includeFilter = True onInterestCall = entry.getOnInterest() # If onInterest is not a function nor a method assumes it is a # calleable object if (not inspect.isfunction(onInterestCall) and not inspect.ismethod(onInterestCall)): onInterestCall = onInterestCall.__call__ # Use getcallargs to test if onInterest accepts 5 args. try: inspect.getcallargs(onInterestCall, None, None, None, None, None) except TypeError: # Assume onInterest is old-style with 4 arguments. includeFilter = False if includeFilter: try: entry.getOnInterest()(entry.getFilter().getPrefix(), interest, entry.getFace(), entry.getInterestFilterId(), entry.getFilter()) except: logging.exception("Error in onInterest") else: # Old-style onInterest without the filter argument. We # still pass a Face instead of Transport since Face also # has a send method. try: entry.getOnInterest()(entry.getFilter().getPrefix(), interest, entry.getFace(), entry.getInterestFilterId()) except: logging.exception("Error in onInterest") elif data != None: pendingInterests = [] self._pendingInterestTable.extractEntriesForExpressedInterest( data, pendingInterests) for pendingInterest in pendingInterests: try: pendingInterest.getOnData()(pendingInterest.getInterest(), data) except: logging.exception("Error in onData")
def onReceivedElement(self, element): """ This is called by the transport's ElementReader to process an entire received Data or Interest element. :param element: The bytes of the incoming element. :type element: An array type with int elements """ lpPacket = None if element[0] == Tlv.LpPacket_LpPacket: # Decode the LpPacket and replace element with the fragment. lpPacket = LpPacket() # Set copy False so that the fragment is a slice which will be # copied below. The header fields are all integers and don't need to # be copied. TlvWireFormat.get().decodeLpPacket(lpPacket, element, False) element = lpPacket.getFragmentWireEncoding().buf() # First, decode as Interest or Data. interest = None data = None decoder = TlvDecoder(element) if decoder.peekType(Tlv.Interest, len(element)): interest = Interest() interest.wireDecode(element, TlvWireFormat.get()) if lpPacket != None: interest.setLpPacket(lpPacket) elif decoder.peekType(Tlv.Data, len(element)): data = Data() data.wireDecode(element, TlvWireFormat.get()) if lpPacket != None: data.setLpPacket(lpPacket) if lpPacket != None: # We have decoded the fragment, so remove the wire encoding to save # memory. lpPacket.setFragmentWireEncoding(Blob()) networkNack = NetworkNack.getFirstHeader(lpPacket) if networkNack != None: if interest == None: # We got a Nack but not for an Interest, so drop the packet. return pendingInterests = [] self._pendingInterestTable.extractEntriesForNackInterest( interest, pendingInterests) for pendingInterest in pendingInterests: try: pendingInterest.getOnNetworkNack()( pendingInterest.getInterest(), networkNack) except: logging.exception("Error in onNetworkNack") # We have processed the network Nack packet. return # Now process as Interest or Data. if interest != None: # Call all interest filter callbacks which match. matchedFilters = [] self._interestFilterTable.getMatchedFilters(interest, matchedFilters) for i in range(len(matchedFilters)): entry = matchedFilters[i] includeFilter = True onInterestCall = entry.getOnInterest() # If onInterest is not a function nor a method assumes it is a # calleable object if (not inspect.isfunction(onInterestCall) and not inspect.ismethod(onInterestCall)): onInterestCall = onInterestCall.__call__ # Use getcallargs to test if onInterest accepts 5 args. try: inspect.getcallargs(onInterestCall, None, None, None, None, None) except TypeError: # Assume onInterest is old-style with 4 arguments. includeFilter = False if includeFilter: try: entry.getOnInterest()( entry.getFilter().getPrefix(), interest, entry.getFace(), entry.getInterestFilterId(), entry.getFilter()) except: logging.exception("Error in onInterest") else: # Old-style onInterest without the filter argument. We # still pass a Face instead of Transport since Face also # has a send method. try: entry.getOnInterest()( entry.getFilter().getPrefix(), interest, entry.getFace(), entry.getInterestFilterId()) except: logging.exception("Error in onInterest") elif data != None: pendingInterests = [] self._pendingInterestTable.extractEntriesForExpressedInterest( data, pendingInterests) for pendingInterest in pendingInterests: try: pendingInterest.getOnData()(pendingInterest.getInterest(), data) except: logging.exception("Error in onData")
def onReceivedElement(self, element): """ This is called by the transport's ElementReader to process an entire received Data or Interest element. :param element: The bytes of the incoming element. :type element: An array type with int elements """ lpPacket = None if element[0] == Tlv.LpPacket_LpPacket: # Decode the LpPacket and replace element with the fragment. lpPacket = LpPacket() # Set copy False so that the fragment is a slice which will be # copied below. The header fields are all integers and don't need to # be copied. TlvWireFormat.get().decodeLpPacket(lpPacket, element, False) element = lpPacket.getFragmentWireEncoding().buf() # First, decode as Interest or Data. interest = None data = None decoder = TlvDecoder(element) if decoder.peekType(Tlv.Interest, len(element)): interest = Interest() interest.wireDecode(element, TlvWireFormat.get()) if lpPacket != None: interest.setLpPacket(lpPacket) elif decoder.peekType(Tlv.Data, len(element)): data = Data() data.wireDecode(element, TlvWireFormat.get()) if lpPacket != None: data.setLpPacket(lpPacket) if lpPacket != None: # We have decoded the fragment, so remove the wire encoding to save # memory. lpPacket.setFragmentWireEncoding(Blob()) networkNack = NetworkNack.getFirstHeader(lpPacket) if networkNack != None: if interest == None: # We got a Nack but not for an Interest, so drop the packet. return pendingInterests = [] self._pendingInterestTable.extractEntriesForNackInterest( interest, pendingInterests) for pendingInterest in pendingInterests: try: pendingInterest.getOnNetworkNack()( pendingInterest.getInterest(), networkNack) except: logging.exception("Error in onNetworkNack") # We have processed the network Nack packet. return # Now process as Interest or Data. if interest != None: self._dispatchInterest(interest) elif data != None: self._satisfyPendingInterests(data)
def onTimeout(interest): if nRetrials > 0: self._sendInterest(interest, nRetrials - 1, link, onVerified, onError) else: onNetworkNack(interest, NetworkNack())