public void OnReceive(IConnectionChannel channel, IConnectionSession session, byte[] bytes) { var factory = channel.Factory; var dispatcher = channel.Dispatcher; string crid = null; try { var message = Encoding.UTF8.GetString(bytes); MessageLogger.LogDebug($"Received: {message}"); var isError = false; var wrapper = factory.DeserializeMessage(message, out crid, ref isError); if (isError) { return; } if (!dispatcher.Dispatch(session, wrapper, (r, rc) => channel.Send(session, new ResponseMessage(r, r.GetType().Name, crid, (byte)rc)))) { channel.SendError(session, crid); } } catch (Exception e) { channel.SendError(session, crid); Logger.Log("ConnectionService ex:", e); } }
/// <inheritdoc/> public virtual Task <IEnumerable <IExtension> > GetExtensions(IConnectionChannel connectionChannel) { List <IExtension> extensions = new List <IExtension>(new IExtension[] { new EightBitMimeExtension(), new SizeExtension(), new SmtpUtfEightExtension() }); if (this.sslCertificate != null) { extensions.Add(new StartTlsExtension()); } return(Task.FromResult <IEnumerable <IExtension> >(extensions)); }
/// <summary> /// Initializes a new instance of the <see cref="Connection"/> class. /// </summary> /// <param name="server">The server.</param> /// <param name="session">The session.</param> /// <param name="connectionChannel">The connection channel.</param> /// <param name="verbMap">The verb map.</param> /// <param name="extensionProcessors">The extension processors.</param> internal Connection(ISmtpServer server, IEditableSession session, IConnectionChannel connectionChannel, IVerbMap verbMap, Func <IConnection, IExtensionProcessor[]> extensionProcessors) { this.id = $"[RemoteIP={connectionChannel.ClientIPAddress}]"; this.ConnectionChannel = connectionChannel; this.ConnectionChannel.ClosedEventHandler += this.OnConnectionChannelClosed; this.VerbMap = verbMap; this.Session = session; this.Server = server; this.ExtensionProcessors = extensionProcessors(this).ToArray(); }
/// <summary> /// Creates the a connection for the specified server and channel.. /// </summary> /// <param name="server">The server.</param> /// <param name="connectionChannel">The connection channel.</param> /// <param name="verbMap">The verb map.</param> /// <returns>An <see cref="Task{T}"/> representing the async operation.</returns> internal static async Task <Connection> Create(ISmtpServer server, IConnectionChannel connectionChannel, IVerbMap verbMap) { IEditableSession session = await server.Behaviour.OnCreateNewSession(connectionChannel).ConfigureAwait(false); var extensions = await server.Behaviour.GetExtensions(connectionChannel).ConfigureAwait(false); IExtensionProcessor[] CreateConnectionExtensions(IConnection c) => extensions.Select(e => e.CreateExtensionProcessor(c)).ToArray(); Connection result = new Connection(server, session, connectionChannel, verbMap, CreateConnectionExtensions); return(result); }
public void SetBlockchainChannel(IConnectionChannel blockchain) { if (BlockchainChannel != null) { throw new Exception("Please call this only once !"); } if (blockchain.GetChannelByte() != BLOCKCHAIN_CHANNEL) { throw new Exception("Please set the right channel"); } BlockchainChannel = blockchain; }
public Connection(IServer server, IConnectionChannel connectionChannel, IVerbMap verbMap) { ConnectionChannel = connectionChannel; VerbMap = verbMap; Session = server.Behaviour.OnCreateNewSession(this, ConnectionChannel.ClientIPAddress, DateTime.Now); Server = server; ConnectionChannel.ReceiveTimeout = Server.Behaviour.GetReceiveTimeout(this); SetReaderEncodingToDefault(); ExtensionProcessors = Server.Behaviour.GetExtensions(this).Select(e => e.CreateExtensionProcessor(this)).ToArray(); }
public async Task <Application> GetApplication(ISender sender, IConnectionChannel connectionChannel, string ns) { var status = await CheckStatusAsync(sender); var application = status.Applications.First(a => a.Namespaces.Any(n => n.Name == ns)); if (!IsConnected) { await connectionChannel.ConnectAsync(sender, application.SessionId); IsConnected = true; } return(application); }
/// <inheritdoc/> public virtual Task <IEnumerable <IExtension> > GetExtensions(IConnectionChannel connectionChannel) { List <IExtension> extensions = new List <IExtension>(new IExtension[] { new EightBitMimeExtension(), new SizeExtension(), new SmtpUtfEightExtension() }); if (this.startTlsCertificate != null) { extensions.Add(new StartTlsExtension()); } if (this.AuthenticationCredentialsValidationRequiredEventHandler != null) { extensions.Add(new AuthExtension()); } return(Task.FromResult <IEnumerable <IExtension> >(extensions)); }
public Connection(IServer server, IConnectionChannel connectionChannel, IVerbMap verbMap) { _id = string.Format("[RemoteIP={0}]", connectionChannel.ClientIPAddress.ToString()); ConnectionChannel = connectionChannel; ConnectionChannel.Closed += OnConnectionChannelClosed; VerbMap = verbMap; Session = server.Behaviour.OnCreateNewSession(this, ConnectionChannel.ClientIPAddress, DateTime.Now); Server = server; ConnectionChannel.ReceiveTimeout = Server.Behaviour.GetReceiveTimeout(this); ConnectionChannel.SendTimeout = Server.Behaviour.GetSendTimeout(this); SetReaderEncodingToDefault(); ExtensionProcessors = Server.Behaviour.GetExtensions(this).Select(e => e.CreateExtensionProcessor(this)).ToArray(); }
public Player( ILogger logger, IReceiver receiver, string destinationId = AppConstants.DESTINATION_ID, string senderId = AppConstants.SENDER_ID, bool logToConsole = true, bool logTrace = false) { _logger = logger; _destinationId = destinationId; CanLogToConsole = logToConsole; CanLogTrace = logTrace; _sender = new Sender(_logger, senderId, receiver, HandleResponseMsg); _sender.Disconnected += OnDisconnect; _connectionChannel = new ConnectionChannel(destinationId); _heartbeatChannel = new HeartbeatChannel(destinationId); _mediaChannel = new MediaChannel(destinationId, async() => { var app = await _receiverChannel.GetApplication(_sender, _connectionChannel, _mediaChannel.Namespace); return(app.SessionId); }); _receiverChannel = new ReceiverChannel(destinationId); }
/// <inheritdoc/> public Task <IEditableSession> OnCreateNewSession(IConnectionChannel connection) { return(Task.FromResult <IEditableSession>(new MemorySession(connection.ClientIPAddress, DateTime.Now))); }
/// <inheritdoc/> public virtual Task <TimeSpan> GetSendTimeout(IConnectionChannel connectionChannel) { return(Task.FromResult(new TimeSpan(0, 0, 30))); }