Exemplo n.º 1
0
        /// <summary>Where data packets prepended with a prepended subring come.
        /// Here we receive data as well as create new SubringEdges.</summary>
        public void HandleData(MemBlock data, ISender return_path, object state)
        {
            AHSender from = return_path as AHSender;

            if (from == null)
            {
                return;
            }

            AHAddress target = (AHAddress)from.Destination;
            MemBlock  payload;
            int       local_id, remote_id;

            _it.Parse(data, out payload, out local_id, out remote_id);

            IIdentifierPair ip;
            SubringEdge     se;

            if (_it.TryGet(local_id, remote_id, out ip))
            {
                se = ip as SubringEdge;
            }
            else if (local_id == 0)
            {
                if (!from.Node.Realm.Equals(_shared_node.Realm))
                {
                    // We don't have matching realms
                    return;
                }
                var rem_sta = new SubringTransportAddress(target, from.Node.Realm);
                se = new SubringEdge(_local_ta, rem_sta, true, from, _ptype);
                _it.Add(se);
                se.RemoteID    = remote_id;
                se.CloseEvent += CloseHandler;
                SendEdgeEvent(se);
            }
            else
            {
                // Probably an edge closed earlier...
                return;
            }

            se.ReceivedPacketEvent(payload);
        }
Exemplo n.º 2
0
        override public void HandleData(MemBlock data, ISender return_path, object state)
        {
            if (return_path is SecurityAssociation)
            {
                Handle(data, return_path);
                return;
            }

            MemBlock tmp = data.Slice(0, _ptype_mb.Length);

            if (tmp.Equals(_ptype_mb))
            {
                data = data.Slice(_ptype_mb.Length);
            }

            MemBlock        payload;
            int             localid, remoteid;
            IIdentifierPair cp;
            DtlsAssociation sa;

            try {
                _it.Parse(data, out payload, out localid, out remoteid);
                _it.TryGet(localid, remoteid, out cp);
            } catch (Exception e) {
                ProtocolLog.WriteIf(ProtocolLog.SecurityExceptions, e.Message);
                return;
            }

            if (cp != null)
            {
                sa = cp as DtlsAssociation;
            }
            else
            {
                NoSuchSA(return_path, remoteid, false, out sa);
                _it.Add(sa);
                sa.RemoteID = remoteid;
                sa.Subscribe(this, null);
            }
            sa.HandleData(payload, return_path, null);
        }
Exemplo n.º 3
0
        /// <summary>Got a packet from Xmpp.</summary>
        protected void HandleData(Element msg, JID from)
        {
            // Speed in this method isn't key as we are going through a relay
            XmppRelay xr = msg as XmppRelay;

            if (xr == null)
            {
                return;
            }

            MemBlock payload;
            int      local_id, remote_id;

            _it.Parse(xr.Data, out payload, out local_id, out remote_id);

            IIdentifierPair ip;
            XmppEdge        xe;

            if (_it.TryGet(local_id, remote_id, out ip))
            {
                xe = ip as XmppEdge;
            }
            else if (local_id == 0)
            {
                xe = new XmppEdge(this, _local_ta, new XmppTransportAddress(from), true);
                _it.Add(xe);
                xe.CloseEvent += CloseHandler;
                xe.RemoteID    = remote_id;
                SendEdgeEvent(xe);
            }
            else
            {
                // Probably an edge closed earlier...
                return;
            }

            xe.ReceivedPacketEvent(payload);
        }