private static void decodeControlParameters( ControlParameters controlParameters, TlvDecoder decoder, bool copy) { controlParameters.clear(); int endOffset = decoder .readNestedTlvsStart(net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_ControlParameters); // decode name if (decoder.peekType(net.named_data.jndn.encoding.tlv.Tlv.Name, endOffset)) { Name name = new Name(); decodeName(name, new int[1], new int[1], decoder, copy); controlParameters.setName(name); } // decode face ID controlParameters.setFaceId((int) decoder .readOptionalNonNegativeIntegerTlv( net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_FaceId, endOffset)); // decode URI if (decoder.peekType(net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_Uri, endOffset)) { // Set copy false since we just immediately get the string. Blob uri = new Blob(decoder.readOptionalBlobTlv( net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_Uri, endOffset), false); controlParameters.setUri("" + uri); } // decode integers controlParameters.setLocalControlFeature((int) decoder .readOptionalNonNegativeIntegerTlv( net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_LocalControlFeature, endOffset)); controlParameters.setOrigin((int) decoder .readOptionalNonNegativeIntegerTlv( net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_Origin, endOffset)); controlParameters.setCost((int) decoder .readOptionalNonNegativeIntegerTlv(net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_Cost, endOffset)); // set forwarding flags if (decoder.peekType(net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_Flags, endOffset)) { ForwardingFlags flags = new ForwardingFlags(); flags.setNfdForwardingFlags((int) decoder .readNonNegativeIntegerTlv(net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_Flags)); controlParameters.setForwardingFlags(flags); } // decode strategy if (decoder.peekType(net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_Strategy, endOffset)) { int strategyEndOffset = decoder .readNestedTlvsStart(net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_Strategy); decodeName(controlParameters.getStrategy(), new int[1], new int[1], decoder, copy); decoder.finishNestedTlvs(strategyEndOffset); } // decode expiration period controlParameters.setExpirationPeriod(decoder .readOptionalNonNegativeIntegerTlv( net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_ExpirationPeriod, endOffset)); decoder.finishNestedTlvs(endOffset); }
/// <summary> /// Do the work of registerPrefix to register with NFD. /// </summary> /// /// <param name="registeredPrefixId">registeredPrefixTable_ (assuming it has already been done).</param> /// <param name="prefix"></param> /// <param name="onInterest"></param> /// <param name="onRegisterFailed"></param> /// <param name="onRegisterSuccess"></param> /// <param name="flags"></param> /// <param name="commandKeyChain"></param> /// <param name="commandCertificateName"></param> /// <param name="wireFormat_0"></param> /// <param name="face_1"></param> /// <exception cref="System.Security.SecurityException">If cannot find the private key for thecertificateName.</exception> private void nfdRegisterPrefix(long registeredPrefixId, Name prefix, OnInterestCallback onInterest, OnRegisterFailed onRegisterFailed, OnRegisterSuccess onRegisterSuccess, ForwardingFlags flags, KeyChain commandKeyChain, Name commandCertificateName, WireFormat wireFormat_0, Face face_1) { if (commandKeyChain == null) { throw new Exception( "registerPrefix: The command KeyChain has not been set. You must call setCommandSigningInfo."); } if (commandCertificateName.size() == 0) { throw new Exception( "registerPrefix: The command certificate name has not been set. You must call setCommandSigningInfo."); } ControlParameters controlParameters = new ControlParameters(); controlParameters.setName(prefix); controlParameters.setForwardingFlags(flags); Interest commandInterest = new Interest(); // Determine whether to use remote prefix registration. bool faceIsLocal; try { faceIsLocal = isLocal(); } catch (IOException ex) { logger_.log( ILOG.J2CsMapping.Util.Logging.Level.INFO, "Register prefix failed: Error attempting to determine if the face is local: {0}", ex); try { onRegisterFailed.onRegisterFailed(prefix); } catch (Exception exception) { logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onRegisterFailed", exception); } return; } if (faceIsLocal) { commandInterest.setName(new Name("/localhost/nfd/rib/register")); // The interest is answered by the local host, so set a short timeout. commandInterest.setInterestLifetimeMilliseconds(2000.0d); } else { commandInterest.setName(new Name("/localhop/nfd/rib/register")); // The host is remote, so set a longer timeout. commandInterest.setInterestLifetimeMilliseconds(4000.0d); } // NFD only accepts TlvWireFormat packets. commandInterest.getName().append( controlParameters.wireEncode(net.named_data.jndn.encoding.TlvWireFormat.get())); makeCommandInterest(commandInterest, commandKeyChain, commandCertificateName, net.named_data.jndn.encoding.TlvWireFormat.get()); // Send the registration interest. Node.RegisterResponse response = new Node.RegisterResponse( new RegisterResponse.Info(prefix, onRegisterFailed, onRegisterSuccess, registeredPrefixId, onInterest, face_1), this); try { expressInterest(getNextEntryId(), commandInterest, response, response, null, wireFormat_0, face_1); } catch (IOException ex_2) { // Can't send the interest. Call onRegisterFailed. logger_.log( ILOG.J2CsMapping.Util.Logging.Level.INFO, "Register prefix failed: Error sending the register prefix interest to the forwarder: {0}", ex_2); try { onRegisterFailed.onRegisterFailed(prefix); } catch (Exception exception_3) { logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onRegisterFailed", exception_3); } } }
/// <summary> /// Do the work of registerPrefix to register with NFD. /// </summary> /// /// <param name="registeredPrefixId">registeredPrefixTable_ (assuming it has already been done).</param> /// <param name="prefix"></param> /// <param name="onInterest"></param> /// <param name="onRegisterFailed"></param> /// <param name="onRegisterSuccess"></param> /// <param name="flags"></param> /// <param name="commandKeyChain"></param> /// <param name="commandCertificateName"></param> /// <param name="wireFormat_0"></param> /// <param name="face_1"></param> /// <exception cref="System.Security.SecurityException">If cannot find the private key for thecertificateName.</exception> private void nfdRegisterPrefix(long registeredPrefixId, Name prefix, OnInterestCallback onInterest, OnRegisterFailed onRegisterFailed, OnRegisterSuccess onRegisterSuccess, ForwardingFlags flags, KeyChain commandKeyChain, Name commandCertificateName, WireFormat wireFormat_0, Face face_1) { if (commandKeyChain == null) throw new Exception( "registerPrefix: The command KeyChain has not been set. You must call setCommandSigningInfo."); if (commandCertificateName.size() == 0) throw new Exception( "registerPrefix: The command certificate name has not been set. You must call setCommandSigningInfo."); ControlParameters controlParameters = new ControlParameters(); controlParameters.setName(prefix); controlParameters.setForwardingFlags(flags); Interest commandInterest = new Interest(); // Determine whether to use remote prefix registration. bool faceIsLocal; try { faceIsLocal = isLocal(); } catch (IOException ex) { logger_.log( ILOG.J2CsMapping.Util.Logging.Level.INFO, "Register prefix failed: Error attempting to determine if the face is local: {0}", ex); try { onRegisterFailed.onRegisterFailed(prefix); } catch (Exception exception) { logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onRegisterFailed", exception); } return; } if (faceIsLocal) { commandInterest.setName(new Name("/localhost/nfd/rib/register")); // The interest is answered by the local host, so set a short timeout. commandInterest.setInterestLifetimeMilliseconds(2000.0d); } else { commandInterest.setName(new Name("/localhop/nfd/rib/register")); // The host is remote, so set a longer timeout. commandInterest.setInterestLifetimeMilliseconds(4000.0d); } // NFD only accepts TlvWireFormat packets. commandInterest.getName().append( controlParameters.wireEncode(net.named_data.jndn.encoding.TlvWireFormat.get())); makeCommandInterest(commandInterest, commandKeyChain, commandCertificateName, net.named_data.jndn.encoding.TlvWireFormat.get()); // Send the registration interest. Node.RegisterResponse response = new Node.RegisterResponse ( new RegisterResponse.Info(prefix, onRegisterFailed, onRegisterSuccess, registeredPrefixId, onInterest, face_1), this); try { expressInterest(getNextEntryId(), commandInterest, response, response, null, wireFormat_0, face_1); } catch (IOException ex_2) { // Can't send the interest. Call onRegisterFailed. logger_.log( ILOG.J2CsMapping.Util.Logging.Level.INFO, "Register prefix failed: Error sending the register prefix interest to the forwarder: {0}", ex_2); try { onRegisterFailed.onRegisterFailed(prefix); } catch (Exception exception_3) { logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onRegisterFailed", exception_3); } } }