Single-threaded edge listener for simulation purposes.
Наследование: Edge
Пример #1
0
        private void CreateRemoteEdge(SimulationEdge se_l)
        {
            int remote_id = se_l.RemoteID;
            var el_map    = GetEdgeListenerList(TAType);

            if (!el_map.ContainsKey(remote_id))
            {
                return;
            }

            var remote = el_map[remote_id];

            if (!remote.Nat.AllowingIncomingConnections)
            {
                return;
            }

            // Make sure that the remote listener does not deny our TAs.
            foreach (TransportAddress ta_local in LocalTAs)
            {
                if (remote.TAAuth.Authorize(ta_local) == TAAuthorizer.Decision.Deny)
                {
                    return;
                }
            }

            SimulationEdge se_r = new SimulationEdge(remote, remote_id, LocalID, true,
                                                     se_l.Delay, _ta_type);

            remote.AddEdge(se_r);

            se_l.Partner = se_r;
            se_r.Partner = se_l;
            remote.SendEdgeEvent(se_r);
        }
Пример #2
0
        protected void CloseHandler(object edge, EventArgs ea)
        {
            SimulationEdge se = edge as SimulationEdge;

            // Speed up GC
            if (se.Partner != null)
            {
                se.Partner.Partner = null;
                se.Partner         = null;
            }
            _edges.Remove(se);
        }
Пример #3
0
        /*
         * Implements the EdgeListener function to
         * create edges of this type.
         */
        public override void CreateEdgeTo(TransportAddress ta, EdgeCreationCallback ecb)
        {
            if (!IsStarted)
            {
                // it should return null and not throw an exception
                // for graceful disconnect and preventing others to
                // connect to us after we've disconnected.
                ecb(false, null, new EdgeException("Not started"));
                return;
            }
            else if (ta.TransportAddressType != this.TAType)
            {
                //Can't make an edge of this type
                ecb(false, null, new EdgeException("Can't make edge of this type"));
                return;
            }
            else if (_ta_auth.Authorize(ta) == TAAuthorizer.Decision.Deny)
            {
                //Not authorized.  Can't make this edge:
                ecb(false, null, new EdgeException(ta.ToString() + " is not authorized"));
                return;
            }

            int remote_id      = ((SimulationTransportAddress)ta).ID;
            int real_remote_id = (remote_id >= 0) ? remote_id : ~remote_id;

            //Outbound edge:
            int delay = 0;

            if (_use_delay)
            {
                if (LatencyMap != null)
                {
                    int local  = LocalID % LatencyMap.Count;
                    int remote = real_remote_id % LatencyMap.Count;
                    delay = LatencyMap[local][remote] / 1000;
                }
                else
                {
                    delay = 100;
                }
            }

            SimulationEdge se_l = new SimulationEdge(this, LocalID, remote_id, false, delay, _ta_type);

            if (real_remote_id == remote_id)
            {
                CreateRemoteEdge(se_l);
            }
            ecb(true, se_l, null);
        }
Пример #4
0
        public void HandleEdgeSend(Edge from, ICopyable p)
        {
            SimulationEdge se_from = (SimulationEdge)from;

            if (!Nat.Outgoing(se_from.RemoteTA))
            {
                return;
            }

            if (_ploss_prob > 0)
            {
                if (_rand.NextDouble() < _ploss_prob)
                {
                    return;
                }
            }

            MemBlock mb = p as MemBlock;

            if (mb == null)
            {
                int offset = p.CopyTo(_ba.Buffer, _ba.Offset);
                mb = MemBlock.Reference(_ba.Buffer, _ba.Offset, offset);
                _ba.AdvanceBuffer(offset);
                _bytes += offset;
            }

            SimulationEdge se_to = se_from.Partner;

            if (se_to == null)
            {
                return;
            }

            if (!se_to.SimEL.Nat.Incoming(se_from.LocalTA))
            {
                return;
            }

            se_to.Push(mb);
        }