Ejemplo n.º 1
0
 private bool CheckNeighbor(MessageVersion1 message)
 {
     return neighbors.Contains(new Neighbor { Identifier = message.PeerId });
 }
Ejemplo n.º 2
0
 public void AddMessageToBuffer(MessageVersion1 message)
 {
     if (BufferedMessages == null)
         BufferedMessages = new List<MessageVersion1>();
     BufferedMessages.Add(message);
 }
Ejemplo n.º 3
0
 private IEnumerable<MessageVersion1> ApplyMessageBuffer(MessageVersion1 message, out Neighbor neighbor)
 {
     neighbor = null;
     if (!CheckNeighbor(message)) return null;
     neighbor = neighbors.Single(n => n.Identifier.Equals(message.PeerId));
     if (message.PacketIndex <= neighbor.IncomingPacketIndex) return null;
     if (message.PacketIndex > neighbor.IncomingPacketIndex + 1)
     {
         lock (neighbor)
             neighbor.AddMessageToBuffer(message);
         return null;
     }
     lock (neighbor)
         if (neighbor.HasBufferedMessages)
         {
             neighbor.AddMessageToBuffer(message);
             neighbor.IncomingPacketIndex += (ulong)neighbor.BufferedMessages.Count;
             return neighbor.RemoveMessagesFromBuffer();
         }
         else
         {
             neighbor.IncomingPacketIndex++;
             return new[] { message };
         }
 }
Ejemplo n.º 4
0
 private bool VerifySignature(MessageVersion1 msgv1)
 {
     if (RsaKeyStore == null) return true;
     var rsa = new RSACryptoServiceProvider
         (RsaKeyStore.CspParameters ?? new CspParameters { Flags = CspProviderFlags.NoFlags });
     if (RsaKeyStore.CspParameters == null)
         rsa.ImportParameters(RsaKeyStore.RsaParameters);
     var signature = new byte[128];
     msgv1.Signature.CopyTo(signature, 0);
     Array.Clear(msgv1.Signature, 0, 128);
     var buffer = msgv1.Serialize();
     return rsa.VerifyData(buffer, new SHA1CryptoServiceProvider(), signature);
 }