using static Vanara.PInvoke.Crypt32; using static Vanara.PInvoke.Ws2_32; namespace Vanara.PInvoke; /// Items from the Drt.dll public static partial class Drt { private const string Lib_Drt = "drt.dll"; private const string Lib_DrtProv = "drtprov.dll"; private const string Lib_DrtTrans = "drttransport.dll"; /// public const uint DRT_PAYLOAD_REVOKED = (1 << 0); /// public const uint DRT_MIN_ROUTING_ADDRESSES = 1; /// public const uint DRT_MAX_ROUTING_ADDRESSES = 20; /// public const uint DRT_MAX_PAYLOAD_SIZE = 5120; /// public const uint DRT_MAX_INSTANCE_PREFIX_LEN = 128; /// public const uint DRT_LINK_LOCAL_ISATAP_SCOPEID = 0xffffffff; /// Increments the count of references for the Bootstrap Provider with a set of DRTs. /// Contains the pvContext value from DRT_BOOTSTRAP_PROVIDER. /// [PInvokeData("drt.h", MSDNShortId = "NS:drt.drt_bootstrap_provider_tag")] [UnmanagedFunctionPointer(CallingConvention.Winapi)] public delegate HRESULT DRT_BOOTSTRAP_PROVIDER_Attach([In] IntPtr pvContext); /// Decrements the count of references for the Bootstrap Provider with a set of DRTs. /// Contains the pvContext value from DRT_BOOTSTRAP_PROVIDER. [PInvokeData("drt.h", MSDNShortId = "NS:drt.drt_bootstrap_provider_tag")] [UnmanagedFunctionPointer(CallingConvention.Winapi)] public delegate void DRT_BOOTSTRAP_PROVIDER_Detach([In] IntPtr pvContext); /// Ends the resolution of an endpoint. /// Contains the pvContext value from DRT_BOOTSTRAP_PROVIDER. /// /// The BOOTSTRAP_RESOLVE_CONTEXT received from the Resolve function of the specified bootstrap provider. /// [PInvokeData("drt.h", MSDNShortId = "NS:drt.drt_bootstrap_provider_tag")] [UnmanagedFunctionPointer(CallingConvention.Winapi)] public delegate void DRT_BOOTSTRAP_PROVIDER_EndResolve([In] IntPtr pvContext, [In] DRT_BOOTSTRAP_RESOLVE_CONTEXT ResolveContext); /// Called by the DRT infrastructure to supply configuration information about upcoming name resolutions. /// Contains the pvContext value from DRT_BOOTSTRAP_PROVIDER. /// Specifies if the resolve operation is being utilized for network split detection and recovery. /// Specifies the maximum time a resolve should take before timing out. This value is represented in milliseconds. /// Specifies the maximum number of results to return during the resolve operation. /// Pointer to resolver specific data. /// /// If the bootstrap provider encounters an irrecoverable error, this parameter must be set to TRUE when the function /// complete in order for the DRT to transition to the faulted state. The HRESULT that is made available to the higher layer /// application for debugging will appear in the hr member of the DRT_EVENT_DATA structure associated with the event /// signaling the transition to the faulted state. This bootstrap provider function should not return S_OK if setting the /// fFatalError flag to TRUE. /// /// [PInvokeData("drt.h", MSDNShortId = "NS:drt.drt_bootstrap_provider_tag")] [UnmanagedFunctionPointer(CallingConvention.Winapi)] public delegate HRESULT DRT_BOOTSTRAP_PROVIDER_InitResolve([In] IntPtr pvContext, [MarshalAs(UnmanagedType.Bool)] bool fSplitDetect, uint timeout, uint cMaxResults, out DRT_BOOTSTRAP_RESOLVE_CONTEXT ResolveContext, [MarshalAs(UnmanagedType.Bool)] out bool fFatalError); /// /// Called by the DRT infrastructure to issue a resolution to determine the endpoints of nodes already active in the DRT cloud. /// /// Contains the pvContext value from DRT_BOOTSTRAP_PROVIDER. /// Pointer to the context data that is passed back to the callback defined by the next parameter. /// A BOOTSTRAP_RESOLVE_CALLBACK that is called back for each result and DRT_E_NO_MORE. /// Pointer to resolver specific data. /// /// If the bootstrap provider encounters an irrecoverable error, this parameter must be set to TRUE when the function /// complete in order for the DRT to transition to the faulted state. The HRESULT that is made available to the higher layer /// application for debugging will appear in the hr member of the DRT_EVENT_DATA structure associated with the event /// signaling the transition to the faulted state. This bootstrap provider function should not return S_OK if setting the /// fFatalError flag to TRUE. /// /// [PInvokeData("drt.h", MSDNShortId = "NS:drt.drt_bootstrap_provider_tag")] [UnmanagedFunctionPointer(CallingConvention.Winapi)] public delegate HRESULT DRT_BOOTSTRAP_PROVIDER_IssueResolve([In] IntPtr pvContext, [In] IntPtr pvCallbackContext, DRT_BOOTSTRAP_RESOLVE_CALLBACK callback, [In] DRT_BOOTSTRAP_RESOLVE_CONTEXT ResolveContext, [MarshalAs(UnmanagedType.Bool)] out bool fFatalError); /// /// Registers an endpoint with the bootstrapping mechanism. This process makes it possible for other nodes find the endpoint via the /// bootstrap resolver. /// /// Contains the pvContext value from DRT_BOOTSTRAP_PROVIDER. /// Pointer to containing the list of addresses to register with the bootstrapping mechanism. /// [PInvokeData("drt.h", MSDNShortId = "NS:drt.drt_bootstrap_provider_tag")] [UnmanagedFunctionPointer(CallingConvention.Winapi)] public delegate HRESULT DRT_BOOTSTRAP_PROVIDER_Register([In] IntPtr pvContext, [In] IntPtr pAddressList); /// /// This function deregisters an endpoint with the bootstrapping mechanism. As a result, other nodes will be unable to find the /// local node via the bootstrap resolver. /// /// Contains the pvContext value from DRT_BOOTSTRAP_PROVIDER. [PInvokeData("drt.h", MSDNShortId = "NS:drt.drt_bootstrap_provider_tag")] [UnmanagedFunctionPointer(CallingConvention.Winapi)] public delegate void DRT_BOOTSTRAP_PROVIDER_Unregister([In] IntPtr pvContext); /// Callback for some DRT functions. /// The error. /// Contains the pvContext value from DRT_BOOTSTRAP_PROVIDER. /// Pointer to containing the list of addresses to register with the bootstrapping mechanism. /// /// If the bootstrap provider encounters an irrecoverable error, this parameter must be set to TRUE when the function /// complete in order for the DRT to transition to the faulted state. The HRESULT that is made available to the higher layer /// application for debugging will appear in the hr member of the DRT_EVENT_DATA structure associated with the event /// signaling the transition to the faulted state. This bootstrap provider function should not return S_OK if setting the /// fFatalError flag to TRUE. /// [PInvokeData("drt.h", MSDNShortId = "NS:drt.drt_bootstrap_provider_tag")] [UnmanagedFunctionPointer(CallingConvention.Winapi)] public delegate void DRT_BOOTSTRAP_RESOLVE_CALLBACK(HRESULT hr, IntPtr pvContext, [In] IntPtr pAddresses, [MarshalAs(UnmanagedType.Bool)] BOOL fFatalError); /// Increments the count of references for the Security Provider with a set of DRTs. /// Pointer to the value held by the pvContext member of DRT_SECURITY_PROVIDER. /// public delegate HRESULT DRT_SECURITY_PROVIDER_Attach([In] IntPtr pvContext); /// /// Called when the DRT receives a message containing encrypted data. This function is only called when the DRT is operating in the /// DRT_SECURE_CONFIDENTIALPAYLOAD security mode defined by DRT_SECURITY_MODE. /// /// Pointer to the value held by the pvContext member of DRT_SECURITY_PROVIDER. /// /// Contains the encrypted session key that can be decrypted by the recipient of the message and used to decrypt the protected fields. /// /// Contains the context passed into DrtRegisterKey when the key was registered. /// Contains the size of pData buffer. /// Contains the decrypted data upon completion of the function. /// public delegate HRESULT DRT_SECURITY_PROVIDER_DecryptData([In] IntPtr pvContext, in DRT_DATA pKeyToken, [In] IntPtr pvKeyContext, [In] uint dwBuffers, [In, Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] DRT_DATA[] pData); /// Decrements the count of references for the Security Provider with a set of DRTs. /// Pointer to the value held by the pvContext member of DRT_SECURITY_PROVIDER. public delegate void DRT_SECURITY_PROVIDER_Detach([In] IntPtr pvContext); /// /// Called when the DRT sends a message containing data that must be encrypted. This function is only called when the DRT is /// operating in the DRT_SECURE_CONFIDENTIALPAYLOAD security mode defined by DRT_SECURITY_MODE. /// /// Pointer to the value held by the pvContext member of DRT_SECURITY_PROVIDER. /// Contains the credential of the peer that will receive the protected message. /// Contains the length of the pDataBuffers and pEncryptedBuffers. /// Contains the unencrypted buffer. /// Contains the encrypted content upon completion of the function. /// /// Contains the encrypted session key that can be decrypted by the recipient of the message and used to decrypted the protected fields. /// /// public delegate HRESULT DRT_SECURITY_PROVIDER_EncryptData([In] IntPtr pvContext, in DRT_DATA pRemoteCredential, [In] uint dwBuffers, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] DRT_DATA[] pDataBuffers, [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] DRT_DATA[] pEncryptedBuffers, out DRT_DATA pKeyToken); /// Called to release resources previously allocated for a security provider function. /// Pointer to the value held by the pvContext member of DRT_SECURITY_PROVIDER. /// Specifies what data to free. public delegate void DRT_SECURITY_PROVIDER_FreeData([In] IntPtr pvContext, [In, Optional] IntPtr pv); /// /// Called when the DRT must provide a credential used to authorize the local node. This function is only called when the DRT is /// operating in the DRT_SECURE_MEMBERSHIP and DRT_SECURE_CONFIDENTIALPAYLOAD security modes defined by DRT_SECURITY_MODE. /// /// Pointer to the value held by the pvContext member of DRT_SECURITY_PROVIDER. /// Contains the serialized credential upon completion of the function. /// public delegate HRESULT DRT_SECURITY_PROVIDER_GetSerializedCredential([In] IntPtr pvContext, out DRT_DATA pSelfCredential); /// Called to register a key with the Security Provider. /// Pointer to the value held by the pvContext member of DRT_SECURITY_PROVIDER. /// /// Pointer to the DRT_REGISTRATION structure created by an application and passed to the DrtRegisterKey function. /// /// Pointer to the context data created by an application and passed to the DrtRegisterKey function. /// public delegate HRESULT DRT_SECURITY_PROVIDER_RegisterKey([In] IntPtr pvContext, in DRT_REGISTRATION pRegistration, [In, Optional] IntPtr pvKeyContext); /// /// Called when an Authority message is about to be sent on the wire. It is responsible for securing the data before it is sent, and /// for packing the service addresses, revoked flag, nonce, and other application data into the Secured Address Payload. /// /// Pointer to the value held by the pvContext member of DRT_SECURITY_PROVIDER. /// Contains the context passed into DrtRegisterKey when the key was registered. /// Pointer to the byte array that represents the protocol major version. /// Pointer to the byte array that represents the protocol minor version. /// /// /// Any DRT specific flags, currently defined only to be the revoked or deleted flag that need to be packed, secured and sent to /// another instance for processing. /// /// Note Currently the only allowed value is: DRT_PAYLOAD_REVOKED /// /// Pointer to the key to which this payload is registered. /// Pointer to the payload specified by the application when calling DrtRegisterKey. /// Pointer to the service addresses that are placed in the Secured Address Payload. /// /// Pointer to the nonce that was sent in the original Inquire or Lookup message. This value is fixed at 16 bytes. /// /// /// Pointer to the payload to send on the wire which contains the service addresses, revoked flag, nonce, and other data required by /// the security provider. pSecuredAddressPayload.pb is allocated by the security provider. /// /// /// Pointer to the classifier to send in the Authority message. pClassifier.pb is allocated by the security provider. /// /// /// Pointer to the application data payload received in the Authority message. After validation, the original data (after /// decryption, removal of signature, and so on.) is output as pPayload. pSecuredPayload.pb is allocated by the security provider. /// /// /// Pointer to the cert chain to send in the Authority message. pCertChain.pb is allocated by the security provider. /// /// public unsafe delegate HRESULT DRT_SECURITY_PROVIDER_SecureAndPackPayload([In] IntPtr pvContext, [In, Optional] IntPtr pvKeyContext, byte bProtocolMajor, byte bProtocolMinor, uint dwFlags, in DRT_DATA pKey, [In, Optional] DRT_DATA* pPayload, [In, Optional] IntPtr pAddressList, in DRT_DATA pNonce, out DRT_DATA pSecuredAddressPayload, [Out, Optional] DRT_DATA* pClassifier, [Out, Optional] DRT_DATA* pSecuredPayload, [Out, Optional] DRT_DATA* pCertChain); /// /// Called when the DRT must sign a data blob for inclusion in a DRT protocol message. This function is only called when the DRT is /// operating in the DRT_SECURE_MEMBERSHIP and DRT_SECURE_CONFIDENTIALPAYLOAD security modes defined by DRT_SECURITY_MODE. /// /// Pointer to the value held by the pvContext member of DRT_SECURITY_PROVIDER. /// Contains the size of the pDataBuffers buffer. /// Contains the data to be signed. /// /// Upon completion of this function, contains an index that can be used to select from multiple credentials for use in calculating /// the signature. /// /// Upon completion of this function, contains the signature data. /// public delegate HRESULT DRT_SECURITY_PROVIDER_SignData([In] IntPtr pvContext, [In] uint dwBuffers, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] DRT_DATA[] pDataBuffers, out DRT_DATA pKeyIdentifier, out DRT_DATA pSignature); /// Called to deregister a key with the Security Provider. /// Pointer to the value held by the pvContext member of DRT_SECURITY_PROVIDER. /// Pointer to the key to which the payload is registered. /// Pointer to the context data created by the application and passed to DrtRegisterKey. /// public delegate HRESULT DRT_SECURITY_PROVIDER_UnregisterKey([In] IntPtr pvContext, in DRT_DATA pKey, [In, Optional] IntPtr pvKeyContext); /// /// Called when an Authority message is received on the wire. It is responsible for validating the data received, and for unpacking /// the service addresses, revoked flag, and nonce from the Secured Address Payload. /// /// Pointer to the value held by the pvContext member of DRT_SECURITY_PROVIDER. /// /// Pointer to the payload received on the wire that contains the service addresses, revoked flag, nonce, and any other data /// required by the security provider. /// /// Pointer to the cert chain received in the authority message. /// Pointer to the classifier received in the authority message. /// /// Pointer to the nonce that was sent in the original Inquire or Lookup message. This value must be compared to the /// value embedded in the Secured Address Payload to ensure they are the same. This value is fixed at 16 bytes. /// /// /// Pointer to the application data payload received in the Authority message. After validation, the original data (after /// decryption, removal of signature, and so on.) is output as pPayload. /// /// /// Pointer to the byte array that represents the protocol major version. This is packed in every DRT packet to identify the version /// of the security provider in use when a single DRT instance is supporting multiple Security Providers. /// /// /// Pointer to the byte array that represents the protocol minor version. This is packed in every DRT packet to identify the version /// of the security provider in use when a single DRT instance is supporting multiple Security Providers. /// /// Pointer to the key to which the payload is registered. /// /// Pointer to the original payload specified by the remote application. pPayload.pb is allocated by the security provider. /// /// Pointer to a pointer to the number of service addresses embedded in the secured address payload. /// /// Pointer to a pointer to the service addresses that are embedded in the Secured Address Payload. pAddresses is allocated /// by the security provider. /// /// /// Any DRT flags currently defined only to be the revoked or deleted flag that need to be unpacked for the local DRT instance processing. /// Note Currently the only allowed value is: DRT_PAYLOAD_REVOKED (1) /// /// public unsafe delegate HRESULT DRT_SECURITY_PROVIDER_ValidateAndUnpackPayload([In] IntPtr pvContext, in DRT_DATA pSecuredAddressPayload, [In, Optional] DRT_DATA* pCertChain, [In, Optional] DRT_DATA* pClassifier, [In, Optional] DRT_DATA* pNonce, [In, Optional] DRT_DATA* pSecuredPayload, [Out] byte* pbProtocolMajor, [Out] byte* pbProtocolMinor, out DRT_DATA pKey, [Out, Optional] DRT_DATA* pPayload, [Out] CERT_PUBLIC_KEY_INFO** ppPublicKey, [Out, Optional] void** ppAddressList, out uint pdwFlags); /// Called when the DRT must validate a credential provided by a peer node. /// Pointer to the value held by the pvContext member of DRT_SECURITY_PROVIDER. /// Contains the serialized credential provided by the peer node. /// public delegate HRESULT DRT_SECURITY_PROVIDER_ValidateRemoteCredential([In] IntPtr pvContext, in DRT_DATA pRemoteCredential); /// /// Called when the DRT must verify a signature calculated over a block of data included in a DRT message. This function is only /// called when the DRT is operating in the DRT_SECURE_MEMBERSHIP and DRT_SECURE_CONFIDENTIALPAYLOAD security modes /// defined by DRT_SECURITY_MODE. /// /// Pointer to the value held by the pvContext member of DRT_SECURITY_PROVIDER. /// Contains the size of the pDataBuffers buffer. /// Contains the data over which the signature was calculated. /// Contains the credentials of the remote node used to calculate the signature. /// Contains an index that may be used to select from multiple credentials provided in pRemoteCredentials. /// Contains the signature to be verified. /// public delegate HRESULT DRT_SECURITY_PROVIDER_VerifyData([In] IntPtr pvContext, [In] uint dwBuffers, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] DRT_DATA[] pDataBuffers, in DRT_DATA pRemoteCredentials, in DRT_DATA pKeyIdentifier, in DRT_DATA pSignature); /// /// The DRT_ADDRESS_FLAGS enumeration defines the set of responses that may be returned by an intermediate node when /// performing a search for a key. /// // https://docs.microsoft.com/en-us/windows/win32/api/drt/ne-drt-drt_address_flags typedef enum _DRT_ADDRESS_FLAGS { // DRT_ADDRESS_FLAG_ACCEPTED, DRT_ADDRESS_FLAG_REJECTED, DRT_ADDRESS_FLAG_UNREACHABLE, DRT_ADDRESS_FLAG_LOOP, // DRT_ADDRESS_FLAG_TOO_BUSY, DRT_ADDRESS_FLAG_BAD_VALIDATE_ID, DRT_ADDRESS_FLAG_SUSPECT_UNREGISTERED_ID, DRT_ADDRESS_FLAG_INQUIRE } // DRT_ADDRESS_FLAGS, *PDRT_ADDRESS_FLAGS; [PInvokeData("drt.h", MSDNShortId = "NE:drt._DRT_ADDRESS_FLAGS")] [Flags] public enum DRT_ADDRESS_FLAGS { /// The response provided by this machine was successfully used to make progress towards the search target. DRT_ADDRESS_FLAG_ACCEPTED = 0x01, /// /// The response provided by this machine was not used in the search. This machine may have provided the address of a node /// publishing a key numerically farther from the target than other nodes already contacted. /// DRT_ADDRESS_FLAG_REJECTED = 0x02, /// This machine did not respond. DRT_ADDRESS_FLAG_UNREACHABLE = 0x04, /// /// The response provided by this machine was not used in the search. This machine provided the address of a node that has /// already been contacted. /// DRT_ADDRESS_FLAG_LOOP = 0x08, /// This machine indicated that it does not have sufficient resources to process the query. DRT_ADDRESS_FLAG_TOO_BUSY = 0x10, /// /// This machine is not publishing the key expected by the local DRT instance. As a result, it may not be able to provide useful information. /// DRT_ADDRESS_FLAG_BAD_VALIDATE_ID = 0x20, /// This machine has reason to believe that the target key has been unregistered. DRT_ADDRESS_FLAG_SUSPECT_UNREGISTERED_ID = 0x40, /// This machine was asked to provide proof of ownership of its key. DRT_ADDRESS_FLAG_INQUIRE = 0x80, } /// The DRT_EVENT_TYPE enumeration defines the set of events that can be raised by the Distributed Routing Table. /// The event handle passed to DrtOpen is signaled with an event specified by the DRT_EVENT_TYPE enumeration. // https://docs.microsoft.com/en-us/windows/win32/api/drt/ne-drt-drt_event_type typedef enum drt_event_type_tag { // DRT_EVENT_STATUS_CHANGED, DRT_EVENT_LEAFSET_KEY_CHANGED, DRT_EVENT_REGISTRATION_STATE_CHANGED } DRT_EVENT_TYPE; [PInvokeData("drt.h", MSDNShortId = "NE:drt.drt_event_type_tag")] public enum DRT_EVENT_TYPE { /// The status of the local DRT instance has changed. DRT_EVENT_STATUS_CHANGED, /// A key or node was changed from the DRT leaf set of the local node. DRT_EVENT_LEAFSET_KEY_CHANGED, /// A locally published key is no longer resolvable by other nodes. DRT_EVENT_REGISTRATION_STATE_CHANGED, } /// /// The DRT_LEAFSET_KEY_CHANGE_TYPE enumeration defines the set of changes that can occur on nodes in the leaf set of a /// locally registered key. /// /// /// This enumeration is used to determine the event type returned by DrtGetEventData, which is called with the event handle passed /// to DrtOpen. /// // https://docs.microsoft.com/en-us/windows/win32/api/drt/ne-drt-drt_leafset_key_change_type typedef enum // drt_leafset_key_change_type_tag { DRT_LEAFSET_KEY_ADDED, DRT_LEAFSET_KEY_DELETED } DRT_LEAFSET_KEY_CHANGE_TYPE; [PInvokeData("drt.h", MSDNShortId = "NE:drt.drt_leafset_key_change_type_tag")] public enum DRT_LEAFSET_KEY_CHANGE_TYPE { /// A node was added to the DRT leaf set of the local node. DRT_LEAFSET_KEY_ADDED, /// A node was deleted from the DRT leaf set of the local node. DRT_LEAFSET_KEY_DELETED, } /// The DRT_MATCH_TYPE enumeration defines the exactness of a search result returned by DrtGetSearchResult after initiating a search with the DrtStartSearch API. // https://learn.microsoft.com/en-us/windows/win32/api/drt/ne-drt-drt_match_type // typedef enum drt_match_type_tag { DRT_MATCH_EXACT = 0, DRT_MATCH_NEAR = 1, DRT_MATCH_INTERMEDIATE = 2 } DRT_MATCH_TYPE; [PInvokeData("drt.h", MSDNShortId = "NE:drt.drt_match_type_tag")] public enum DRT_MATCH_TYPE { /// /// Value: /// 0 /// The node found is publishing the target key or is publishing a key within the specified range. /// DRT_MATCH_EXACT, /// /// Value: /// 1 /// The node found is publishing the numerically closest key to the specified target key. /// DRT_MATCH_NEAR, /// /// Value: /// 2 /// /// The node returned is an intermediate node. An application will receive this node match type if fIterative is set to /// . /// /// DRT_MATCH_INTERMEDIATE, } /// The DRT_REGISTRATION_STATE enumeration defines the set of legal states for a registered key. // https://docs.microsoft.com/en-us/windows/win32/api/drt/ne-drt-drt_registration_state typedef enum _DRT_REGISTRATION_STATE { // DRT_REGISTRATION_STATE_UNRESOLVEABLE } DRT_REGISTRATION_STATE, *PDRT_REGISTRATION_STATE; [PInvokeData("drt.h", MSDNShortId = "NE:drt._DRT_REGISTRATION_STATE")] public enum DRT_REGISTRATION_STATE { /// /// The locally registered key is no longer resolvable by other nodes. The Distributed Routing Table signals this state when the /// local security provider is unable to generate an authentication token for the locally registered key. For example, if the /// Derived Key Security Provider is used, this state is signaled when the certificate used to authenticate expires. /// DRT_REGISTRATION_STATE_UNRESOLVEABLE = 1, } /// /// The DRT_SCOPE enumeration defines the set of IPv6 scopes in which DRT operates while using the IPv6 UDP transport created /// by DrtCreateIpv6UdpTransport. /// // https://docs.microsoft.com/en-us/windows/win32/api/drt/ne-drt-drt_scope typedef enum drt_scope_tag { DRT_GLOBAL_SCOPE, // DRT_SITE_LOCAL_SCOPE, DRT_LINK_LOCAL_SCOPE } DRT_SCOPE; [PInvokeData("drt.h", MSDNShortId = "NE:drt.drt_scope_tag")] public enum DRT_SCOPE { /// Uses the global scope. DRT_GLOBAL_SCOPE = 1, /// The DRT_SITE_LOCAL_SCOPE has been deprecated and should not be used. DRT_SITE_LOCAL_SCOPE, /// Uses the link local scope. DRT_LINK_LOCAL_SCOPE, } /// /// The DRT_SECURITY_MODE enumeration defines possible security modes for the DRT. The security mode is specified by a field /// of the DRT_SETTINGS structure. /// /// /// The more secure a DRT security mode, the more of a computational load exists for nodes participating in the DRT. More bandwidth /// is also consumed. /// // https://docs.microsoft.com/en-us/windows/win32/api/drt/ne-drt-drt_security_mode typedef enum drt_security_mode_tag { // DRT_SECURE_RESOLVE, DRT_SECURE_MEMBERSHIP, DRT_SECURE_CONFIDENTIALPAYLOAD } DRT_SECURITY_MODE; [PInvokeData("drt.h", MSDNShortId = "NE:drt.drt_security_mode_tag")] public enum DRT_SECURITY_MODE { /// /// Nodes must authenticate the keys they publish. Nodes are not required to authenticate themselves when performing searches. /// DRT_SECURE_RESOLVE, /// /// Nodes must authenticate the keys they publish. Nodes must also authenticate themselves when performing searches. /// Unauthorized nodes cannot search for keys and cannot retrieve the data associated with published keys. /// DRT_SECURE_MEMBERSHIP, /// /// Nodes must authenticate the keys they publish. Nodes must also authenticate themselves when performing searches. Encryption /// is required for all data associated with published keys prior to transmission between DRT nodes. Unauthorized nodes cannot /// search for keys, cannot retrieve the data associated with published keys, and cannot retrieve data by observing network /// traffic between other DRT nodes. /// DRT_SECURE_CONFIDENTIALPAYLOAD, } /// The DRT_STATUS enumeration defines the status of a local DRT instance. // https://docs.microsoft.com/en-us/windows/win32/api/drt/ne-drt-drt_status typedef enum drt_status_tag { DRT_ACTIVE, DRT_ALONE, // DRT_NO_NETWORK, DRT_FAULTED } DRT_STATUS; [PInvokeData("drt.h", MSDNShortId = "NE:drt.drt_status_tag")] public enum DRT_STATUS { /// /// The local node is connected to the DRT mesh and participating in the DRT system. This is also an indication that remote /// nodes exist and are present in the cache of the local node. /// DRT_ACTIVE = 0, /// /// The local node is participating in the DRT system, but is waiting for remote nodes to join the DRT mesh. This is an /// indication that remote nodes do not exist, or are not yet present in the cache of the local node. /// DRT_ALONE = 1, /// The local node does not have network connectivity. DRT_NO_NETWORK = 10, /// /// A critical error has occurred in the local DRT instance. The DrtClose function must be called, after which an attempt to /// re-open the DRT can be made. /// DRT_FAULTED = 20, } /// The DrtClose function closes the local instance of the DRT. /// Handle to the DRT instance. /// /// This function returns S_OK on success. Other possible values include: /// /// /// Return code /// Description /// /// /// E_HANDLE /// The hDrt handle is invalid. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/drt/nf-drt-drtclose void DrtClose( HDRT hDrt ); [DllImport(Lib_Drt, SetLastError = false, ExactSpelling = true)] [PInvokeData("drt.h", MSDNShortId = "NF:drt.DrtClose")] public static extern void DrtClose(HDRT hDrt); /// /// The DrtContinueSearch function continues an iterative search for a key.This function is used only when the /// fIterative flag is set to 'true' in the associated DRT_SEARCH_INFO structure. Call this after getting a /// DRT_MATCH_INTERMEDIATE search result. /// /// Handle to the search context to close. This parameter is returned by the DrtStartSearch API. /// /// This function returns S_OK on success. Other possible values include: /// /// /// Return code /// Description /// /// /// E_HANDLE /// The hSearchContext handle is invalid. /// /// /// E_UNEXPECTED /// This search is not an iterative search. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/drt/nf-drt-drtcontinuesearch HRESULT DrtContinueSearch( HDRT_SEARCH_CONTEXT // hSearchContext ); [DllImport(Lib_Drt, SetLastError = false, ExactSpelling = true)] [PInvokeData("drt.h", MSDNShortId = "NF:drt.DrtContinueSearch")] public static extern HRESULT DrtContinueSearch(HDRT_SEARCH_CONTEXT hSearchContext); /// /// The DrtCreateDerivedKey function creates a key that can be utilized by DrtRegisterKey when the DRT is using a derived key /// security provider. /// /// /// Pointer to the certificate that is the "local" portion of the chain. The root of this chain must match the root specified by /// pRootCert in DrtCreateDerivedKeySecurityProvider. This certificate is used to generate a key that is used to register and prove /// "key ownership" with the DRT. /// /// Pointer to the created key. /// /// This function returns S_OK on success. Other possible values include: /// /// /// Return code /// Description /// /// /// E_INVALIDARG /// /// /// /// DRT_E_CAPABILITY_MISMATCH /// /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/drt/nf-drt-drtcreatederivedkey HRESULT DrtCreateDerivedKey( PCCERT_CONTEXT // pLocalCert, DRT_DATA *pKey ); [DllImport(Lib_DrtProv, SetLastError = false, ExactSpelling = true)] [PInvokeData("drt.h", MSDNShortId = "NF:drt.DrtCreateDerivedKey")] public static extern HRESULT DrtCreateDerivedKey(PCCERT_CONTEXT pLocalCert, [Out] SafeDRT_DATA pKey); /// /// The DrtCreateDerivedKeySecurityProvider function creates the derived key security provider for a Distributed Routing Table. /// /// /// Pointer to the certificate that is the "root" portion of the chain. This is used to ensure that keys derived from the same chain /// can be verified. /// /// Pointer to the DRT_SECURITY_PROVIDER module to be included in the DRT_SETTINGS structure. /// Receives a pointer to the created security provider. /// /// This function returns S_OK on success. Other possible values include: /// /// /// Return code /// Description /// /// /// E_INVALIDARG /// pRootCert is NULL. /// /// /// E_OUTOFMEMORY /// The system could not allocate memory for the security provider. /// /// /// DRT_E_CAPABILITY_MISMATCH /// /// /// /// DRT_E_INVALID_CERT_CHAIN /// No certificate store attached or there is an error in the certificate chain. /// /// /// /// /// The security provider created by this function is specific to the DRT it was created for. It cannot be shared by multiple DRT instances. /// // https://docs.microsoft.com/en-us/windows/win32/api/drt/nf-drt-drtcreatederivedkeysecurityprovider HRESULT // DrtCreateDerivedKeySecurityProvider( PCCERT_CONTEXT pRootCert, PCCERT_CONTEXT pLocalCert, DRT_SECURITY_PROVIDER // **ppSecurityProvider ); [DllImport(Lib_DrtProv, SetLastError = false, ExactSpelling = true)] [PInvokeData("drt.h", MSDNShortId = "NF:drt.DrtCreateDerivedKeySecurityProvider")] public static extern HRESULT DrtCreateDerivedKeySecurityProvider(PCCERT_CONTEXT pRootCert, PCCERT_CONTEXT pLocalCert, out IntPtr ppSecurityProvider); /// /// The DrtCreateDnsBootstrapResolver function creates a bootstrap resolver that will use the GetAddrInfo system function to /// resolve the hostname of a will known node already present in the DRT mesh. /// /// Specifies the port to which the DRT protocol is bound on the well known node. /// Specifies the hostname of the well known node. /// Pointer to the DRT_BOOTSTRAP_PROVIDER module to be included in the DRT_SETTINGS structure. /// /// This function returns S_OK on success. Other possible values include: /// /// /// Return code /// Description /// /// /// E_INVALIDARG /// pwszAddress is NULL. /// /// /// E_OUTOFMEMORY /// The system could not allocate memory for the provider. /// /// /// Note This function may also return errors from underlying calls to WSAStartup and StringCbPrintfW. /// // https://docs.microsoft.com/en-us/windows/win32/api/drt/nf-drt-drtcreatednsbootstrapresolver HRESULT // DrtCreateDnsBootstrapResolver( USHORT port, PCWSTR pwszAddress, DRT_BOOTSTRAP_PROVIDER **ppModule ); [DllImport(Lib_DrtProv, SetLastError = false, ExactSpelling = true)] [PInvokeData("drt.h", MSDNShortId = "NF:drt.DrtCreateDnsBootstrapResolver")] public static extern HRESULT DrtCreateDnsBootstrapResolver(ushort port, [MarshalAs(UnmanagedType.LPWStr)] string pwszAddress, out IntPtr ppModule); /// The DrtCreateIpv6UdpTransport function creates a transport based on the IPv6 UDP protocol. /// The DRT_SCOPE enumeration that specifies the IPv6 scope in which the DRT is to operate. /// /// The identifier that uniquely specifies the interface the scope is associated with. /// /// For the Global scope this parameter is always the "GLOBAL_" ID and is optional when using only the global scope. For the link /// local scope, this parameter represents the interface associated with the Network Interface Card on which the link local scope exists. /// /// /// /// The identifier that specifies how Locality information based on IpV6 addresses is used when caching neighbors. By default, the /// DRT gives preference to neighbors that have an IPv6 address with a prefix in common with the local machine. /// /// Pointer to the port utilized by the local DRT instance. /// Pointer to a DRT transport handle specified in the DRT_SETTINGS structure. /// /// This function returns S_OK on success. Other possible values include: /// /// /// Return code /// Description /// /// /// E_OUTOFMEMORY /// The system cannot allocate memory for the provider. /// /// /// DRT_E_INVALID_PORT /// pwPort is NULL. /// /// /// DRT_E_INVALID_TRANSPORT_PROVIDER /// hTransport is NULL. /// /// /// DRT_E_INVALID_SCOPE /// The specified scope is not DRT_GLOBAL_SCOPE, DRT_SITE_LOCAL_SCOPE or DRT_LINK_LOCAL_SCOPE. /// /// /// DRT_E_TRANSPORT_UNEXPECTED /// An unexpected error has occurred. See TraceError for reason. /// /// /// /// Note This function may also return errors from underlying calls to NotifyUnicastIpAddressChange,WSAStartup, /// GetAdaptersAddresses, setsockopt, WSASocket, Bind, WSAIoctl, CreateThreadpoolIo, CreateThreadpoolCleanupGroup and CreateTimerQueue. /// /// /// /// /// The default IPv6 UDP Transport created by this function is specific to the DRT it is created for. As a result it cannot be /// re-used across multiple DRTs. /// /// /// When using the Distributed Routing Table API in Windows XP with Service Pack 2 (SP2), support of the IPv6 protocol must be /// enabled for the creation of a transport using DrtCreateIpv6UdpTransport to be successful. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/drt/nf-drt-drtcreateipv6udptransport HRESULT DrtCreateIpv6UdpTransport( // DRT_SCOPE scope, ULONG dwScopeId, ULONG dwLocalityThreshold, USHORT *pwPort, HDRT_TRANSPORT *phTransport ); [DllImport(Lib_DrtTrans, SetLastError = false, ExactSpelling = true)] [PInvokeData("drt.h", MSDNShortId = "NF:drt.DrtCreateIpv6UdpTransport")] public static extern HRESULT DrtCreateIpv6UdpTransport(DRT_SCOPE scope, uint dwScopeId, uint dwLocalityThreshold, ref ushort pwPort, out SafeHDRT_TRANSPORT phTransport); /// /// The DrtCreateNullSecurityProvider function creates a null security provider. This security provider does not require nodes to /// authenticate keys. /// /// Pointer to the DRT_SETTINGS structure. /// /// This function returns S_OK on success. Other possible values include: /// /// /// Return code /// Description /// /// /// E_OUTOFMEMORY /// The system cannot allocate memory for the provider. /// /// /// DRT_E_INVALID_ARG /// ppDrtSecurityProvider is NULL. /// /// /// // https://learn.microsoft.com/en-us/windows/win32/api/drt/nf-drt-drtcreatenullsecurityprovider // HRESULT DrtCreateNullSecurityProvider( [out] DRT_SECURITY_PROVIDER **ppSecurityProvider ); [PInvokeData("drt.h", MSDNShortId = "NF:drt.DrtCreateNullSecurityProvider")] [DllImport(Lib_DrtProv, SetLastError = false, ExactSpelling = true)] public static extern HRESULT DrtCreateNullSecurityProvider(out IntPtr ppSecurityProvider); /// /// The DrtCreatePnrpBootstrapResolver function creates a bootstrap resolver based on the Peer Name Resolution Protocol (PNRP). /// /// /// If TRUE, the PeerName contained in pwzPeerName and passed with the PNRP Bootstrap Resolver is published by the local DRT /// using PNRP. This node will be resolvable by other nodes using the PNRP bootstrap provider, and will assist other nodes /// attempting to bootstrap /// /// /// The name of the peer to search for in the PNRP cloud. This string has a maximum limit of 137 unicode characters /// /// /// The name of the cloud to search for in for the DRT corresponding to the MeshName. /// /// This string has a maximum limit of 256 unicode characters. If left blank the PNRP Bootstrap Provider will use all PNRP clouds available. /// /// /// /// The PeerIdentity that is publishing into the PNRP cloud utilized for bootstrapping. This string has a maximum limit of 137 /// unicode characters. It is important to note that if fPublish is set to TRUE, the PublishingIdentity must be allowed to /// publish the PeerName specified. /// /// A pointer to the created PNRP bootstrap resolver which is used in the DRT_SETTINGS structure. /// /// This function returns S_OK on success. Other possible values include: /// /// /// Return code /// Description /// /// /// E_OUTOFMEMORY /// The system cannot allocate memory for the provider. /// /// /// E_INVALIDARG /// pwzPeerName is invalid. /// /// /// DRT_S_RETRY /// Underlying calls to PeerPnrpStartup or PeerIdentityGetCryptKey return a transient error. Try calling this function again. /// /// /// Note This function may also surface errors returned by underlying calls to PeerPnrpStartup or PeerIdentityGetCryptKey. /// /// /// The default PNRP Bootstrap Resolver created by this function is specific to the DRT it is created for. As a result it cannot be /// re-used across multiple DRTs. /// // https://docs.microsoft.com/en-us/windows/win32/api/drt/nf-drt-drtcreatepnrpbootstrapresolver HRESULT // DrtCreatePnrpBootstrapResolver( BOOL fPublish, PCWSTR pwzPeerName, PCWSTR pwzCloudName, PCWSTR pwzPublishingIdentity, // DRT_BOOTSTRAP_PROVIDER **ppResolver ); [DllImport(Lib_DrtProv, SetLastError = false, ExactSpelling = true)] [PInvokeData("drt.h", MSDNShortId = "NF:drt.DrtCreatePnrpBootstrapResolver")] public static extern HRESULT DrtCreatePnrpBootstrapResolver([MarshalAs(UnmanagedType.Bool)] bool fPublish, [MarshalAs(UnmanagedType.LPWStr)] string pwzPeerName, [Optional, MarshalAs(UnmanagedType.LPWStr)] string? pwzCloudName, [Optional, MarshalAs(UnmanagedType.LPWStr)] string? pwzPublishingIdentity, out IntPtr ppResolver); /// /// The DrtDeleteDerivedKeySecurityProvider function deletes a derived key security provider for a Distributed Routing Table. /// /// Pointer to a DRT_SECURITY_PROVIDER specifying the security provider to delete. /// None // https://docs.microsoft.com/en-us/windows/win32/api/drt/nf-drt-drtdeletederivedkeysecurityprovider void // DrtDeleteDerivedKeySecurityProvider( DRT_SECURITY_PROVIDER *pSecurityProvider ); [DllImport(Lib_DrtProv, SetLastError = false, ExactSpelling = true)] [PInvokeData("drt.h", MSDNShortId = "NF:drt.DrtDeleteDerivedKeySecurityProvider")] public static extern void DrtDeleteDerivedKeySecurityProvider(in DRT_SECURITY_PROVIDER pSecurityProvider); /// /// The DrtDeleteDerivedKeySecurityProvider function deletes a derived key security provider for a Distributed Routing Table. /// /// Pointer to a DRT_SECURITY_PROVIDER specifying the security provider to delete. /// None // https://docs.microsoft.com/en-us/windows/win32/api/drt/nf-drt-drtdeletederivedkeysecurityprovider void // DrtDeleteDerivedKeySecurityProvider( DRT_SECURITY_PROVIDER *pSecurityProvider ); [DllImport(Lib_DrtProv, SetLastError = false, ExactSpelling = true)] [PInvokeData("drt.h", MSDNShortId = "NF:drt.DrtDeleteDerivedKeySecurityProvider")] public static extern void DrtDeleteDerivedKeySecurityProvider([In] IntPtr pSecurityProvider); /// The DrtDeleteDnsBootstrapResolver function deletes a DNS Bootstrap Provider instance. /// Pointer to a DRT_BOOTSTRAP_PROVIDER instance specifying the security provider to delte. /// None // https://docs.microsoft.com/en-us/windows/win32/api/drt/nf-drt-drtdeletednsbootstrapresolver void DrtDeleteDnsBootstrapResolver( // DRT_BOOTSTRAP_PROVIDER *pResolver ); [DllImport(Lib_DrtProv, SetLastError = false, ExactSpelling = true)] [PInvokeData("drt.h", MSDNShortId = "NF:drt.DrtDeleteDnsBootstrapResolver")] public static extern void DrtDeleteDnsBootstrapResolver(in DRT_BOOTSTRAP_PROVIDER pResolver); /// The DrtDeleteDnsBootstrapResolver function deletes a DNS Bootstrap Provider instance. /// Pointer to a DRT_BOOTSTRAP_PROVIDER instance specifying the security provider to delte. /// None // https://docs.microsoft.com/en-us/windows/win32/api/drt/nf-drt-drtdeletednsbootstrapresolver void DrtDeleteDnsBootstrapResolver( // DRT_BOOTSTRAP_PROVIDER *pResolver ); [DllImport(Lib_DrtProv, SetLastError = false, ExactSpelling = true)] [PInvokeData("drt.h", MSDNShortId = "NF:drt.DrtDeleteDnsBootstrapResolver")] public static extern void DrtDeleteDnsBootstrapResolver([In] IntPtr pResolver); /// The DrtDeleteIpv6UdpTransport function deletes a transport based on the IPv6 UDP protocol. /// The DRT transport handle specifying the transport to delete. /// /// This function returns S_OK on success. Other possible values include: /// /// /// Return code /// Description /// /// /// DRT_E_INVALID_TRANSPORT_PROVIDER /// hTransport is NULL or invalid. /// /// /// DRT_E_TRANSPORT_EXECUTING_CALLBACK /// The transport provider is currently executing a method. /// /// /// DRT_E_TRANSPORT_STILL_BOUND /// The transport is still bound. /// /// /// DRT_E_TRANSPORTPROVIDER_IN_USE /// All clients have not called Release on the transport. /// /// /// Note This function may also surface errors returned by underlying calls to PeerPnrpStartup or PeerIdentityGetCryptKey. /// // https://docs.microsoft.com/en-us/windows/win32/api/drt/nf-drt-drtdeleteipv6udptransport HRESULT DrtDeleteIpv6UdpTransport( // HDRT_TRANSPORT hTransport ); [DllImport(Lib_DrtTrans, SetLastError = false, ExactSpelling = true)] [PInvokeData("drt.h", MSDNShortId = "NF:drt.DrtDeleteIpv6UdpTransport")] public static extern HRESULT DrtDeleteIpv6UdpTransport(HDRT_TRANSPORT hTransport); /// The DrtDeleteNullSecurityProvider function deletes a null security provider for a Distributed Routing Table. /// Pointer to a DRT_SECURITY_PROVIDER structure specifying the security provider to delete. /// None // https://docs.microsoft.com/en-us/windows/win32/api/drt/nf-drt-drtdeletenullsecurityprovider void DrtDeleteNullSecurityProvider( // DRT_SECURITY_PROVIDER *pSecurityProvider ); [DllImport(Lib_DrtProv, SetLastError = false, ExactSpelling = true)] [PInvokeData("drt.h", MSDNShortId = "NF:drt.DrtDeleteNullSecurityProvider")] public static extern void DrtDeleteNullSecurityProvider(in DRT_SECURITY_PROVIDER pSecurityProvider); /// The DrtDeleteNullSecurityProvider function deletes a null security provider for a Distributed Routing Table. /// Pointer to a DRT_SECURITY_PROVIDER structure specifying the security provider to delete. /// None // https://docs.microsoft.com/en-us/windows/win32/api/drt/nf-drt-drtdeletenullsecurityprovider void DrtDeleteNullSecurityProvider( // DRT_SECURITY_PROVIDER *pSecurityProvider ); [DllImport(Lib_DrtProv, SetLastError = false, ExactSpelling = true)] [PInvokeData("drt.h", MSDNShortId = "NF:drt.DrtDeleteNullSecurityProvider")] public static extern void DrtDeleteNullSecurityProvider([In] IntPtr pSecurityProvider); /// /// The DrtDeletePnrpBootstrapResolver function deletes a bootstrap resolver based on the Peer Name Resolution Protocol (PNRP). /// /// Pointer to the created PNRP bootstrap resolver to be deleted. /// None // https://docs.microsoft.com/en-us/windows/win32/api/drt/nf-drt-drtdeletepnrpbootstrapresolver void DrtDeletePnrpBootstrapResolver( // DRT_BOOTSTRAP_PROVIDER *pResolver ); [DllImport(Lib_DrtProv, SetLastError = false, ExactSpelling = true)] [PInvokeData("drt.h", MSDNShortId = "NF:drt.DrtDeletePnrpBootstrapResolver")] public static extern void DrtDeletePnrpBootstrapResolver(in DRT_BOOTSTRAP_PROVIDER pResolver); /// /// The DrtDeletePnrpBootstrapResolver function deletes a bootstrap resolver based on the Peer Name Resolution Protocol (PNRP). /// /// Pointer to the created PNRP bootstrap resolver to be deleted. /// None // https://docs.microsoft.com/en-us/windows/win32/api/drt/nf-drt-drtdeletepnrpbootstrapresolver void DrtDeletePnrpBootstrapResolver( // DRT_BOOTSTRAP_PROVIDER *pResolver ); [DllImport(Lib_DrtProv, SetLastError = false, ExactSpelling = true)] [PInvokeData("drt.h", MSDNShortId = "NF:drt.DrtDeletePnrpBootstrapResolver")] public static extern void DrtDeletePnrpBootstrapResolver([In] IntPtr pResolver); /// /// The DrtEndSearch function cancels a search for a key in a DRT. This API can be called at any point after a search is issued. /// /// Handle to the search context to end. This parameter is returned from DrtStartSearch. /// /// This function returns S_OK on success. Other possible values include: /// /// /// Return code /// Description /// /// /// E_HANDLE /// The hSearchContext handle is invalid. /// /// /// E_UNEXPECTED /// The DRT infrastructure is unaware of the requested search. /// /// /// /// Calling the DrtEndSearch function will stop the return of search results via DRT_SEARCH_RESULT. // https://docs.microsoft.com/en-us/windows/win32/api/drt/nf-drt-drtendsearch HRESULT DrtEndSearch( HDRT_SEARCH_CONTEXT // hSearchContext ); [DllImport(Lib_Drt, SetLastError = false, ExactSpelling = true)] [PInvokeData("drt.h", MSDNShortId = "NF:drt.DrtEndSearch")] public static extern HRESULT DrtEndSearch(HDRT_SEARCH_CONTEXT hSearchContext); /// The DrtGetEventData function retrieves event data associated with a signaled event. /// Handle to the Distributed Routing Table instance for which the event occurred. /// The size, in bytes, of the pEventData buffer. /// Pointer to a DRT_EVENT_DATA structure that contains the event data. /// /// This function returns S_OK on success. Other possible values include: /// /// /// Return code /// Description /// /// /// E_UNEXPECTED /// The DRT infrastructure is unaware of the requested search. /// /// /// E_HANDLE /// The hDrt handle is invalid. /// /// /// DRT_E_INSUFFICIENT_BUFFER /// The provided buffer is insufficient in size. /// /// /// DRT_E_NO_MORE /// No more event data available. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/drt/nf-drt-drtgeteventdata HRESULT DrtGetEventData( HDRT hDrt, ULONG // ulEventDataLen, DRT_EVENT_DATA *pEventData ); [DllImport(Lib_Drt, SetLastError = false, ExactSpelling = true)] [PInvokeData("drt.h", MSDNShortId = "NF:drt.DrtGetEventData")] public static extern HRESULT DrtGetEventData(HDRT hDrt, uint ulEventDataLen, [Out] IntPtr pEventData); /// /// The DrtGetEventDataSize function returns the size of the DRT_EVENT_DATA structure associated with a signaled event. /// /// Handle to the Distributed Routing Table instance for which the event occurred. /// The size, in bytes, of the event data. /// /// This function returns S_OK on success. Other possible values include: /// /// /// Return code /// Description /// /// /// E_UNEXPECTED /// The DRT infrastructure is unaware of the requested search. /// /// /// E_INVALIDARG /// pulEventDataLen is NULL. /// /// /// E_HANDLE /// hDrt is invalid. /// /// /// DRT_E_NO_MORE /// There is no more event data available. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/drt/nf-drt-drtgeteventdatasize HRESULT DrtGetEventDataSize( HDRT hDrt, ULONG // *pulEventDataLen ); [DllImport(Lib_Drt, SetLastError = false, ExactSpelling = true)] [PInvokeData("drt.h", MSDNShortId = "NF:drt.DrtGetEventDataSize")] public static extern HRESULT DrtGetEventDataSize(HDRT hDrt, out uint pulEventDataLen); /// /// The DrtGetInstanceName function retrieves the full name of the Distributed Routing Table instance that corresponds to the /// specified DRT handle. /// /// Handle to the DRT instance. /// The length of the pwzDrtInstanceName buffer. /// Contains the complete name of the DRT instance associated with hDRT. /// /// This function returns S_OK on success. Other possible values include: /// /// /// Return code /// Description /// /// /// E_INVALIDARG /// pwzDrtInstanceName is NULL. /// /// /// E_HANDLE /// hDrt is invalid. /// /// /// DRT_E_INSUFFICIENT_BUFFER /// The pwzDrtInstanceName buffer is insufficient in size. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/drt/nf-drt-drtgetinstancename HRESULT DrtGetInstanceName( HDRT hDrt, ULONG // ulcbInstanceNameSize, PWSTR pwzDrtInstanceName ); [DllImport(Lib_Drt, SetLastError = false, ExactSpelling = true)] [PInvokeData("drt.h", MSDNShortId = "NF:drt.DrtGetInstanceName")] public static extern HRESULT DrtGetInstanceName(HDRT hDrt, uint ulcbInstanceNameSize, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder pwzDrtInstanceName); /// The DrtGetInstanceNameSize function returns the size of the Distributed Routing Table instance name. /// Handle to the target DRT instance. /// The length of the DRT instance name. /// /// This function returns S_OK on success. Other possible values include: /// /// /// Return code /// Description /// /// /// E_INVALIDARG /// pulcbInstanceNameSize is NULL. /// /// /// E_HANDLE /// hDrt handle is invalid. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/drt/nf-drt-drtgetinstancenamesize HRESULT DrtGetInstanceNameSize( HDRT hDrt, // ULONG *pulcbInstanceNameSize ); [DllImport(Lib_Drt, SetLastError = false, ExactSpelling = true)] [PInvokeData("drt.h", MSDNShortId = "NF:drt.DrtGetInstanceNameSize")] public static extern HRESULT DrtGetInstanceNameSize(HDRT hDrt, out uint pulcbInstanceNameSize); /// The DrtGetSearchPath function returns a list of nodes contacted during the search operation. /// Handle to the search context. This parameter is returned by the DrtStartSearch function. /// The size of the search path which represents the number of nodes utilized in the search operation. /// Pointer to a DRT_ADDRESS_LIST structure containing the list of addresses. /// This function returns S_OK on success. // https://docs.microsoft.com/en-us/windows/win32/api/drt/nf-drt-drtgetsearchpath HRESULT DrtGetSearchPath( HDRT_SEARCH_CONTEXT // hSearchContext, ULONG ulSearchPathSize, DRT_ADDRESS_LIST *pSearchPath ); [DllImport(Lib_Drt, SetLastError = false, ExactSpelling = true)] [PInvokeData("drt.h", MSDNShortId = "NF:drt.DrtGetSearchPath")] public static extern HRESULT DrtGetSearchPath(HDRT_SEARCH_CONTEXT hSearchContext, uint ulSearchPathSize, [Out] IntPtr pSearchPath); /// /// The DrtGetSearchPathSize function returns the size of the search path, which represents the number of nodes utilized in /// the search operation. /// /// Handle to the search context. This parameter is returned by the DrtStartSearch function. /// Pointer to a ULONG value that indicates the size of the search path. /// This function returns S_OK on success. // https://docs.microsoft.com/en-us/windows/win32/api/drt/nf-drt-drtgetsearchpathsize HRESULT DrtGetSearchPathSize( // HDRT_SEARCH_CONTEXT hSearchContext, ULONG *pulSearchPathSize ); [DllImport(Lib_Drt, SetLastError = false, ExactSpelling = true)] [PInvokeData("drt.h", MSDNShortId = "NF:drt.DrtGetSearchPathSize")] public static extern HRESULT DrtGetSearchPathSize(HDRT_SEARCH_CONTEXT hSearchContext, out uint pulSearchPathSize); /// The DrtGetSearchResult function allows the caller to retrieve the search result(s). /// Handle to the search context to close. This parameter is returned by the DrtStartSearch function. /// Pointer to the DRT_SEARCH_RESULT structure containing the search result. /// Receives a pointer to a DRT_SEARCH_RESULT structure containing the search results. /// /// This function returns S_OK on success. Other possible values include: /// /// /// Return code /// Description /// /// /// E_INVALIDARG /// ulSearchPathSize is less than the size of DRT_SEARCH_RESULT. /// /// /// E_HANDLE /// hSearchContext is an invalid handle. /// /// /// DRT_E_FAULTED /// the DRT cloud is in the faulted state. /// /// /// DRT_E_INSUFFICIENT_BUFFER /// The provided buffer is insufficient in size to contain the search result. /// /// /// DRT_E_NO_MORE /// There are no more results to return. /// /// /// DRT_E_TIMEOUT /// The search failed because it timed out. /// /// /// DRT_E_SEARCH_IN_PROGRESS /// The search is currently in progress. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/drt/nf-drt-drtgetsearchresult HRESULT DrtGetSearchResult( HDRT_SEARCH_CONTEXT // hSearchContext, ULONG ulSearchResultSize, DRT_SEARCH_RESULT *pSearchResult ); [DllImport(Lib_Drt, SetLastError = false, ExactSpelling = true)] [PInvokeData("drt.h", MSDNShortId = "NF:drt.DrtGetSearchResult")] public static extern HRESULT DrtGetSearchResult(HDRT_SEARCH_CONTEXT hSearchContext, uint ulSearchResultSize, [Out] IntPtr pSearchResult); /// The DrtGetSearchResultSize function returns the size of the next available search result. /// Handle to the search context to close. This parameter is returned by the DrtStartSearch function. /// Holds the size of the next available search result. /// /// Returns S_OK if the function succeeds. Other possible values include: /// /// /// Return code /// Description /// /// /// E_INVALIDARG /// pulSearchResultSize is NULL. /// /// /// E_HANDLE /// hSearchContext is an invalid handle. /// /// /// DRT_E_FAULTED /// The DRT cloud is in the faulted state. /// /// /// DRT_E_NO_MORE /// There are no more results to return. /// /// /// DRT_E_TIMEOUT /// The search failed because it timed out. /// /// /// DRT_E_SEARCH_IN_PROGRESS /// The search is still in progress. /// /// /// /// /// The application will receive S_OK and continue to loop using the DrtGetSearchResultSize and DrtGetSearchResult functions /// as long as the queue contains the search results. When the queue is empty the DrtGetSearchResult function will return /// DRT_E_SEARCH_IN_PROGRESS or DRT_E_NO_MORE. /// // https://docs.microsoft.com/en-us/windows/win32/api/drt/nf-drt-drtgetsearchresultsize HRESULT DrtGetSearchResultSize( // HDRT_SEARCH_CONTEXT hSearchContext, ULONG *pulSearchResultSize ); [DllImport(Lib_Drt, SetLastError = false, ExactSpelling = true)] [PInvokeData("drt.h", MSDNShortId = "NF:drt.DrtGetSearchResultSize")] public static extern HRESULT DrtGetSearchResultSize(HDRT_SEARCH_CONTEXT hSearchContext, out uint pulSearchResultSize); /// /// The DrtOpen function creates a local Distributed Routing Table instance against criteria specified by the DRT_SETTINGS structure. /// /// /// Pointer to the DRT_SETTINGS structure which specifies the settings used for the creation of the DRT instance. /// /// Handle to the event signaled when an event occurs. /// User defined context data which is passed to the application via events. /// The new handle associated with the DRT. This is used in all future operations on the DRT instance. /// /// This function returns S_OK on success. Other possible values include: /// /// /// Return code /// Description /// /// /// E_INVALIDARG /// phDrt is NULL. /// /// /// DRT_E_INVALID_SETTINGS /// pSettings is NULL or the dwSize member value of DRT_SETTINGS is not equal to the size of the DRT_SETTINGS object. /// /// /// DRT_E_INVALID_KEY_SIZE /// cbKey is not equal to 256 bits. /// /// /// DRT_E_INVALID_MAX_ADDRESSES /// The ulMaxRoutingAddresses member of DRT_SETTINGS specifies less than 1 or more than 20 as the maximum number of addresses. /// /// /// DRT_E_INVALID_TRANSPORT_PROVIDER /// The hTransport member in DRT_SETTINGS is NULL or some fields of the Transport are NULL /// /// /// DRT_E_INVALID_SECURITY_MODE /// The eSecurityMode member of DRT_SETTINGS specifies an invalid security mode. /// /// /// DRT_E_INVALID_SECURITY_PROVIDER /// The pSecurityProvider member of DRT_SETTINGS is NULL. /// /// /// DRT_E_INVALID_BOOTSTRAP_PROVIDER /// The pBootstrapProvider member of DRT_SETTINGS is NULL or some fields of the bootstrap provider are NULL. /// /// /// DRT_E_INVALID_INSTANCE_PREFIX /// The size of the pwzDrtInstancePrefix specified in DRT_SETTINGS is larger than the maximum prefix length (128). /// /// /// E_OUTOFMEMORY /// The system cannot allocate memory for this operation. /// /// /// DRT_E_BOOTSTRAPPROVIDER_IN_USE /// The bootstrap provider is already attached. /// /// /// DRT_E_SECURITYPROVIDER_IN_USE /// The security provider is already attached. /// /// /// DRT_TRANSPORTPROVIDER_IN_USE /// The transport provider is already attached. /// /// /// DRT_E_INVALID_CERT_CHAIN /// The certification chain is invalid. /// /// /// DRT_E_CAPABILITY_MISMATCH /// Local certificate cannot be NULL in DRT_SECURE_MEMBERSHIP and DRT_SECURE_CONFIDENTIALPAYLOAD security. /// /// /// DRT_E_TRANSPORT_SHUTTING_DOWN /// Transport is shutting down. /// /// /// DRT_E_TRANSPORT_ALREADY_BOUND /// Trasport is already bound. /// /// /// DRT_S_RETRY /// Bootstrap provider failed to locate other nodes, but may be successful in a second attempt. /// /// /// DRT_E_TRANSPORT_INVALID_ARGUMENT /// Transport provider parameter is NULL or invalid. /// /// /// DRT_E_TRANSPORTPROVIDER_NOT_ATTACHED /// Transport is not attached. /// /// /// E_FAIL /// An unexpected fatal error occurred. /// /// /// /// /// After DrtOpen is called, the DRT will begin the bootstrapping procedure and move to the DRT_ACTIVE or /// DRT_ALONE state, depending on the success of the bootstrap. /// // https://docs.microsoft.com/en-us/windows/win32/api/drt/nf-drt-drtopen HRESULT DrtOpen( const DRT_SETTINGS *pSettings, HANDLE // hEvent, const PVOID pvContext, HDRT *phDrt ); [DllImport(Lib_Drt, SetLastError = false, ExactSpelling = true)] [PInvokeData("drt.h", MSDNShortId = "NF:drt.DrtOpen")] public static extern HRESULT DrtOpen(in DRT_SETTINGS pSettings, HANDLE hEvent, [In, Optional] IntPtr pvContext, out SafeHDRT phDrt); /// The DrtRegisterKey function registers a key in the DRT. /// A pointer to a handle returned by the DrtOpen function. /// A pointer to a handle to the DRT_REGISTRATION structure. /// /// Pointer to the context data associated with the key in the DRT. This data is passed to the key-specific functions of the /// security provider. /// /// Pointer to a handle for a key that has been registered. /// /// This function returns S_OK on success. Other possible values include: /// /// /// Return code /// Description /// /// /// E_INVALIDARG /// /// /// /// E_HANDLE /// hDrt is an invalid handle or phKeyRegistration is an invalid handle /// /// /// DRT_E_INVALID_KEY_SIZE /// /// The size of cb value of the key member of the DRT_REGISTRATION structure is not equal to 256 bits or the pb value of the key /// member of the DRT_REGISTRATION structure is NULL.. /// /// /// /// DRT_E_FAULTED /// The DRT cloud is in the faulted state. /// /// /// DRT_E_DUPLICATE_KEY /// The key is already registered. /// /// /// DRT_E_INVALID_CERT_CHAIN /// The provided certification chain is invalid. /// /// /// DRT_E_CAPABILITY_MISMATCH /// Supplied certificate provider is not AES capable. /// /// /// DRT_E_INVALID_KEY /// Supplied key does not match generated key. /// /// /// DRT_E_TRANSPORT_NO_DEST_ADDRESSES /// Valid address not found. /// /// /// DRT_E_TRANSPORT_SHUTTING_DOWN /// Transport is shutting down. /// /// /// DRT_E_INVALID_TRANSPORT_PROVIDER /// Transport provider is NULL. /// /// /// DRT_E_TRANSPORTPROVIDER_NOT_ATTACHED /// Transport is not attached. /// /// /// DRT_E_SECURITYPROVIDER_NOT_ATTACHED /// Security provider is not attached. /// /// /// DRT_E_TRANSPORT_NOT_BOUND /// Transport is not currently bound. /// /// /// E_OUTOFMEMORY /// The system is out of memory. /// /// /// E_UNEXPECTED /// /// /// /// E_FAIL /// An unexpected fatal error has occurred. /// /// /// /// NoteDrtRegisterKey may also surface errors from underlying calls to CryptGetProvParam, CertGetCertificateChain, /// CertOpenStore, CertAddCertificateContextToStore, CryptContextAddRef, CryptAcquireCertificatePrivateKey, CertSaveStore, WSAIoctl, /// CryptImportPublicKeyInfoEx2, NCryptSignHash, CertEnumCertificatesInStore, BCryptGetProperty, BCryptGenRandom, /// BCryptGenerateSymmetricKey and BCryptEncrypt. /// /// /// /// /// A node can register keys while in the DRT_ACTIVE, DRT_ALONE, or DRT_NO_NETWORK state. However, keys /// registered in DRT_ALONE and DRT_NO_NETWORK states can only be recognized by other DRTs after the local node has /// transitioned to DRT_ACTIVE. /// /// /// To update an existing key, an application must first deregister the key with DrtUnregisterKey before calling /// DrtRegisterKey to register the updated key. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/drt/nf-drt-drtregisterkey HRESULT DrtRegisterKey( HDRT hDrt, DRT_REGISTRATION // *pRegistration, PVOID pvKeyContext, HDRT_REGISTRATION_CONTEXT *phKeyRegistration ); [DllImport(Lib_Drt, SetLastError = false, ExactSpelling = true)] [PInvokeData("drt.h", MSDNShortId = "NF:drt.DrtRegisterKey")] public static extern HRESULT DrtRegisterKey(HDRT hDrt, in DRT_REGISTRATION pRegistration, [In, Optional] IntPtr pvKeyContext, out HDRT_REGISTRATION_CONTEXT phKeyRegistration); /// The DrtStartSearch function searches the DRT for a key using criteria specified in the DRT_SEARCH_INFO structure. /// The DRT handle returned by the DrtOpen function. /// Pointer to the DRT_DATA structure containing the key. /// Pointer to the DRT_SEARCH_INFO structure that specifies the properties of the search. /// Specifies the milliseconds until the search is stopped. /// /// Handle to the event that is signaled when the DrtStartSearch API finishes or an intermediate node is found. /// /// Pointer to the context data passed to the application through the event. /// Handle used in the call to DrtEndSearch. /// /// This function returns S_OK on success. Other possible values include: /// /// /// Return code /// Description /// /// /// E_HANDLE /// hDrt is an invalid handle or phKeyRegistration is an invalid handle /// /// /// E_INVALIDARG /// /// /// /// DRT_E_INVALID_KEY_SIZE /// /// /// /// DRT_E_INVALID_SEARCH_INFO /// pInfo was passed in but the dwSize of pInfo is not equal to size of the DRT_SEARCH_INFO structure. /// /// /// DRT_E_INVALID_MAX_ENDPOINTS /// /// pInfo was passed in but max endpoints (cMaxEndpoints) is set to 0 inside pInfo or pInfo was passed in but cMaxEndpoints is /// greater than 1 with fAnyMatchInRange set to TRUE /// /// /// /// DRT_E_INVALID_SEARCH_RANGE /// Min and max key values are equal, but target is different. /// /// /// DRT_E_FAULTED /// The DRT cloud is in the faulted state. /// /// /// E_OUTOFMEMORY /// The system is out of memory. /// /// /// E_UNEXPECTED /// The DRT is shutting down. /// /// /// E_FAIL /// An unexpected fatal error has occurred. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/drt/nf-drt-drtstartsearch HRESULT DrtStartSearch( HDRT hDrt, DRT_DATA *pKey, // const DRT_SEARCH_INFO *pInfo, ULONG timeout, HANDLE hEvent, const PVOID pvContext, HDRT_SEARCH_CONTEXT *hSearchContext ); [DllImport(Lib_Drt, SetLastError = false, ExactSpelling = true)] [PInvokeData("drt.h", MSDNShortId = "NF:drt.DrtStartSearch")] public static extern HRESULT DrtStartSearch(HDRT hDrt, in DRT_DATA pKey, in DRT_SEARCH_INFO pInfo, uint timeout, HEVENT hEvent, [In, Optional] IntPtr pvContext, out HDRT_SEARCH_CONTEXT hSearchContext); /// The DrtStartSearch function searches the DRT for a key using criteria specified in the DRT_SEARCH_INFO structure. /// The DRT handle returned by the DrtOpen function. /// Pointer to the DRT_DATA structure containing the key. /// Pointer to the DRT_SEARCH_INFO structure that specifies the properties of the search. /// Specifies the milliseconds until the search is stopped. /// /// Handle to the event that is signaled when the DrtStartSearch API finishes or an intermediate node is found. /// /// Pointer to the context data passed to the application through the event. /// Handle used in the call to DrtEndSearch. /// /// This function returns S_OK on success. Other possible values include: /// /// /// Return code /// Description /// /// /// E_HANDLE /// hDrt is an invalid handle or phKeyRegistration is an invalid handle /// /// /// E_INVALIDARG /// /// /// /// DRT_E_INVALID_KEY_SIZE /// /// /// /// DRT_E_INVALID_SEARCH_INFO /// pInfo was passed in but the dwSize of pInfo is not equal to size of the DRT_SEARCH_INFO structure. /// /// /// DRT_E_INVALID_MAX_ENDPOINTS /// /// pInfo was passed in but max endpoints (cMaxEndpoints) is set to 0 inside pInfo or pInfo was passed in but cMaxEndpoints is /// greater than 1 with fAnyMatchInRange set to TRUE /// /// /// /// DRT_E_INVALID_SEARCH_RANGE /// Min and max key values are equal, but target is different. /// /// /// DRT_E_FAULTED /// The DRT cloud is in the faulted state. /// /// /// E_OUTOFMEMORY /// The system is out of memory. /// /// /// E_UNEXPECTED /// The DRT is shutting down. /// /// /// E_FAIL /// An unexpected fatal error has occurred. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/drt/nf-drt-drtstartsearch HRESULT DrtStartSearch( HDRT hDrt, DRT_DATA *pKey, // const DRT_SEARCH_INFO *pInfo, ULONG timeout, HANDLE hEvent, const PVOID pvContext, HDRT_SEARCH_CONTEXT *hSearchContext ); [DllImport(Lib_Drt, SetLastError = false, ExactSpelling = true)] [PInvokeData("drt.h", MSDNShortId = "NF:drt.DrtStartSearch")] public static extern HRESULT DrtStartSearch(HDRT hDrt, in DRT_DATA pKey, [In, Optional] IntPtr pInfo, uint timeout, HEVENT hEvent, [In, Optional] IntPtr pvContext, out HDRT_SEARCH_CONTEXT hSearchContext); /// The DrtUnregisterKey function deregisters a key from the DRT. /// /// The DRT handle returned by the DrtRegisterKey function specifying a registered key within the DRT. /// /// None /// /// /// A node can deregister a key anytime after registration. Additionally, if an application calls DrtClose, all keys are /// deregistered by the DRT infrastructure. /// /// /// Only the application that registered they key may deregister it. An application can deregister a key from the local node. Upon /// completion the function triggers a DRT_EVENT_LEAFSET_KEY_CHANGE event; informing the application and other nodes /// participating in the DRT mesh of the deregistration. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/drt/nf-drt-drtunregisterkey void DrtUnregisterKey( HDRT_REGISTRATION_CONTEXT // hKeyRegistration ); [DllImport(Lib_Drt, SetLastError = false, ExactSpelling = true)] [PInvokeData("drt.h", MSDNShortId = "NF:drt.DrtUnregisterKey")] public static extern void DrtUnregisterKey(HDRT_REGISTRATION_CONTEXT hKeyRegistration); /// The DrtUpdateKey function updates the application data associated with a registered key. /// /// The DRT handle returned by the DrtRegisterKey function specifying a registered key within the DRT instance. /// /// The new application data to associate with the key. /// /// This function returns S_OK on success. Other possible values include: /// /// /// Return code /// Description /// /// /// E_INVALIDARG /// /// /// /// E_HANDLE /// hKeyRegistration is an invalid handle. /// /// /// E_OUTOFMEMORY /// The system is out of memory. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/drt/nf-drt-drtupdatekey HRESULT DrtUpdateKey( HDRT_REGISTRATION_CONTEXT // hKeyRegistration, DRT_DATA *pAppData ); [DllImport(Lib_Drt, SetLastError = false, ExactSpelling = true)] [PInvokeData("drt.h", MSDNShortId = "NF:drt.DrtUpdateKey")] public static extern HRESULT DrtUpdateKey(HDRT_REGISTRATION_CONTEXT hKeyRegistration, in DRT_DATA pAppData); /// /// The DRT_ADDRESS structure contains endpoint information about a DRT node that participated in a search. This information /// is intended for use in debugging connectivity problems. /// // https://docs.microsoft.com/en-us/windows/win32/api/drt/ns-drt-drt_address typedef struct _DRT_ADDRESS { SOCKADDR_STORAGE // socketAddress; ULONG flags; LONG nearness; ULONG latency; } DRT_ADDRESS, *PDRT_ADDRESS; [PInvokeData("drt.h", MSDNShortId = "NS:drt._DRT_ADDRESS")] [StructLayout(LayoutKind.Sequential)] public struct DRT_ADDRESS { /// Contains the endpoint on which the DRT protocol is listening on the remote node. public SOCKADDR_STORAGE socketAddress; /// Holds information explaining how this node behaved in the key lookup. public DRT_ADDRESS_FLAGS flags; /// /// Contains the number of bits that the key published by this node shares in common with the target key in the search. /// public int nearness; /// Round trip time to this node. public uint latency; } /// /// The DRT_ADDRESS_LIST structure contains a set of DRT_ADDRESS structures that represent the nodes contacted during a /// search for a key. /// // https://docs.microsoft.com/en-us/windows/win32/api/drt/ns-drt-drt_address_list typedef struct _DRT_ADDRESS_LIST { ULONG // AddressCount; DRT_ADDRESS AddressList[1]; } DRT_ADDRESS_LIST, *PDRT_ADDRESS_LIST; [PInvokeData("drt.h", MSDNShortId = "NS:drt._DRT_ADDRESS_LIST")] [VanaraMarshaler(typeof(SafeAnysizeStructMarshaler), nameof(AddressCount))] [StructLayout(LayoutKind.Sequential)] public struct DRT_ADDRESS_LIST { /// The count of entries in AddressList. public uint AddressCount; /// /// An array of DRT_ADDRESS structures that contain information about addresses that participated in the search operation. /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public DRT_ADDRESS[] AddressList; } /// /// The DRT_BOOTSTRAP_PROVIDER structure defines the DRT interface that must be implemented by a bootstrap provider. /// Note The DRT infrastructure does not call the methods of the bootstrap provider concurrently. /// // https://docs.microsoft.com/en-us/windows/win32/api/drt/ns-drt-drt_bootstrap_provider typedef struct drt_bootstrap_provider_tag { // PVOID pvContext; HRESULT( )(const PVOID pvContext) *Attach; VOID( )(const PVOID pvContext) *Detach; HRESULT((const PVOID // pvContext,BOOL fSplitDetect,ULONG timeout,ULONG cMaxResults,DRT_BOOTSTRAP_RESOLVE_CONTEXT *ResolveContext,BOOL *fFatalError) * // )InitResolve; HRESULT()(const PVOID pvContext, const PVOID pvCallbackContext,DRT_BOOTSTRAP_RESOLVE_CALLBACK // callback,DRT_BOOTSTRAP_RESOLVE_CONTEXT ResolveContext,BOOL *fFatalError) * IssueResolve; VOID( )(const PVOID // pvContext,DRT_BOOTSTRAP_RESOLVE_CONTEXT ResolveContext) // *EndResolve; HRESULT()(const PVOID pvContext, const SOCKET_ADDRESS_LIST *pAddressList) * Register; VOID( )(const PVOID pvContext) // *Unregister; } DRT_BOOTSTRAP_PROVIDER, *PDRT_BOOTSTRAP_PROVIDER; [PInvokeData("drt.h", MSDNShortId = "NS:drt.drt_bootstrap_provider_tag")] [StructLayout(LayoutKind.Sequential)] public struct DRT_BOOTSTRAP_PROVIDER { /// /// Pointer to context data that is defined by the bootstrap resolver. When creating a bootstrap resolver, the developer is /// required to populate the resolver with the required information; often times, this occurs as a "this" pointer. This context /// gets passed to all the context parameters in the functions defined by the DRT_BOOTSTRAP_PROVIDER. /// public IntPtr pvContext; /// Increments the count of references for the Bootstrap Provider with a set of DRTs. [MarshalAs(UnmanagedType.FunctionPtr)] public DRT_BOOTSTRAP_PROVIDER_Attach Attach; /// Decrements the count of references for the Bootstrap Provider with a set of DRTs. [MarshalAs(UnmanagedType.FunctionPtr)] public DRT_BOOTSTRAP_PROVIDER_Detach Detach; /// Called by the DRT infrastructure to supply configuration information about upcoming name resolutions. [MarshalAs(UnmanagedType.FunctionPtr)] public DRT_BOOTSTRAP_PROVIDER_InitResolve InitResolve; /// /// Called by the DRT infrastructure to issue a resolution to determine the endpoints of nodes already active in the DRT cloud. /// [MarshalAs(UnmanagedType.FunctionPtr)] public DRT_BOOTSTRAP_PROVIDER_IssueResolve IssueResolve; /// Ends the resolution of an endpoint. [MarshalAs(UnmanagedType.FunctionPtr)] public DRT_BOOTSTRAP_PROVIDER_EndResolve EndResolve; /// /// Registers an endpoint with the bootstrapping mechanism. This process makes it possible for other nodes find the endpoint via /// the bootstrap resolver. /// [MarshalAs(UnmanagedType.FunctionPtr)] public DRT_BOOTSTRAP_PROVIDER_Register Register; /// /// This function deregisters an endpoint with the bootstrapping mechanism. As a result, other nodes will be unable to find the /// local node via the bootstrap resolver. /// [MarshalAs(UnmanagedType.FunctionPtr)] public DRT_BOOTSTRAP_PROVIDER_Unregister Unregister; } /// Provides a handle to a DRT resolution. [StructLayout(LayoutKind.Sequential)] public struct DRT_BOOTSTRAP_RESOLVE_CONTEXT : IHandle { private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. public DRT_BOOTSTRAP_RESOLVE_CONTEXT(IntPtr preexistingHandle) => handle = preexistingHandle; /// Returns an invalid handle by instantiating a object with . public static DRT_BOOTSTRAP_RESOLVE_CONTEXT NULL => new(IntPtr.Zero); /// Gets a value indicating whether this instance is a null handle. public bool IsNull => handle == IntPtr.Zero; /// Performs an explicit conversion from to . /// The handle. /// The result of the conversion. public static explicit operator IntPtr(DRT_BOOTSTRAP_RESOLVE_CONTEXT h) => h.handle; /// Performs an implicit conversion from to . /// The pointer to a handle. /// The result of the conversion. public static implicit operator DRT_BOOTSTRAP_RESOLVE_CONTEXT(IntPtr h) => new(h); /// Implements the operator !=. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator !=(DRT_BOOTSTRAP_RESOLVE_CONTEXT h1, DRT_BOOTSTRAP_RESOLVE_CONTEXT h2) => !(h1 == h2); /// Implements the operator ==. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator ==(DRT_BOOTSTRAP_RESOLVE_CONTEXT h1, DRT_BOOTSTRAP_RESOLVE_CONTEXT h2) => h1.Equals(h2); /// public override bool Equals(object? obj) => obj is DRT_BOOTSTRAP_RESOLVE_CONTEXT h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); /// public IntPtr DangerousGetHandle() => handle; } /// The DRT_DATA structure contains a data blob. This structure is used by several DRT functions. // https://docs.microsoft.com/en-us/windows/win32/api/drt/ns-drt-drt_data typedef struct drt_data_tag { ULONG cb; BYTE *pb; } // DRT_DATA, *PDRT_DATA; [PInvokeData("drt.h", MSDNShortId = "NS:drt.drt_data_tag")] [StructLayout(LayoutKind.Sequential)] public struct DRT_DATA : IArrayStruct { /// The number of bytes. public uint cb; /// Pointer to a byte array that contains the common data. public IntPtr pb; /// Performs an implicit conversion from to []. /// The instance. /// The result of the conversion. public static implicit operator byte[]?(DRT_DATA d) => d.pb == IntPtr.Zero ? null : d.GetArray(); } /// /// The DRT_EVENT_DATA structure contains the event data returned by calling DrtGetEventData after an application receives an /// event signal on the hEvent passed into DrtOpen. /// // https://docs.microsoft.com/en-us/windows/win32/api/drt/ns-drt-drt_event_data typedef struct drt_event_data_tag { DRT_EVENT_TYPE // type; HRESULT hr; PVOID pvContext; union { struct { DRT_LEAFSET_KEY_CHANGE_TYPE change; DRT_DATA localKey; DRT_DATA remoteKey; } // leafsetKeyChange; struct { DRT_REGISTRATION_STATE state; DRT_DATA localKey; } registrationStateChange; struct { DRT_STATUS // status; struct { ULONG cntAddress; PSOCKADDR_STORAGE pAddresses; } bootstrapAddresses; } statusChange; }; } DRT_EVENT_DATA, *PDRT_EVENT_DATA; [PInvokeData("drt.h", MSDNShortId = "NS:drt.drt_event_data_tag")] [StructLayout(LayoutKind.Sequential)] public struct DRT_EVENT_DATA { /// A DRT_EVENT_TYPE enumeration that specifies the event type. public DRT_EVENT_TYPE type; /// /// The HRESULT of the operation for which the event was signaled that indicates if a result is the last result within a search. /// public HRESULT hr; /// /// Pointer to the context data passed to the API that generated the event. For example, if data is passed into the pvContext /// parameter of DrtOpen, that data is returned through this field. /// public IntPtr pvContext; /// public UNION union; /// [StructLayout(LayoutKind.Explicit)] public struct UNION { /// /// This structure appears when the event has been raised to signal a change in a leaf set of a locally registered key; the /// type field of the DRT_EVENT_DATA structure is set to DRT_EVENT_LEAFSET_KEY_CHANGED. /// [FieldOffset(0)] public LEAFSETKEYCHANGE leafsetKeyChange; /// /// This structure appears when the event has been raised to signal a change in a local key registration; the type field of /// the DRT_EVENT_DATA structure is set to DRT_EVENT_REGISTRATION_STATE_CHANGED. /// [FieldOffset(0)] public REGISTRATIONSTATECHANGE registrationStateChange; /// /// This structure appears when the event has been raised to signal a state change in the local DRT instance; the type field /// of the DRT_EVENT_DATA structure is set to DRT_EVENT_STATUS_CHANGED. /// [FieldOffset(0)] public STATUSCHANGE statusChange; /// /// This structure appears when the event has been raised to signal a change in a leaf set of a locally registered key; the /// type field of the DRT_EVENT_DATA structure is set to DRT_EVENT_LEAFSET_KEY_CHANGED. /// [StructLayout(LayoutKind.Sequential)] public struct LEAFSETKEYCHANGE { /// Specifies the type of key change that has occurred. public DRT_LEAFSET_KEY_CHANGE_TYPE change; /// Specifies the local key associated with the leaf set that has changed. public DRT_DATA localKey; /// Specifies the remote key that changed. public DRT_DATA remoteKey; } /// /// This structure appears when the event has been raised to signal a change in a local key registration; the type field of /// the DRT_EVENT_DATA structure is set to DRT_EVENT_REGISTRATION_STATE_CHANGED. /// [StructLayout(LayoutKind.Sequential)] public struct REGISTRATIONSTATECHANGE { /// Specifies the type of registration state change that has occurred. public DRT_REGISTRATION_STATE state; /// Specifies the local key associated with the registration that has changed. public DRT_DATA localKey; } /// /// This structure appears when the event has been raised to signal a state change in the local DRT instance; the type field /// of the DRT_EVENT_DATA structure is set to DRT_EVENT_STATUS_CHANGED. /// [StructLayout(LayoutKind.Sequential)] public struct STATUSCHANGE { /// Contains the current DRT_STATUS of the local DRT instance. public DRT_STATUS status; /// /// This structure contains the addresses returned by the bootstrap provider when the DRT attempts to join the mesh. This /// structure is completed only when the DRT transitions to the DRT_ALONE state. The contents of this structure can be /// used to diagnose connectivity issues between the local DRT instance and other nodes already present in the mesh. /// public BOOTSTRAPADDRESSES bootstrapAddresses; /// /// This structure contains the addresses returned by the bootstrap provider when the DRT attempts to join the mesh. This /// structure is completed only when the DRT transitions to the DRT_ALONE state. The contents of this structure can be /// used to diagnose connectivity issues between the local DRT instance and other nodes already present in the mesh. /// [StructLayout(LayoutKind.Sequential)] public struct BOOTSTRAPADDRESSES { /// Contains the number of addresses in pAddresses. public uint cntAddress; /// Contains an array of SOCKADDR_STORAGE addresses returned by the bootstrap provider. public IntPtr pAddresses; /// Gets the array of SOCKADDR_STORAGE addresses returned by the bootstrap provider. public SOCKADDR_STORAGE[] Addresses => pAddresses.ToArray((int)cntAddress) ?? new SOCKADDR_STORAGE[0]; } } } } /// The DRT_REGISTRATION structure contains key and application data that make up a registration. // https://docs.microsoft.com/en-us/windows/win32/api/drt/ns-drt-drt_registration typedef struct drt_registration_tag { DRT_DATA // key; DRT_DATA appData; } DRT_REGISTRATION, *PDRT_REGISTRATION; [PInvokeData("drt.h", MSDNShortId = "NS:drt.drt_registration_tag")] [StructLayout(LayoutKind.Sequential)] public struct DRT_REGISTRATION { /// Contains the key portion of the registration. public DRT_DATA key; /// /// The application data associated with the key. The DRT_DATA structure containing this application data must point to a buffer /// less than 4KB in size. /// public DRT_DATA appData; } /// The DRT_SEARCH_INFO structure represents a search query issued with DrtStartSearch. // https://docs.microsoft.com/en-us/windows/win32/api/drt/ns-drt-drt_search_info typedef struct drt_search_info_tag { DWORD dwSize; // BOOL fIterative; BOOL fAllowCurrentInstanceMatch; BOOL fAnyMatchInRange; ULONG cMaxEndpoints; DRT_DATA *pMaximumKey; DRT_DATA // *pMinimumKey; } DRT_SEARCH_INFO, *PDRT_SEARCH_INFO; [PInvokeData("drt.h", MSDNShortId = "NS:drt.drt_search_info_tag")] [StructLayout(LayoutKind.Sequential)] public struct DRT_SEARCH_INFO { /// Specifies the byte count of DRT_SEARCH_INFO. public uint dwSize; /// Indicates whether the search is iterative. If set to TRUE, the search is iterative. [MarshalAs(UnmanagedType.Bool)] public bool fIterative; /// /// Indicates whether search results can contain matches found in the local DRT instance. If set to TRUE, the search /// results are capable of containing matches found in the local DRT instance. /// [MarshalAs(UnmanagedType.Bool)] public bool fAllowCurrentInstanceMatch; /// /// If set to true, the search will stop locating the first key falling within the specified range. Otherwise, the search /// for the closest match to the target key specified by DrtStartSearch will continue. /// [MarshalAs(UnmanagedType.Bool)] public bool fAnyMatchInRange; /// /// Specifies the number of results to return. This includes closest and exact matches. If this value is greater than 1 when /// fIterative is TRUE, the search will only return 1 result. /// public uint cMaxEndpoints; /// Specifies the numerically largest key value the infrastructure should attempt to match. public IntPtr pMaximumKey; /// Specifies the numerically smallest key value the infrastructure should attempt to match. public IntPtr pMinimumKey; } /// /// The DRT_SEARCH_RESULT contains the registration entry and the type of match of the search result returned by /// DrtGetSearchResult when the hEvent passed into DrtStartSearch is signaled. /// // https://docs.microsoft.com/en-us/windows/win32/api/drt/ns-drt-drt_search_result typedef struct drt_search_result_tag { DWORD // dwSize; DRT_MATCH_TYPE type; PVOID pvContext; DRT_REGISTRATION registration; } DRT_SEARCH_RESULT, *PDRT_SEARCH_RESULT; [PInvokeData("drt.h", MSDNShortId = "NS:drt.drt_search_result_tag")] [StructLayout(LayoutKind.Sequential)] public struct DRT_SEARCH_RESULT { /// The size of the DRT_SEARCH_RESULT structure. public uint dwSize; /// Specifies the exactness of the search. This member corresponds to the DRT_MATCH_TYPE enumeration. public DRT_MATCH_TYPE type; /// Pointer to the context data passed to the DrtStartSearch API. public IntPtr pvContext; /// Contains the registration result. public DRT_REGISTRATION registration; } /// The DRT_SECURITY_PROVIDER structure defines the DRT interface that must be implemented by a security provider. // https://docs.microsoft.com/en-us/windows/win32/api/drt/ns-drt-drt_security_provider typedef struct drt_security_provider_tag { // PVOID pvContext; HRESULT( )(const PVOID pvContext) *Attach; VOID( )(const PVOID pvContext) *Detach; HRESULT()(const PVOID // pvContext, const DRT_REGISTRATION *pRegistration,PVOID pvKeyContext) * RegisterKey; HRESULT()(const PVOID pvContext, const // DRT_DATA *pKey,PVOID pvKeyContext) * UnregisterKey; HRESULT( pvContext,DRT_DATA *pSecuredAddressPayload,DRT_DATA // *pCertChain,DRT_DATA *pClassifier,DRT_DATA *pNonce,DRT_DATA *pSecuredPayload,BYTE *pbProtocolMajor,BYTE *pbProtocolMinor,DRT_DATA // *pKey,DRT_DATA *pPayload,CERT_PUBLIC_KEY_INFO **ppPublicKey,SOCKET_ADDRESS_LIST **ppAddressList,DWORD *pdwFlags) * )(const // PVOIDValidateAndUnpackPayload; HRESULT( PVOID pvContext,PVOID pvKeyContext,BYTE bProtocolMajor,BYTE bProtocolMinor,DWORD dwFlags, // const DRT_DATA *pKey, const DRT_DATA *pPayload, const SOCKET_ADDRESS_LIST *pAddressList, const DRT_DATA *pNonce,DRT_DATA // *pSecuredAddressPayload,DRT_DATA *pClassifier,DRT_DATA *pSecuredPayload,DRT_DATA *pCertChain) * )(constSecureAndPackPayload; // void( )(const PVOID pvContext,PVOID pv) *FreeData; HRESULT(onst PVOID pvContext, const DRT_DATA *pRemoteCredential,DWORD // dwBuffers,DRT_DATA *pDataBuffers,DRT_DATA *pEncryptedBuffers,DRT_DATA *pKeyToken) * )(cEncryptData; HRESULT((const PVOID // pvContext,DRT_DATA *pKeyToken, const PVOID pvKeyContext,DWORD dwBuffers,DRT_DATA *pData) * )DecryptData; HRESULT()(const PVOID // pvContext,DRT_DATA *pSelfCredential) * GetSerializedCredential; HRESULT()(const PVOID pvContext,DRT_DATA *pRemoteCredential) * // ValidateRemoteCredential; HRESULT(const PVOID pvContext,DWORD dwBuffers,DRT_DATA *pDataBuffers,DRT_DATA *pKeyIdentifier,DRT_DATA // *pSignature) * )(SignData; HRESULT(onst PVOID pvContext,DWORD dwBuffers,DRT_DATA *pDataBuffers,DRT_DATA // *pRemoteCredentials,DRT_DATA *pKeyIdentifier,DRT_DATA *pSignature) * )(cVerifyData; } DRT_SECURITY_PROVIDER, *PDRT_SECURITY_PROVIDER; [PInvokeData("drt.h", MSDNShortId = "NS:drt.drt_security_provider_tag")] [StructLayout(LayoutKind.Sequential)] public struct DRT_SECURITY_PROVIDER { /// /// /// This member is specified by the application when passing the DRT_SECURITY_PROVIDER structure to the DrtOpen function. /// /// /// The DRT treats it as an opaque pointer, and passes it as the first parameter to the functions referenced by this structure. /// An application will use this as a pointer to the security provider state or to the object that implements the security /// provider functionality. /// /// public IntPtr pvContext; /// Increments the count of references for the Security Provider with a set of DRTs. [MarshalAs(UnmanagedType.FunctionPtr)] public DRT_SECURITY_PROVIDER_Attach Attach; /// Decrements the count of references for the Security Provider with a set of DRTs. [MarshalAs(UnmanagedType.FunctionPtr)] public DRT_SECURITY_PROVIDER_Detach Detach; /// Called to register a key with the Security Provider. [MarshalAs(UnmanagedType.FunctionPtr)] public DRT_SECURITY_PROVIDER_RegisterKey RegisterKey; /// Called to deregister a key with the Security Provider. [MarshalAs(UnmanagedType.FunctionPtr)] public DRT_SECURITY_PROVIDER_UnregisterKey UnregisterKey; /// /// Called when an Authority message is received on the wire. It is responsible for validating the data received, and for /// unpacking the service addresses, revoked flag, and nonce from the Secured Address Payload. /// [MarshalAs(UnmanagedType.FunctionPtr)] public DRT_SECURITY_PROVIDER_ValidateAndUnpackPayload ValidateAndUnpackPayload; /// /// Called when an Authority message is about to be sent on the wire. It is responsible for securing the data before it is sent, /// and for packing the service addresses, revoked flag, nonce, and other application data into the Secured Address Payload. /// [MarshalAs(UnmanagedType.FunctionPtr)] public DRT_SECURITY_PROVIDER_SecureAndPackPayload SecureAndPackPayload; /// Called to release resources previously allocated for a security provider function. [MarshalAs(UnmanagedType.FunctionPtr)] public DRT_SECURITY_PROVIDER_FreeData FreeData; /// /// Called when the DRT sends a message containing data that must be encrypted. This function is only called when the DRT is /// operating in the DRT_SECURE_CONFIDENTIALPAYLOAD security mode defined by DRT_SECURITY_MODE. /// [MarshalAs(UnmanagedType.FunctionPtr)] public DRT_SECURITY_PROVIDER_EncryptData EncryptData; /// /// Called when the DRT receives a message containing encrypted data. This function is only called when the DRT is operating in /// the DRT_SECURE_CONFIDENTIALPAYLOAD security mode defined by DRT_SECURITY_MODE. /// [MarshalAs(UnmanagedType.FunctionPtr)] public DRT_SECURITY_PROVIDER_DecryptData DecryptData; /// /// Called when the DRT must provide a credential used to authorize the local node. This function is only called when the DRT is /// operating in the DRT_SECURE_MEMBERSHIP and DRT_SECURE_CONFIDENTIALPAYLOAD security modes defined by DRT_SECURITY_MODE. /// [MarshalAs(UnmanagedType.FunctionPtr)] public DRT_SECURITY_PROVIDER_GetSerializedCredential GetSerializedCredential; /// Called when the DRT must validate a credential provided by a peer node. [MarshalAs(UnmanagedType.FunctionPtr)] public DRT_SECURITY_PROVIDER_ValidateRemoteCredential ValidateRemoteCredential; /// /// Called when the DRT must sign a data blob for inclusion in a DRT protocol message. This function is only called when the DRT /// is operating in the DRT_SECURE_MEMBERSHIP and DRT_SECURE_CONFIDENTIALPAYLOAD security modes defined by DRT_SECURITY_MODE. /// [MarshalAs(UnmanagedType.FunctionPtr)] public DRT_SECURITY_PROVIDER_SignData SignData; /// /// Called when the DRT must verify a signature calculated over a block of data included in a DRT message. This function is only /// called when the DRT is operating in the DRT_SECURE_MEMBERSHIP and DRT_SECURE_CONFIDENTIALPAYLOAD security /// modes defined by DRT_SECURITY_MODE. /// [MarshalAs(UnmanagedType.FunctionPtr)] public DRT_SECURITY_PROVIDER_VerifyData VerifyData; } /// The DRT_SETTINGS structure contains the settings utilized by the local Distributed Routing Table. // https://docs.microsoft.com/en-us/windows/win32/api/drt/ns-drt-drt_settings typedef struct drt_settings_tag { DWORD dwSize; ULONG // cbKey; BYTE bProtocolMajorVersion; BYTE bProtocolMinorVersion; ULONG ulMaxRoutingAddresses; PWSTR pwzDrtInstancePrefix; // HDRT_TRANSPORT hTransport; DRT_SECURITY_PROVIDER *pSecurityProvider; DRT_BOOTSTRAP_PROVIDER *pBootstrapProvider; // DRT_SECURITY_MODE eSecurityMode; } DRT_SETTINGS, *PDRT_SETTINGS; [PInvokeData("drt.h", MSDNShortId = "NS:drt.drt_settings_tag")] [StructLayout(LayoutKind.Sequential)] public struct DRT_SETTINGS { /// /// The size of the structure specified by the sizeof parameter found in DRT_SETTINGS with the purpose of allowing new /// fields in the structure in future versions of the DRT API. /// public uint dwSize; /// /// Specifies the exact number of bytes for keys in this DRT instance. Currently only 8 bytes are supported. Any other values /// will return E_INVALIDARG via the DrtOpen function. /// public uint cbKey; /// /// Pointer to the byte array that represents the protocol major version specified by the application. This is packed in every /// DRT packet to identify the version of the Security or Bootstrap Providers in use when a single DRT instance is supporting /// multiple Security or Bootstrap Providers. /// public byte bProtocolMajorVersion; /// /// Pointer to the byte array that represents the protocol minor version specified by the application. This is packed in every /// DRT packet to identify the version of the Security or Bootstrap Providers in use when a single DRT instance is supporting /// multiple Security or Bootstrap Providers. /// public byte bProtocolMinorVersion; /// /// Specifies the maximum number of address the DRT registers when an application registers a key. The maximum value for this /// field is 4. /// public uint ulMaxRoutingAddresses; /// /// This string forms the basis of the name of the DRT instance. The name of the instance can be used to locate the Windows /// performance counters associated with it. /// [MarshalAs(UnmanagedType.LPWStr)] public string pwzDrtInstancePrefix; /// /// Handle to a transport created by the transport creation API. This is used to open a DRT with a transport specified by the /// DRT_SETTINGS structure. Currently only IPv6 UDP is supported via DrtCreateIpv6UdpTransport. /// public HDRT_TRANSPORT hTransport; /// /// Pointer to the security provider specified for use. An instance of the Derived Key Security Provider can be obtained by /// calling DrtCreateDerivedKeySecurityProvider. /// public IntPtr pSecurityProvider; /// public IntPtr pBootstrapProvider; /// /// Specifies the security mode that the DRT should operate under. All nodes participating in a DRT mesh must use the same /// security mode. /// public DRT_SECURITY_MODE eSecurityMode; } /// Provides a handle to a distributed routing table. [StructLayout(LayoutKind.Sequential)] public struct HDRT : IHandle { private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. public HDRT(IntPtr preexistingHandle) => handle = preexistingHandle; /// Returns an invalid handle by instantiating a object with . public static HDRT NULL => new(IntPtr.Zero); /// Gets a value indicating whether this instance is a null handle. public bool IsNull => handle == IntPtr.Zero; /// Performs an explicit conversion from to . /// The handle. /// The result of the conversion. public static explicit operator IntPtr(HDRT h) => h.handle; /// Performs an implicit conversion from to . /// The pointer to a handle. /// The result of the conversion. public static implicit operator HDRT(IntPtr h) => new(h); /// Implements the operator !=. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator !=(HDRT h1, HDRT h2) => !(h1 == h2); /// Implements the operator ==. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator ==(HDRT h1, HDRT h2) => h1.Equals(h2); /// public override bool Equals(object? obj) => obj is HDRT h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); /// public IntPtr DangerousGetHandle() => handle; } /// Provides a handle to a DRT registration context. [StructLayout(LayoutKind.Sequential)] public struct HDRT_REGISTRATION_CONTEXT : IHandle { private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. public HDRT_REGISTRATION_CONTEXT(IntPtr preexistingHandle) => handle = preexistingHandle; /// Returns an invalid handle by instantiating a object with . public static HDRT_REGISTRATION_CONTEXT NULL => new(IntPtr.Zero); /// Gets a value indicating whether this instance is a null handle. public bool IsNull => handle == IntPtr.Zero; /// Performs an explicit conversion from to . /// The handle. /// The result of the conversion. public static explicit operator IntPtr(HDRT_REGISTRATION_CONTEXT h) => h.handle; /// Performs an implicit conversion from to . /// The pointer to a handle. /// The result of the conversion. public static implicit operator HDRT_REGISTRATION_CONTEXT(IntPtr h) => new(h); /// Implements the operator !=. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator !=(HDRT_REGISTRATION_CONTEXT h1, HDRT_REGISTRATION_CONTEXT h2) => !(h1 == h2); /// Implements the operator ==. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator ==(HDRT_REGISTRATION_CONTEXT h1, HDRT_REGISTRATION_CONTEXT h2) => h1.Equals(h2); /// public override bool Equals(object? obj) => obj is HDRT_REGISTRATION_CONTEXT h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); /// public IntPtr DangerousGetHandle() => handle; } /// Provides a handle to a DRT search context. [StructLayout(LayoutKind.Sequential)] public struct HDRT_SEARCH_CONTEXT : IHandle { private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. public HDRT_SEARCH_CONTEXT(IntPtr preexistingHandle) => handle = preexistingHandle; /// Returns an invalid handle by instantiating a object with . public static HDRT_SEARCH_CONTEXT NULL => new(IntPtr.Zero); /// Gets a value indicating whether this instance is a null handle. public bool IsNull => handle == IntPtr.Zero; /// Performs an explicit conversion from to . /// The handle. /// The result of the conversion. public static explicit operator IntPtr(HDRT_SEARCH_CONTEXT h) => h.handle; /// Performs an implicit conversion from to . /// The pointer to a handle. /// The result of the conversion. public static implicit operator HDRT_SEARCH_CONTEXT(IntPtr h) => new(h); /// Implements the operator !=. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator !=(HDRT_SEARCH_CONTEXT h1, HDRT_SEARCH_CONTEXT h2) => !(h1 == h2); /// Implements the operator ==. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator ==(HDRT_SEARCH_CONTEXT h1, HDRT_SEARCH_CONTEXT h2) => h1.Equals(h2); /// public override bool Equals(object? obj) => obj is HDRT_SEARCH_CONTEXT h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); /// public IntPtr DangerousGetHandle() => handle; } /// Provides a handle to a DRT transport. [StructLayout(LayoutKind.Sequential)] public struct HDRT_TRANSPORT : IHandle { private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. public HDRT_TRANSPORT(IntPtr preexistingHandle) => handle = preexistingHandle; /// Returns an invalid handle by instantiating a object with . public static HDRT_TRANSPORT NULL => new(IntPtr.Zero); /// Gets a value indicating whether this instance is a null handle. public bool IsNull => handle == IntPtr.Zero; /// Performs an explicit conversion from to . /// The handle. /// The result of the conversion. public static explicit operator IntPtr(HDRT_TRANSPORT h) => h.handle; /// Performs an implicit conversion from to . /// The pointer to a handle. /// The result of the conversion. public static implicit operator HDRT_TRANSPORT(IntPtr h) => new(h); /// Implements the operator !=. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator !=(HDRT_TRANSPORT h1, HDRT_TRANSPORT h2) => !(h1 == h2); /// Implements the operator ==. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator ==(HDRT_TRANSPORT h1, HDRT_TRANSPORT h2) => h1.Equals(h2); /// public override bool Equals(object? obj) => obj is HDRT_TRANSPORT h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); /// public IntPtr DangerousGetHandle() => handle; } /// /// The DRT_DATA structure contains an arbitrary array of bytes. The structure definition includes aliases appropriate to the various /// functions that use it. /// [PInvokeData("wincrypt.h")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public class SafeDRT_DATA : SafeNativeArray { static readonly int HdrSize = Marshal.SizeOf(typeof(DRT_DATA)); /// Initializes a new instance of the class. /// The size, in bytes, to allocate. public SafeDRT_DATA(int size) : base(size, (uint)HdrSize) { } /// Initializes a new instance of the class. /// The bytes to copy into the blob. public SafeDRT_DATA(byte[] bytes) : base(bytes, (uint)HdrSize) { } /// Initializes a new instance of the class with a string. /// The string value. /// The character set to use. public SafeDRT_DATA(string value, CharSet charSet = CharSet.Ansi) : this(StringHelper.GetBytes(value, true, charSet)) { } /// A DWORD variable that contains the count, in bytes, of data. public int cb => base.Count; /// A pointer to the data buffer. public IntPtr pb => handle.Offset(HdrSize); /// Represents an empty instance of a blob. public static readonly SafeDRT_DATA Empty = new(0); /// Performs an implicit conversion from to . /// The safe data. /// The resulting instance from the conversion. public static implicit operator DRT_DATA(SafeDRT_DATA safeData) { safeData.UpdateHdr(); return safeData.handle.ToStructure(); } /// protected override void OnCountChanged() => UpdateHdr(); /// protected override void OnUpdateHeader() => UpdateHdr(); private void UpdateHdr() => handle.Write(new DRT_DATA() { cb = (uint)base.Count, pb = base.Count == 0 ? IntPtr.Zero : handle.Offset(HdrSize) }); } /// Provides a for that is disposed using . public class SafeHDRT : SafeHANDLE { /// Initializes a new instance of the class and assigns an existing handle. /// An object that represents the pre-existing handle to use. /// to reliably release the handle during the finalization phase; otherwise, (not recommended). public SafeHDRT(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { } /// Initializes a new instance of the class. private SafeHDRT() : base() { } /// Performs an implicit conversion from to . /// The safe handle instance. /// The result of the conversion. public static implicit operator HDRT(SafeHDRT h) => h.handle; /// protected override bool InternalReleaseHandle() { DrtClose(handle); return true; } } /// Provides a for that is disposed using . public class SafeHDRT_TRANSPORT : SafeHANDLE { /// Initializes a new instance of the class and assigns an existing handle. /// An object that represents the pre-existing handle to use. /// /// to reliably release the handle during the finalization phase; otherwise, (not recommended). /// public SafeHDRT_TRANSPORT(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { } /// Initializes a new instance of the class. private SafeHDRT_TRANSPORT() : base() { } /// Performs an implicit conversion from to . /// The safe handle instance. /// The result of the conversion. public static implicit operator HDRT_TRANSPORT(SafeHDRT_TRANSPORT h) => h.handle; /// protected override bool InternalReleaseHandle() => DrtDeleteIpv6UdpTransport(handle).Succeeded; } }