Exemplo n.º 1
0
Arquivo: Peer.cs Projeto: wyk125/AElf
        /// <summary>
        /// This method sends authentification information to the distant peer and
        /// start the authentification timer.
        /// </summary>
        /// <returns></returns>
        private void StartAuthentification()
        {
            var nodeInfo = new NodeData {
                Port = _port
            };

            ECSigner    signer = new ECSigner();
            ECSignature sig    = signer.Sign(_nodeKey, nodeInfo.ToByteArray());

            var nd = new Handshake
            {
                NodeInfo  = nodeInfo,
                PublicKey = ByteString.CopyFrom(_nodeKey.GetEncodedPublicKey()),
                Height    = CurrentHeight,
                Version   = GlobalConfig.ProtocolVersion,
                R         = ByteString.CopyFrom(sig.R),
                S         = ByteString.CopyFrom(sig.S)
            };

            byte[] packet = nd.ToByteArray();

            _logger?.Trace($"Sending authentification : {{ port: {nd.NodeInfo.Port}, addr: {nd.PublicKey.ToByteArray().ToHex()} }}");

            _messageWriter.EnqueueMessage(new Message {
                Type = (int)MessageType.Auth, HasId = false, Length = packet.Length, Payload = packet
            });

            StartAuthTimer();
        }