Пример #1
0
        /// <summary>
        /// Adds the or update peer relation.
        /// </summary>
        /// <param name="ownerPeer">The owner peer.</param>
        /// <param name="pairPeer">The pair peer.</param>
        /// <param name="connected">if set to <c>true</c> [connected].</param>
        /// <param name="stateId">The state id.</param>
        internal void AddOrUpdatePeerRelationForce(NetworkPeerRemote ownerPeer, NetworkPeerRemote pairPeer, bool connected, long stateId)
        {
            PeerRelationPair _pair = null;

            foreach (PeerRelationPair pair in mPeerRelationPairs)
            {
                if (pair.PeerA.Equals(ownerPeer) && pair.PeerB.Equals(pairPeer))
                {
                    if (pair.StateId < stateId)
                    {
                        pair.Connected = connected;
                        pair.StateId   = stateId;
                    }
                    _pair = pair;
                    break;
                }
            }

            if (_pair == null)
            {
                _pair = new PeerRelationPair(ownerPeer, pairPeer)
                {
                    Connected = connected, StateId = stateId
                };
                mPeerRelationPairs.Add(_pair);
                //this.mStateId++;
            }
        }
Пример #2
0
 /// <summary>
 /// Sets the connection offline.
 /// </summary>
 /// <param name="ownerPeer">The owner peer.</param>
 /// <param name="pairPeer">The pair peer.</param>
 internal void SetConnectionOffline(NetworkPeerRemote ownerPeer, NetworkPeerRemote pairPeer)
 {
     foreach (PeerRelationPair pair in mPeerRelationPairs)
     {
         if (pair.PeerA.Equals(ownerPeer) && pair.PeerB.Equals(pairPeer))
         {
             pair.Connected = false;
             mPeerRelationPairs.Remove(pair);
             break;
         }
     }
 }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PeerRelationPair"/> class.
 /// </summary>
 /// <param name="peerA">The peer A.</param>
 /// <param name="peerB">The peer B.</param>
 internal PeerRelationPair(NetworkPeerRemote peerA, NetworkPeerRemote peerB)
 {
     if (peerA == null)
     {
         ThrowHelper.ThrowArgumentNullException("peerA");
     }
     if (peerB == null)
     {
         ThrowHelper.ThrowArgumentNullException("peerB");
     }
     this.mPeerA = peerA;
     this.mPeerB = peerB;
 }
Пример #4
0
        /// <summary>
        /// Adds the or update peer relation.
        /// </summary>
        /// <param name="ownerPeer">The owner peer.</param>
        /// <param name="pairPeer">The pair peer.</param>
        /// <param name="connected">if set to <c>true</c> [connected].</param>
        /// <param name="changed">if set to <c>true</c> [changed].</param>
        /// <returns>PeerRelationPair</returns>
        internal PeerRelationPair AddOrUpdatePeerRelation(NetworkPeerRemote ownerPeer, NetworkPeerRemote pairPeer, bool connected, out bool changed)
        {
            changed = false;
            PeerRelationPair result = null;

            foreach (PeerRelationPair pair in mPeerRelationPairs)
            {
                if (pair.PeerA.Equals(ownerPeer) && pair.PeerB.Equals(pairPeer))
                {
                    if (pair.Connected != connected)
                    {
                        pair.Connected = connected;
                        pair.StateId   = pair.StateId + 1;
                        changed        = true;
                        if (LOGGER.IsDebugEnabled)
                        {
                            LOGGER.Debug(string.Format("PEER_RELATION, [{0}] relation changed with [{1}]. StateId: {2}, State: {3}", ownerPeer.Id, pairPeer.Id, pair.StateId, pair.Connected));
                        }
                    }
                    else
                    {
                        if (LOGGER.IsDebugEnabled)
                        {
                            LOGGER.Debug(string.Format("PEER_RELATION, [{0}] relation NOT changed with [{1}]. StateId: {2}, State: {3}", ownerPeer.Id, pairPeer.Id, pair.StateId, pair.Connected));
                        }
                    }
                    result = pair;
                    break;
                }
            }

            if (result == null)
            {
                result = new PeerRelationPair(ownerPeer, pairPeer)
                {
                    Connected = connected
                };
                mPeerRelationPairs.Add(result);
                changed = true;
                if (NetworkManager.Instance.InternalLocalhost.Id.Equals(ownerPeer.Id))
                {
                    // csak a saját azonosítómat szabad változtatni, másét nem!
                    this.mStateId++;
                    result.StateId = result.StateId + 1;
                }
            }

            return(result);
        }