Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

248 lines
6.1 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 2000, Microsoft Corporation
  4. //
  5. // File: DfsReferralData.hxx
  6. //
  7. // Contents: the DFS Referral dataclass
  8. //
  9. // Classes: DfsReferralData
  10. //
  11. // History: Dec. 8 2000, Author: udayh
  12. //
  13. //-----------------------------------------------------------------------------
  14. #ifndef __DFS_REFERRAL_DATA__
  15. #define __DFS_REFERRAL_DATA__
  16. #include "DfsGeneric.hxx"
  17. #include "DfsReplica.hxx"
  18. class DfsSite;
  19. class DfsGenericSiteNameSupport;
  20. //+----------------------------------------------------------------------------
  21. //
  22. // Class: DfsReferralData
  23. //
  24. // Synopsis: This class implements the DfsReferralData class
  25. //
  26. //-----------------------------------------------------------------------------
  27. #define MAX_DFS_REFERRAL_LOAD_WAIT 2400000 // 4 minutes.
  28. #define MIN_SITE_COST_HASH_BUCKETS 4L
  29. #define MAX_SITE_COST_HASH_BUCKETS 512L
  30. //
  31. // This is the max number of DS API errors that we'll tolerate before giving up.
  32. //
  33. #define DS_ERROR_THRESHOLD 3
  34. #define DFS_ROOT_REFERRAL 0x1
  35. class DfsReferralData: public DfsGeneric
  36. {
  37. private:
  38. HANDLE _WaitHandle; // Event on which threads wait
  39. ULONG _TickCount; // Last use tick count.
  40. ULONG _NumDsErrors; // Number of consecutive errors received from DS APIs.
  41. DFSSTATUS _LastDsError; // Last error received when the timer was started
  42. protected:
  43. ULONG _Flags; // Flags
  44. public:
  45. ULONG ReplicaCount; // how many replicas?
  46. DfsReplica *pReplicas; // list of replicas.
  47. DFSSTATUS LoadStatus; // Status of load.
  48. ULONG Timeout;
  49. BOOLEAN InSite;
  50. BOOLEAN DoSiteCosting; // Order referrals based on inter-site costs we get from the DS.
  51. BOOLEAN OutOfDomain;
  52. BOOLEAN FolderOffLine;
  53. // PolicyList: this may be something we want to add when we
  54. // implement policies.
  55. public:
  56. //
  57. // Function DfsReferralData: Constructor for this class.
  58. // Creates the event on which other threads should wait while load is
  59. // in progress.
  60. //
  61. DfsReferralData( DFSSTATUS *pStatus, DfsObjectTypeEnumeration Type = DFS_OBJECT_TYPE_REFERRAL_DATA) :
  62. DfsGeneric(Type)
  63. {
  64. pReplicas = NULL;
  65. ReplicaCount = 0;
  66. LoadStatus = STATUS_SUCCESS;
  67. _Flags = 0;
  68. InSite = FALSE;
  69. DoSiteCosting = FALSE;
  70. OutOfDomain = FALSE;
  71. FolderOffLine = FALSE;
  72. _NumDsErrors = 0;
  73. _LastDsError = ERROR_SUCCESS;
  74. *pStatus = ERROR_SUCCESS;
  75. //
  76. // create an event that we will be set and reset manually,
  77. // with an initial state set to false (event is not signalled)
  78. //
  79. _WaitHandle = CreateEvent( NULL, //must be null.
  80. TRUE, // manual reset
  81. FALSE, // initial state
  82. NULL ); // event not named
  83. if ( _WaitHandle == NULL )
  84. {
  85. *pStatus = ERROR_NOT_ENOUGH_MEMORY;
  86. }
  87. }
  88. //
  89. // Function ~DfsReferralData: Destructor.
  90. //
  91. ~DfsReferralData()
  92. {
  93. //
  94. // note that if any of our derived classes do their own
  95. // destructor processing of preplicas, they should set it to
  96. // null, to avoid double frees.
  97. // The FolderReferralData does this.
  98. //
  99. if (pReplicas != NULL)
  100. {
  101. delete [] pReplicas;
  102. }
  103. if ( _WaitHandle != NULL )
  104. {
  105. CloseHandle(_WaitHandle);
  106. }
  107. }
  108. DFSSTATUS
  109. GenerateCostMatrix(
  110. DfsSite *pReferralSite);
  111. //
  112. // Function Wait: This function waits on the event to be signalled.
  113. // If the load state indicates load is in progress, the thread calls
  114. // wait, to wait for the load to complete.
  115. // When the load is complete, the thread that is doing the load calls
  116. // signal to signal the event so that all waiting threads are
  117. // unblocked.
  118. // We set a max wait to prevent some thread from blocking for ever.
  119. //
  120. DFSSTATUS
  121. Wait()
  122. {
  123. DFSSTATUS Status;
  124. Status = WaitForSingleObject( _WaitHandle,
  125. MAX_DFS_REFERRAL_LOAD_WAIT );
  126. if ( Status == ERROR_SUCCESS )
  127. {
  128. Status = LoadStatus;
  129. }
  130. return Status;
  131. }
  132. //
  133. // Function Signal: Set the event to a signalled state so that
  134. // all waiting threads will be woken up.
  135. //
  136. VOID
  137. Signal()
  138. {
  139. SetEvent( _WaitHandle );
  140. }
  141. VOID
  142. SetInSite()
  143. {
  144. InSite = TRUE;
  145. }
  146. VOID
  147. SetSiteCosting()
  148. {
  149. DoSiteCosting = TRUE;
  150. }
  151. BOOLEAN
  152. IsRestrictToSite()
  153. {
  154. return InSite;
  155. }
  156. BOOLEAN
  157. SiteCostingEnabled()
  158. {
  159. return DoSiteCosting;
  160. }
  161. VOID
  162. SetOutOfDomain()
  163. {
  164. OutOfDomain = TRUE;
  165. }
  166. BOOLEAN
  167. IsOutOfDomain()
  168. {
  169. return OutOfDomain;
  170. }
  171. VOID
  172. SetTime()
  173. {
  174. _TickCount = GetTickCount();
  175. }
  176. BOOLEAN
  177. TimeToRefresh()
  178. {
  179. ULONG CurrentTime = GetTickCount();
  180. if (CurrentTime - _TickCount > DfsServerGlobalData.RootReferralRefreshInterval)
  181. {
  182. return TRUE;
  183. }
  184. else
  185. {
  186. return FALSE;
  187. }
  188. }
  189. private:
  190. DFSSTATUS
  191. PopulateTransientTable(
  192. PUNICODE_STRING pSiteName,
  193. DfsSiteNameSupport *pTransientSiteTable);
  194. DFSSTATUS
  195. CreateUniqueSiteArray(
  196. PUNICODE_STRING pSiteName,
  197. LPWSTR **ppSiteNameArray,
  198. DfsSite ***ppDfsSiteArray,
  199. PULONG pNumUniqueSites);
  200. VOID
  201. DeleteUniqueSiteArray(
  202. LPBYTE pSiteArray);
  203. };
  204. #endif // __DFS_REFERRAL_DATA__