Exemplo n.º 1
0
    def setForwardingFlags(self, flags):
        """
        Set the RegistrationOptions object to a copy of flags.
        You can use getForwardingFlags() and change the existing
        RegistrationOptions object.

        :param RegistrationOptions flags: The new RegistrationOptions object
          containing the flags, or None if not specified.
        """
        self._flags = (RegistrationOptions(flags)
                       if isinstance(flags, RegistrationOptions)
                       else RegistrationOptions())
Exemplo n.º 2
0
 def clear(self):
     self._name = None
     self._faceId = None
     self._uri = ""
     self._localControlFeature = None
     self._origin = None
     self._cost = None
     self._flags = RegistrationOptions()
     self._strategy = Name()
     self._expirationPeriod = None
Exemplo n.º 3
0
 def __init__(self, value = None):
     if isinstance(value, ControlParameters):
         # Make a deep copy.
         self._name = None if value._name == None else Name(value._name)
         self._faceId = value._faceId
         self._uri = value._uri
         self._localControlFeature = value._localControlFeature
         self._origin = value._origin
         self._cost = value._cost
         self._flags = RegistrationOptions(value._flags)
         self._strategy = Name(value._strategy)
         self._expirationPeriod = value._expirationPeriod
     else:
         self._name = None
         self._faceId = None
         self._uri = ""
         self._localControlFeature = None
         self._origin = None
         self._cost = None
         self._flags = RegistrationOptions()
         self._strategy = Name()
         self._expirationPeriod = None
Exemplo n.º 4
0
    def _registerPrefixHelper(
      self, registeredPrefixId, prefixCopy, onInterest, onRegisterFailed,
      arg5 = None, arg6 = None, arg7 = None):
        """
        This is a protected helper method to do the work of registerPrefix to
        resolve the different overloaded forms. The registeredPrefixId is from
        getNextEntryId(). This has no return value and can be used in a callback.
        """
        # arg5, arg6, arg7 may be:
        # OnRegisterSuccess,   RegistrationOptions, WireFormat
        # OnRegisterSuccess,   RegistrationOptions, None
        # OnRegisterSuccess,   WireFormat,          None
        # OnRegisterSuccess,   None,                None
        # RegistrationOptions, WireFormat,          None
        # RegistrationOptions, None,                None
        # WireFormat,          None,                None
        # None,                None,                None
        if isinstance(arg5, collections.Callable):
            onRegisterSuccess = arg5
        else:
            onRegisterSuccess = None

        if isinstance(arg5, RegistrationOptions):
            registrationOptions = arg5
        elif isinstance(arg6, RegistrationOptions):
            registrationOptions = arg6
        else:
            registrationOptions = RegistrationOptions()

        if isinstance(arg5, WireFormat):
            wireFormat = arg5
        elif isinstance(arg6, WireFormat):
            wireFormat = arg6
        elif isinstance(arg7, WireFormat):
            wireFormat = arg7
        else:
            # Don't use a default argument since getDefaultWireFormat can change.
            wireFormat = WireFormat.getDefaultWireFormat()

        return self._node.registerPrefix(
          registeredPrefixId, prefixCopy, onInterest, onRegisterFailed,
          onRegisterSuccess, registrationOptions, wireFormat, self._commandKeyChain,
          self._commandCertificateName, self)
Exemplo n.º 5
0
    def registerPrefix(self,
                       prefix,
                       onRegisterFailed,
                       onRegisterSuccess=None,
                       onDataNotFound=None,
                       registrationOptions=None,
                       wireFormat=None):
        """
        Call registerPrefix on the Face given to the constructor so that this
        MemoryContentCache will answer interests whose name has the prefix.
        Alternatively, if the Face's registerPrefix has already been called,
        then you can call this object's setInterestFilter.

        :param Name prefix: The Name for the prefix to register. This copies the
          Name.
        :param onRegisterFailed: If this fails to register the prefix for any
          reason, this calls onRegisterFailed(prefix) where prefix is the prefix
          given to registerPrefix.
          NOTE: The library will log any exceptions raised by this callback, but
          for better error handling the callback should catch and properly
          handle any exceptions.
        :type onRegisterFailed: function object
        :param onRegisterSuccess: (optional) This calls
          onRegisterSuccess[0](prefix, registeredPrefixId) when this receives a
          success message from the forwarder. If onRegisterSuccess is omitted or
          [None], this does not use it. (As a special case, this optional
          parameter is supplied as a list of one function object, instead of
          just a function object, in order to detect when it is used instead of
          the following optional onDataNotFound function object.)
          NOTE: The library will log any exceptions raised by this callback, but
          for better error handling the callback should catch and properly
          handle any exceptions.
        :type onRegisterSuccess: list of one function object
        :param onDataNotFound: (optional) If a data packet for an interest is
          not found in the cache, this forwards the interest by calling
          onDataNotFound(prefix, interest, face, interestFilterId, filter). Your
          callback can find the Data packet for the interest and call
          face.putData(data). If your callback cannot find the Data packet, it can
          optionally call storePendingInterest(interest, face) to store the
          pending interest in this object to be satisfied by a later call to
          add(data). If you want to automatically store all pending interests,
          you can simply use getStorePendingInterest() for onDataNotFound. If
          onDataNotFound is omitted or None, this does not use it.
          NOTE: The library will log any exceptions raised by this callback, but
          for better error handling the callback should catch and properly
          handle any exceptions.
        :type onDataNotFound: function object
        :param RegistrationOptions registrationOptions: (optional) See Face.registerPrefix.
        :param wireFormat: (optional) See Face.registerPrefix.
        :type wireFormat: A subclass of WireFormat
        """
        arg3 = onRegisterSuccess
        arg4 = onDataNotFound
        arg5 = registrationOptions
        arg6 = wireFormat
        # arg3,                arg4,                arg5,                arg6 may be:
        # [OnRegisterSuccess], OnDataNotFound,      RegistrationOptions, WireFormat
        # [OnRegisterSuccess], OnDataNotFound,      RegistrationOptions, None
        # [OnRegisterSuccess], OnDataNotFound,      WireFormat,          None
        # [OnRegisterSuccess], OnDataNotFound,      None,                None
        # [OnRegisterSuccess], RegistrationOptions, WireFormat,          None
        # [OnRegisterSuccess], RegistrationOptions, None,                None
        # [OnRegisterSuccess], WireFormat,          None,                None
        # [OnRegisterSuccess], None,                None,                None
        # OnDataNotFound,      RegistrationOptions, WireFormat,          None
        # OnDataNotFound,      RegistrationOptions, None,                None
        # OnDataNotFound,      WireFormat,          None,                None
        # OnDataNotFound,      None,                None,                None
        # RegistrationOptions, WireFormat,          None,                None
        # RegistrationOptions, None,                None,                None
        # WireFormat,          None,                None,                None
        # None,                None,                None,                None
        if type(arg3) is list and len(arg3) == 1:
            onRegisterSuccess = arg3[0]
        else:
            onRegisterSuccess = None

        if isinstance(arg3, collections.Callable):
            onDataNotFound = arg3
        elif isinstance(arg4, collections.Callable):
            onDataNotFound = arg4
        else:
            onDataNotFound = None

        if isinstance(arg3, RegistrationOptions):
            registrationOptions = arg3
        elif isinstance(arg4, RegistrationOptions):
            registrationOptions = arg4
        elif isinstance(arg5, RegistrationOptions):
            registrationOptions = arg5
        else:
            registrationOptions = RegistrationOptions()

        if isinstance(arg3, WireFormat):
            wireFormat = arg3
        elif isinstance(arg4, WireFormat):
            wireFormat = arg4
        elif isinstance(arg5, WireFormat):
            wireFormat = arg5
        elif isinstance(arg6, WireFormat):
            wireFormat = arg6
        else:
            # Don't use a default argument since getDefaultWireFormat can change.
            wireFormat = WireFormat.getDefaultWireFormat()

        if onDataNotFound != None:
            self._onDataNotFoundForPrefix[prefix.toUri()] = onDataNotFound
        registeredPrefixId = self._face.registerPrefix(
            prefix, self._onInterest, onRegisterFailed, onRegisterSuccess,
            registrationOptions, wireFormat)
        self._registeredPrefixIdList.append(registeredPrefixId)
Exemplo n.º 6
0
            return (False, type(obj).__name__, "Exception raised", e)

    return (True, type(obj).__name__, vals)


## To Do: Add value checks

# ControlParameters
#
from pyndn.name import Name
from pyndn.control_parameters import ControlParameters
from pyndn.registration_options import RegistrationOptions
for p in [("name", Name("yes"), Name("another")), ("faceId", 32, None),
          ("localControlFeature", 1, None), ("origin", 2, 9),
          ("cost", 1, None),
          ("forwardingFlags", RegistrationOptions(), RegistrationOptions()),
          ("expirationPeriod", 1000.1, None)]:
    res = testPropertyRW(ControlParameters(), p[0], [p[1], p[2]])
    if not res[0]: print(res)

# Data
#
from pyndn.data import Data
from pyndn.name import Name
from pyndn.meta_info import MetaInfo
from pyndn.signature import Signature
from pyndn.util.blob import Blob
# We do not test the signature property because clone is not yet implemented for it.
#
for p in [("name", Name("yes"), Name("another")),
          ("metaInfo", MetaInfo(), MetaInfo()),
Exemplo n.º 7
0
#TODO: Test if DB not initialized, else do
#first_run()
timestamp = int(time.time())
#sys.exit(1)
testbed_json = json.load(open(request.urlretrieve("http://ndndemo.arl.wustl.edu/testbed-nodes.json")[0], "r"))
#Initialize keychain
keychain = KeyChain()
loop = asyncio.get_event_loop()
# loop.call_soon(destroy)
# loop.run_forever()
for hub_name in testbed_json.keys():
    hub = testbed_json[hub_name]
    valid_prefixes = Name(PREFIX + hub["shortname"])

for hub_name in testbed_json.keys():
    hub = testbed_json[hub_name]
    print("Adding faces to hub: {}".format(hub["name"]))
    face_base = hub["site"].strip("http").replace(":80/",":6363")
    for protocol in PROTOCOLS:
        face = ThreadsafeFace(loop, "{}{}".format(protocol, hub))
        face.setCommandSigningInfo(keychain, keychain.getDefaultCertificateName())
        prefix = Name(PREFIX + hub["shortname"])
        options = RegistrationOptions().setOrigin(65)
        face.registerPrefix(prefix, onInterest, onRegisterFailed, onRegisterSuccess=registration, registrationOptions=options)
        time.sleep(2)
        print("Begin ping")
        loop.call_soon(schedulePings, prefix)
        loop.run_forever()
#time.sleep(30)
conn.close()