123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- using System;
- using System.Collections.Generic;
- using System.Net;
- using System.Net.Sockets;
- using SMBLibrary.Authentication.GSSAPI;
- using SMBLibrary.NetBios;
- using Utilities;
- namespace SMBLibrary.Server
- {
- internal delegate void LogDelegate(Severity severity, string message);
- internal class ConnectionState
- {
- private Socket m_clientSocket;
- private IPEndPoint m_clientEndPoint;
- private NBTConnectionReceiveBuffer m_receiveBuffer;
- private BlockingQueue<SessionPacket> m_sendQueue;
- private DateTime m_creationDT;
- private DateTime m_lastReceiveDT;
- private Reference<DateTime> m_lastSendDTRef;
- private LogDelegate LogToServerHandler;
- public SMBDialect Dialect;
- public GSSContext AuthenticationContext;
- public ConnectionState(Socket clientSocket, IPEndPoint clientEndPoint, LogDelegate logToServerHandler)
- {
- m_clientSocket = clientSocket;
- m_clientEndPoint = clientEndPoint;
- m_receiveBuffer = new NBTConnectionReceiveBuffer();
- m_sendQueue = new BlockingQueue<SessionPacket>();
- m_creationDT = DateTime.UtcNow;
- m_lastReceiveDT = DateTime.UtcNow;
- m_lastSendDTRef = DateTime.UtcNow;
- LogToServerHandler = logToServerHandler;
- Dialect = SMBDialect.NotSet;
- }
- public ConnectionState(ConnectionState state)
- {
- m_clientSocket = state.ClientSocket;
- m_clientEndPoint = state.ClientEndPoint;
- m_receiveBuffer = state.ReceiveBuffer;
- m_sendQueue = state.SendQueue;
- m_creationDT = state.CreationDT;
- m_lastReceiveDT = state.LastReceiveDT;
- m_lastSendDTRef = state.LastSendDTRef;
- LogToServerHandler = state.LogToServerHandler;
- Dialect = state.Dialect;
- }
-
-
-
- public virtual void CloseSessions()
- {
- }
- public virtual List<SessionInformation> GetSessionsInformation()
- {
- return new List<SessionInformation>();
- }
- public void LogToServer(Severity severity, string message)
- {
- message = String.Format("[{0}] {1}", ConnectionIdentifier, message);
- if (LogToServerHandler != null)
- {
- LogToServerHandler(severity, message);
- }
- }
- public void LogToServer(Severity severity, string message, params object[] args)
- {
- LogToServer(severity, String.Format(message, args));
- }
- public Socket ClientSocket
- {
- get
- {
- return m_clientSocket;
- }
- }
- public IPEndPoint ClientEndPoint
- {
- get
- {
- return m_clientEndPoint;
- }
- }
- public NBTConnectionReceiveBuffer ReceiveBuffer
- {
- get
- {
- return m_receiveBuffer;
- }
- }
- public BlockingQueue<SessionPacket> SendQueue
- {
- get
- {
- return m_sendQueue;
- }
- }
- public DateTime CreationDT
- {
- get
- {
- return m_creationDT;
- }
- }
- public DateTime LastReceiveDT
- {
- get
- {
- return m_lastReceiveDT;
- }
- }
- public DateTime LastSendDT
- {
- get
- {
- return LastSendDTRef.Value;
- }
- }
- internal Reference<DateTime> LastSendDTRef
- {
- get
- {
- return m_lastSendDTRef;
- }
- }
- public void UpdateLastReceiveDT()
- {
- m_lastReceiveDT = DateTime.UtcNow;
- }
- public void UpdateLastSendDT()
- {
- m_lastSendDTRef.Value = DateTime.UtcNow;
- }
- public string ConnectionIdentifier
- {
- get
- {
- if (ClientEndPoint != null)
- {
- return ClientEndPoint.Address + ":" + ClientEndPoint.Port;
- }
- return String.Empty;
- }
- }
- }
- }
|