/// <summary>Creates an XmppEdge.</summary> public override void CreateEdgeTo(TransportAddress ta, EdgeCreationCallback ecb) { if (_ready == 0) { ecb(false, null, new Exception("Xmpp is not authenticated")); } XmppTransportAddress xta = ta as XmppTransportAddress; if (xta == null) { ecb(false, null, new Exception("TA Type is not Xmpp!")); return; } else if (!_xmpp.IsUserOnline(xta.JID)) { ecb(false, null, new Exception("Xmpp user, " + xta.JID + ", is not online.")); return; } XmppEdge xe = new XmppEdge(this, _local_ta, xta, false); _it.Add(xe); xe.CloseEvent += CloseHandler; ecb(true, xe, null); }
/// <summary>Used to send data over Xmpp using the specified XmppEdge.</summary> public void HandleEdgeSend(Edge from, ICopyable data) { XmppEdge xe = from as XmppEdge; byte[] msg = new byte[xe.Header.Length + data.Length]; xe.Header.CopyTo(msg, 0); data.CopyTo(msg, xe.Header.Length); _xmpp.SendTo(new XmppRelay(new XmlDocument(), msg), xe.To); }
/// <summary>Remove closed XmppEdges from the IdentifierTable.</summary> protected void CloseHandler(object o, EventArgs ea) { XmppEdge xe = o as XmppEdge; if (xe != null) { _it.Remove(xe.LocalID); } }
/// <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); }
/// <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); }
/// <summary>Creates an XmppEdge.</summary> public override void CreateEdgeTo(TransportAddress ta, EdgeCreationCallback ecb) { if(_ready == 0) { ecb(false, null, new Exception("Xmpp is not authenticated")); } XmppTransportAddress xta = ta as XmppTransportAddress; if(xta == null) { ecb(false, null, new Exception("TA Type is not Xmpp!")); return; } else if(!_xmpp.IsUserOnline(xta.JID)) { ecb(false, null, new Exception("Xmpp user, " + xta.JID + ", is not online.")); return; } XmppEdge xe = new XmppEdge(this, _local_ta, xta, false); _it.Add(xe); xe.CloseEvent += CloseHandler; ecb(true, xe, null); }