Exemplo n.º 1
0
        public static ProtocolMessage ToSignedProtocolMessage(this IMessage proto,
                                                              PeerId senderId  = default,
                                                              byte[] signature = default,
                                                              SigningContext signingContext = default,
                                                              ICorrelationId correlationId  = default)
        {
            var peerId          = senderId ?? PeerIdHelper.GetPeerId("sender");
            var protocolMessage = proto.ToProtocolMessage(peerId,
                                                          correlationId ?? CorrelationId.GenerateCorrelationId());
            var newSignature = SignatureHelper.GetSignature(signature, signingContext);

            protocolMessage.Signature = newSignature;

            return(protocolMessage);
        }
Exemplo n.º 2
0
        protected override PeerNeighborsResponse HandleRequest(PeerNeighborsRequest messageDto,
                                                               IChannelHandlerContext channelHandlerContext,
                                                               PeerId senderPeerId,
                                                               ICorrelationId correlationId)
        {
            var count = Interlocked.Increment(ref _counter);

            if (count % 2 == 0)
            {
                throw new ArgumentException("something went wrong handling the request");
            }

            return(new PeerNeighborsResponse {
                Peers = { PeerIdHelper.GetPeerId() }
            });
        }
Exemplo n.º 3
0
        public static CandidateDeltaBroadcast GetCandidateDelta(IHashProvider hashProvider,
                                                                MultiHash previousDeltaHash = null,
                                                                MultiHash hash    = null,
                                                                PeerId producerId = null)
        {
            var candidateHash = hash ?? hashProvider.ComputeMultiHash(ByteUtil.GenerateRandomByteArray(32));
            var previousHash  = previousDeltaHash ?? hashProvider.ComputeMultiHash(ByteUtil.GenerateRandomByteArray(32));
            var producer      = producerId
                                ?? PeerIdHelper.GetPeerId(publicKey: ByteUtil.GenerateRandomByteArray(32));

            return(new CandidateDeltaBroadcast
            {
                Hash = candidateHash.ToArray().ToByteString(),
                PreviousDeltaDfsHash = previousHash.ToArray().ToByteString(),
                ProducerId = producer
            });
        }
Exemplo n.º 4
0
        public static CandidateDeltaBroadcast GetCandidateDelta(IHashProvider hashProvider,
                                                                Cid previousDeltaHash = null,
                                                                Cid hash          = null,
                                                                PeerId producerId = null)
        {
            var candidateHash = hash ??
                                hashProvider.ComputeMultiHash(ByteUtil.GenerateRandomByteArray(32)).CreateCid();
            var previousHash = previousDeltaHash ??
                               hashProvider.ComputeMultiHash(ByteUtil.GenerateRandomByteArray(32)).CreateCid();
            var producer = producerId
                           ?? PeerIdHelper.GetPeerId(ByteUtil.GenerateRandomByteArray(32));

            return(new CandidateDeltaBroadcast
            {
                Hash = MultiBase.Decode(candidateHash).ToByteString(),
                PreviousDeltaDfsHash = MultiBase.Decode(previousHash).ToByteString(),
                ProducerId = producer
            });
        }
Exemplo n.º 5
0
 public static IDictionary <PeerId, ICorrelationId> SubContactedNeighbours(int amount = 5)
 {
     return(Enumerable.Range(0, amount)
            .Select(i => PeerIdHelper.GetPeerId())
            .ToDictionary(v => v, k => Substitute.For <ICorrelationId>()));
 }
Exemplo n.º 6
0
 public TestMessageObserver(ILogger logger) : base(logger, typeof(TProto).ShortenedProtoFullName())
 {
     SubstituteObserver = Substitute.For <IObserver <TProto> >();
     PeerId             = PeerIdHelper.GetPeerId();
 }