public override async void ChannelActive(IChannelHandlerContext context)
        {
            var hostId  = _server.Configuration.HostIdFactory.New();
            var session = _server.Configuration.SessionFactory.Create(hostId, context.Channel, _server);

            context.Channel.GetAttribute(ChannelAttributes.Session).Set(session);

            var log = _server.Configuration.Logger?
                      .ForContext("HostId", hostId)
                      .ForContext("EndPoint", context.Channel.RemoteAddress.ToString());

            log?.Debug("New incoming client({HostId}) on {EndPoint}");

            var config = new NetConfigDto
            {
                EnableServerLog                    = _server.Configuration.EnableServerLog,
                FallbackMethod                     = _server.Configuration.FallbackMethod,
                MessageMaxLength                   = _server.Configuration.MessageMaxLength,
                TimeoutTimeMs                      = _server.Configuration.IdleTimeout.TotalMilliseconds,
                DirectP2PStartCondition            = _server.Configuration.DirectP2PStartCondition,
                OverSendSuspectingThresholdInBytes = _server.Configuration.OverSendSuspectingThresholdInBytes,
                EnableNagleAlgorithm               = _server.Configuration.EnableNagleAlgorithm,
                EncryptedMessageKeyLength          = _server.Configuration.EncryptedMessageKeyLength,
                AllowServerAsP2PGroupMember        = _server.Configuration.AllowServerAsP2PGroupMember,
                EnableP2PEncryptedMessaging        = _server.Configuration.EnableP2PEncryptedMessaging,
                UpnpDetectNatDevice                = _server.Configuration.UpnpDetectNatDevice,
                UpnpTcpAddrPortMapping             = _server.Configuration.UpnpTcpAddrPortMapping,
                EnablePingTest                     = _server.Configuration.EnablePingTest,
                EmergencyLogLineCount              = _server.Configuration.EmergencyLogLineCount
            };
            await session.SendAsync(new NotifyServerConnectionHintMessage(config, _server.Rsa.ExportParameters(false)));

            using (var cts = new CancellationTokenSource(_server.Configuration.ConnectTimeout))
            {
                try
                {
                    await session.HandhsakeEvent.WaitAsync(cts.Token);
                }
                catch (OperationCanceledException)
                {
                    if (!session.IsConnected)
                    {
                        return;
                    }

                    log?.Debug("Client({HostId}) handshake timeout");
                    await session.SendAsync(new ConnectServerTimedoutMessage());

                    await session.CloseAsync();

                    return;
                }
            }

            base.ChannelActive(context);
        }
Example #2
0
 public NotifyServerConnectionHintMessage(NetConfigDto config, RSAParameters publicKey)
 {
     Config    = config;
     PublicKey = publicKey;
 }
Example #3
0
 public NotifyServerConnectionHintMessage()
 {
     Config    = new NetConfigDto();
     PublicKey = new RSAParameters();
 }
Example #4
0
 public NotifyServerConnectionHintMessage(NetConfigDto config)
 {
     Config = config;
 }
Example #5
0
 public NotifyServerConnectionHintMessage()
 {
     Config = new NetConfigDto();
 }