Exemplo n.º 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++;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Builds the peer relation container.
        /// </summary>
        /// <returns>PeerRelationContainer</returns>
        internal PeerRelationContainer BuildPeerRelationContainer(bool blackHole, string targetNetworkContext)
        {
            PeerRelationContainer container = new PeerRelationContainer();

            container.StateId = mStateId;
            if (!blackHole)
            {
                List <PeerRelationPair> allowedPairs = new List <PeerRelationPair>();
                foreach (PeerRelationPair pair in mPeerRelationPairs)
                {
                    if (NetworkManager.Instance.NetworkContextRuleManager.CheckSeparation(pair.PeerA.NetworkContext.Name, targetNetworkContext) &&
                        NetworkManager.Instance.NetworkContextRuleManager.CheckSeparation(pair.PeerB.NetworkContext.Name, targetNetworkContext))
                    {
                        allowedPairs.Add(pair);
                    }
                }

                if (allowedPairs.Count > 0)
                {
                    container.PeerRelations = new PeerRelation[allowedPairs.Count];
                    for (int i = 0; i < allowedPairs.Count; i++)
                    {
                        PeerRelationPair pair = allowedPairs[i];
                        container.PeerRelations[i] = new PeerRelation(pair.StateId, pair.PeerA.Id, pair.PeerB.Id, pair.Connected);
                    }
                }
            }

            return(container);
        }
Exemplo n.º 3
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);
        }