IAppServer.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Net.Security;
  6. using System.Security.Authentication;
  7. using System.Security.Cryptography.X509Certificates;
  8. using System.Text;
  9. using SuperSocket.Common;
  10. using SuperSocket.SocketBase.Command;
  11. using SuperSocket.SocketBase.Config;
  12. using SuperSocket.SocketBase.Logging;
  13. using SuperSocket.SocketBase.Protocol;
  14. using SuperSocket.SocketBase.Provider;
  15. namespace SuperSocket.SocketBase
  16. {
  17. /// <summary>
  18. /// The interface for AppServer
  19. /// </summary>
  20. public interface IAppServer : IWorkItem, ILoggerProvider
  21. {
  22. /// <summary>
  23. /// Gets the started time.
  24. /// </summary>
  25. /// <value>
  26. /// The started time.
  27. /// </value>
  28. DateTime StartedTime { get; }
  29. /// <summary>
  30. /// Gets or sets the listeners.
  31. /// </summary>
  32. /// <value>
  33. /// The listeners.
  34. /// </value>
  35. ListenerInfo[] Listeners { get; }
  36. /// <summary>
  37. /// Gets the Receive filter factory.
  38. /// </summary>
  39. object ReceiveFilterFactory { get; }
  40. /// <summary>
  41. /// Gets the certificate of current server.
  42. /// </summary>
  43. X509Certificate Certificate { get; }
  44. /// <summary>
  45. /// Gets the transfer layer security protocol.
  46. /// </summary>
  47. SslProtocols BasicSecurity { get; }
  48. /// <summary>
  49. /// Creates the app session.
  50. /// </summary>
  51. /// <param name="socketSession">The socket session.</param>
  52. /// <returns></returns>
  53. IAppSession CreateAppSession(ISocketSession socketSession);
  54. /// <summary>
  55. /// Registers the new created app session into the appserver's session container.
  56. /// </summary>
  57. /// <param name="session">The session.</param>
  58. /// <returns></returns>
  59. bool RegisterSession(IAppSession session);
  60. /// <summary>
  61. /// Gets the app session by ID.
  62. /// </summary>
  63. /// <param name="sessionID">The session ID.</param>
  64. /// <returns></returns>
  65. IAppSession GetSessionByID(string sessionID);
  66. /// <summary>
  67. /// Resets the session's security protocol.
  68. /// </summary>
  69. /// <param name="session">The session.</param>
  70. /// <param name="security">The security protocol.</param>
  71. void ResetSessionSecurity(IAppSession session, SslProtocols security);
  72. /// <summary>
  73. /// Gets the log factory.
  74. /// </summary>
  75. ILogFactory LogFactory { get; }
  76. }
  77. /// <summary>
  78. /// The raw data processor
  79. /// </summary>
  80. /// <typeparam name="TAppSession">The type of the app session.</typeparam>
  81. public interface IRawDataProcessor<TAppSession>
  82. where TAppSession : IAppSession
  83. {
  84. /// <summary>
  85. /// Gets or sets the raw binary data received event handler.
  86. /// TAppSession: session
  87. /// byte[]: receive buffer
  88. /// int: receive buffer offset
  89. /// int: receive lenght
  90. /// bool: whether process the received data further
  91. /// </summary>
  92. event Func<TAppSession, byte[], int, int, bool> RawDataReceived;
  93. }
  94. /// <summary>
  95. /// The interface for AppServer
  96. /// </summary>
  97. /// <typeparam name="TAppSession">The type of the app session.</typeparam>
  98. public interface IAppServer<TAppSession> : IAppServer
  99. where TAppSession : IAppSession
  100. {
  101. /// <summary>
  102. /// Gets the matched sessions from sessions snapshot.
  103. /// </summary>
  104. /// <param name="critera">The prediction critera.</param>
  105. /// <returns></returns>
  106. IEnumerable<TAppSession> GetSessions(Func<TAppSession, bool> critera);
  107. /// <summary>
  108. /// Gets all sessions in sessions snapshot.
  109. /// </summary>
  110. /// <returns></returns>
  111. IEnumerable<TAppSession> GetAllSessions();
  112. /// <summary>
  113. /// Gets/sets the new session connected event handler.
  114. /// </summary>
  115. event SessionHandler<TAppSession> NewSessionConnected;
  116. /// <summary>
  117. /// Gets/sets the session closed event handler.
  118. /// </summary>
  119. event SessionHandler<TAppSession, CloseReason> SessionClosed;
  120. }
  121. /// <summary>
  122. /// The interface for AppServer
  123. /// </summary>
  124. /// <typeparam name="TAppSession">The type of the app session.</typeparam>
  125. /// <typeparam name="TRequestInfo">The type of the request info.</typeparam>
  126. public interface IAppServer<TAppSession, TRequestInfo> : IAppServer<TAppSession>
  127. where TRequestInfo : IRequestInfo
  128. where TAppSession : IAppSession, IAppSession<TAppSession, TRequestInfo>, new()
  129. {
  130. /// <summary>
  131. /// Occurs when [request comming].
  132. /// </summary>
  133. event RequestHandler<TAppSession, TRequestInfo> NewRequestReceived;
  134. }
  135. /// <summary>
  136. /// The interface for handler of session request
  137. /// </summary>
  138. /// <typeparam name="TRequestInfo">The type of the request info.</typeparam>
  139. public interface IRequestHandler<TRequestInfo>
  140. where TRequestInfo : IRequestInfo
  141. {
  142. /// <summary>
  143. /// Executes the command.
  144. /// </summary>
  145. /// <param name="session">The session.</param>
  146. /// <param name="requestInfo">The request info.</param>
  147. void ExecuteCommand(IAppSession session, TRequestInfo requestInfo);
  148. }
  149. /// <summary>
  150. /// SocketServer Accessor interface
  151. /// </summary>
  152. public interface ISocketServerAccessor
  153. {
  154. /// <summary>
  155. /// Gets the socket server.
  156. /// </summary>
  157. /// <value>
  158. /// The socket server.
  159. /// </value>
  160. ISocketServer SocketServer { get; }
  161. }
  162. /// <summary>
  163. /// The basic interface for RemoteCertificateValidator
  164. /// </summary>
  165. public interface IRemoteCertificateValidator
  166. {
  167. /// <summary>
  168. /// Validates the remote certificate
  169. /// </summary>
  170. /// <param name="session">The session.</param>
  171. /// <param name="sender">The sender.</param>
  172. /// <param name="certificate">The certificate.</param>
  173. /// <param name="chain">The chain.</param>
  174. /// <param name="sslPolicyErrors">The SSL policy errors.</param>
  175. /// <returns></returns>
  176. bool Validate(IAppSession session, object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors);
  177. }
  178. }