IAppServer.cs 6.4 KB

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