Example #1
0
 protected virtual void RegisterAckHandler(P2PAckMessageEventArgs e)
 {
     if (e.P2PMessage.Version == P2PVersion.P2PV2)
     {
         lock (ackHandlersV2)
         {
             e.P2PMessage.V2Header.OperationCode |= (byte)OperationCode.RAK;
             ackHandlersV2[e.P2PMessage.V2Header.Identifier + e.P2PMessage.Header.MessageSize] = e;
         }
     }
     else if (e.P2PMessage.Version == P2PVersion.P2PV1)
     {
         lock (ackHandlersV1)
         {
             ackHandlersV1[e.P2PMessage.V1Header.AckSessionId] = e;
         }
     }
 }
Example #2
0
 protected virtual void RegisterAckHandler(P2PAckMessageEventArgs e)
 {
     if (e.P2PMessage.Version == P2PVersion.P2PV2)
     {
         lock (ackHandlersV2)
         {
             e.P2PMessage.V2Header.OperationCode |= (byte)OperationCode.RAK;
             ackHandlersV2[e.P2PMessage.V2Header.Identifier + e.P2PMessage.Header.MessageSize] = e;
         }
     }
     else if (e.P2PMessage.Version == P2PVersion.P2PV1)
     {
         lock (ackHandlersV1)
         {
             ackHandlersV1[e.P2PMessage.V1Header.AckSessionId] = e;
         }
     }
 }
Example #3
0
        internal bool HandleACK(P2PMessage p2pMessage)
        {
            bool isAckOrNak = false;

            if (p2pMessage.Header.IsAcknowledgement || p2pMessage.Header.IsNegativeAck)
            {
                P2PAckMessageEventArgs e = null;
                uint ackNakId            = 0;
                isAckOrNak = true;

                if (p2pMessage.Version == P2PVersion.P2PV1)
                {
                    lock (ackHandlersV1)
                    {
                        if (ackHandlersV1.ContainsKey(p2pMessage.Header.AckIdentifier))
                        {
                            ackNakId = p2pMessage.Header.AckIdentifier;
                            e        = ackHandlersV1[ackNakId];
                            ackHandlersV1.Remove(ackNakId);
                        }
                    }
                }
                else if (p2pMessage.Version == P2PVersion.P2PV2)
                {
                    lock (ackHandlersV2)
                    {
                        if (ackHandlersV2.ContainsKey(p2pMessage.Header.AckIdentifier))
                        {
                            ackNakId = p2pMessage.Header.AckIdentifier;
                            e        = ackHandlersV2[ackNakId];
                            ackHandlersV2.Remove(ackNakId);
                        }
                        else if (ackHandlersV2.ContainsKey(p2pMessage.V2Header.NakIdentifier))
                        {
                            ackNakId = p2pMessage.V2Header.NakIdentifier;
                            e        = ackHandlersV2[ackNakId];
                            ackHandlersV2.Remove(ackNakId);
                        }
                    }
                }

                if (ackNakId == 0)
                {
                    Trace.WriteLineIf(Settings.TraceSwitch.TraceWarning,
                                      String.Format("!!!!!! No AckHandler registered for ack/nak {0}:\r\n{1}", p2pMessage.Header.AckIdentifier, p2pMessage.ToDebugString()), GetType().Name);
                }
                else
                {
                    if (e != null && e.AckHandler != null)
                    {
                        e.AckHandler(p2pMessage);
                    }
                    else
                    {
                        Trace.WriteLineIf(Settings.TraceSwitch.TraceWarning,
                                          String.Format("!!!!!! No AckHandler pair for ack {0}\r\n{1}", ackNakId, p2pMessage.ToDebugString()), GetType().Name);
                    }
                }
            }

            return(isAckOrNak);
        }