Example #1
0
        public async Task RespondWithFailure(ResponseOrFailureCode responseCode)
        {
            ReceivedFromNeighborNullable?.AssertIsNotDisposed();

            var failure = new FailurePacket
            {
                ReqP2pSeq16  = ReqP2pSeq16,
                ResponseCode = responseCode,
            };

            var failureUdpData = failure.Encode_OpionallySignNeighborHMAC(ReceivedFromNeighborNullable);
            await _engine.OptionallySendUdpRequestAsync_Retransmit_WaitForNeighborPeerAck("RoutedRequest failure 123123", failureUdpData, ReceivedFromEndpoint,
                                                                                          failure.ReqP2pSeq16, ReceivedFromNeighborNullable, failure.GetSignedFieldsForNeighborHMAC);
        }
Example #2
0
 /// <summary>
 /// sends FAILURE or NPACK
 /// </summary>
 public async Task SendErrorResponse(ResponseOrFailureCode responseCode)
 {
     Logger.WriteToLog_higherLevelDetail($">> SendErrorResponse(responseCode={responseCode}) ReqP2pSeq16={ReqP2pSeq16}");
     if (ReceivedFromNeighborNullable?.IsDisposed == true)
     {
         return;
     }
     if (_repliedWithNPA)
     {
         // send FAILURE
         await RespondWithFailure(responseCode);
     }
     else
     {
         // send NPACK
         SendNeighborPeerAck(responseCode);
     }
 }
Example #3
0
        internal void SendNeighborPeerAck(ResponseOrFailureCode responseCode)
        {
            var npAck = new NeighborPeerAckPacket
            {
                ReqP2pSeq16  = ReqP2pSeq16,
                ResponseCode = responseCode
            };

            if (ReceivedFromNeighborNullable != null)
            {
                npAck.NeighborToken32 = ReceivedFromNeighborNullable.RemoteNeighborToken32;
                npAck.NeighborHMAC    = ReceivedFromNeighborNullable.GetNeighborHMAC(w => npAck.GetSignedFieldsForNeighborHMAC(w, GetSignedFieldsForNeighborHMAC));
            }

            var npAckUdpData = npAck.Encode(ReceivedFromNeighborNullable == null);

            _engine.RespondToRequestAndRetransmissions(RequestUdpPayloadData, npAckUdpData, ReceivedFromEndpoint);
            _repliedWithNPA = true;
        }
Example #4
0
        public NeighborPeerAckPacket(byte[] nextHopResponsePacketData)
        {
            var reader = PacketProcedures.CreateBinaryReader(nextHopResponsePacketData, 1);

            ReqP2pSeq16 = RequestP2pSequenceNumber16.Decode(reader);
            var flags = reader.ReadByte();

            if ((flags & FlagsMask_MustBeZero) != 0)
            {
                throw new NotImplementedException();
            }
            if ((flags & Flag_EPtoA) == 0)
            {
                NeighborToken32 = NeighborToken32.Decode(reader);
            }
            ResponseCode = (ResponseOrFailureCode)reader.ReadByte();
            if ((flags & Flag_EPtoA) == 0)
            {
                NeighborHMAC = HMAC.Decode(reader);
            }
        }
Example #5
0
 public RequestRejectedException(ResponseOrFailureCode responseCode)
     : base($"Request was rejected with status = {responseCode}")
 {
     ResponseCode = responseCode;
 }