public void HandleRpc(ISender caller, string meth, IList args, object state) { if (meth == "create") { Edge calling_edge = (Edge)((ReqrepManager.ReplyState)caller).ReturnPath; string remote_path = (string)args[0]; string local_path = (string)args[1]; PathEdgeListener el = _pel_map[local_path]; if (el.IsStarted) { PathEdge npe = new PathEdge(this, calling_edge, local_path, remote_path); lock ( _sync ) { //We don't announce yet, wait till we get some data, which //verifies that the other side has seen it. _unannounced[calling_edge] = npe; } //So the new Edge has been announced. Rpc.SendResult(state, true); } else { throw new Exception( String.Format("PathEdgeListener({0}) not started", local_path)); } } else { throw new AdrException(-32601, "No Handler for method: " + meth); } }
public override void UpdateRemoteTAs(IList <TransportAddress> list, Edge e, TransportAddress ta) { PathEdge pe = e as PathEdge; if (pe != null) { _el.UpdateRemoteTAs(list, pe.Edge, ta); } }
public override void UpdateLocalTAs(Edge e, TransportAddress ta) { PathEdge pe = e as PathEdge; if (pe != null) { _el.UpdateLocalTAs(pe.Edge, ta); } else { _el.UpdateLocalTAs(e, ta); } }
/** try to create a new PathEdge and send the EdgeEvent */ public void SendPathEdgeEvent(PathEdge pe) { if (1 == _is_started) { pe.CloseEvent += CloseHandler; Interlocked.Increment(ref _count); SendEdgeEvent(pe); } else { throw new Exception( String.Format("PathEdgeListener{0} not yet started", _path)); } }
public void HandleEC(bool succ, Edge e, Exception x) { if (!succ) { ECB(false, null, x); return; } else if (_root) { Interlocked.Increment(ref _pel._count); e.CloseEvent += _pel.CloseHandler; ECB(succ, e, x); return; } /* * Got the underlying Edge, now do the path protocol */ Channel results = new Channel(1); results.CloseEvent += delegate(object q, EventArgs args) { try { RpcResult res = (RpcResult)results.Dequeue(); object o = res.Result; if (o is Exception) { throw (o as Exception); } } catch (Exception cx) { e.Close(); ECB(false, null, cx); return; } //If we get here, everything looks good: PathEdge pe = new PathEdge(_pel._pem, e, LocalPath, RemotePath); //Start sending e's packets into pe pe.Subscribe(); pe.CloseEvent += _pel.CloseHandler; Interlocked.Increment(ref _pel._count); ECB(true, pe, null); }; //Make sure we hear the packets on this edge: e.Subscribe(_pel._pem, null); //Now make the rpc call: _pel._pem.Rpc.Invoke(e, results, "sys:pathing.create", LocalPath, RemotePath); }
protected void EdgeTimeoutChecker() { // Get the list of old edges DateTime remove_timeout = DateTime.UtcNow.AddMinutes(-5); List <Edge> to_close = new List <Edge>(); lock (_sync) { foreach (Edge e in _unannounced.Keys) { if (e.CreatedDateTime < remove_timeout) { to_close.Add(e); } } } // Close the Edges foreach (Edge e in to_close) { PathEdge pe = null; if (!_unannounced.TryGetValue(e, out pe)) { continue; } try { pe.Close(); } catch (Exception ex) { ProtocolLog.WriteIf(ProtocolLog.Exceptions, ex.ToString()); } } // Remove them from the _unannounced dictionary lock (_sync) { foreach (Edge e in to_close) { _unannounced.Remove(e); } } }
protected int GetUdpIdx(ConnectionState cs) { var ue = (BT.UdpEdge)cs.Edge; if (ue == null) { BT.PathEdge tmp = (BT.PathEdge)cs.Edge; if (tmp == null) { return(0); } ue = (BT.UdpEdge)tmp.Edge; } if (ue.IsInbound) { return(ue.ID); } else { return(ue.RemoteID); } }
/** try to create a new PathEdge and send the EdgeEvent */ public void SendPathEdgeEvent(PathEdge pe) { if( 1 == _is_started ) { pe.CloseEvent += CloseHandler; Interlocked.Increment(ref _count); SendEdgeEvent(pe); } else { throw new Exception( String.Format("PathEdgeListener{0} not yet started", _path)); } }
public void HandleEC(bool succ, Edge e, Exception x) { if(!succ) { ECB(false, null, x); return; } else if(_root) { Interlocked.Increment(ref _pel._count); e.CloseEvent += _pel.CloseHandler; ECB(succ, e, x); return; } /* * Got the underlying Edge, now do the path protocol */ Channel results = new Channel(1); results.CloseEvent += delegate(object q, EventArgs args) { try { RpcResult res = (RpcResult)results.Dequeue(); object o = res.Result; if(o is Exception) { throw (o as Exception); } } catch(Exception cx) { e.Close(); ECB(false, null, cx); return; } //If we get here, everything looks good: PathEdge pe = new PathEdge(_pel._pem, e, LocalPath, RemotePath); //Start sending e's packets into pe pe.Subscribe(); pe.CloseEvent += _pel.CloseHandler; Interlocked.Increment(ref _pel._count); ECB(true, pe, null); }; //Make sure we hear the packets on this edge: e.Subscribe(_pel._pem, null); //Now make the rpc call: _pel._pem.Rpc.Invoke(e, results, "sys:pathing.create", LocalPath, RemotePath ); }
public void HandleRpc(ISender caller, string meth, IList args, object state) { if( meth == "create" ) { Edge calling_edge = (Edge)((ReqrepManager.ReplyState)caller).ReturnPath; string remote_path = (string)args[0]; string local_path = (string)args[1]; PathEdgeListener el = _pel_map[local_path]; if( el.IsStarted ) { PathEdge npe = new PathEdge(this, calling_edge, local_path, remote_path); lock( _sync ) { //We don't announce yet, wait till we get some data, which //verifies that the other side has seen it. _unannounced[calling_edge] = npe; } //So the new Edge has been announced. Rpc.SendResult(state, true); } else { throw new Exception( String.Format("PathEdgeListener({0}) not started", local_path)); } } else { throw new AdrException(-32601, "No Handler for method: " + meth); } }
/** Handle incoming data on an Edge */ public void HandleData(MemBlock data, ISender retpath, object state) { MemBlock rest_of_data; PType p; if( state == null ) { try { p = PType.Parse(data, out rest_of_data); } catch(ParseException) { ProtocolLog.WriteIf(ProtocolLog.Pathing, "Invalid PType from: " + data); return; } p = PType.Parse(data, out rest_of_data); } else { //a demux has already happened: p = (PType)state; rest_of_data = data; } if( PType.Protocol.Pathing.Equals(p) ) { /* * We use a special PType to denote this transaction so * we don't confuse it with other RepRep communication */ _rrm.HandleData(rest_of_data, retpath, null); } else if( PType.Protocol.Rpc.Equals(p) ) { /* * Send this to the RpcHandler */ Rpc.HandleData(rest_of_data, retpath, null); } else { /* * This is some other data * It is either: * 1) Time to announce an already created edge. * 2) Assume this is a "default path" edge creation, to be backwards * compatible */ Edge e = null; PathEdge pe = null; try { e = (Edge)retpath; PathEdgeListener pel = null; lock( _sync ) { if( _unannounced.TryGetValue(e, out pe) ) { // _unannounced.Remove(e); pel = _pel_map[pe.LocalPath]; } } if( pe == null ) { if(! _pel_map.ContainsKey(Root) ) { ProtocolLog.WriteIf(ProtocolLog.Pathing, "No root, can't create edge"); if(e != null) { e.Close(); } return; } /* * This must be a "default path" incoming connection */ pel = _pel_map[Root]; pe = new PathEdge(this, e, Root, Root); } pel.SendPathEdgeEvent(pe); pe.Subscribe(); pe.ReceivedPacketEvent(data); } catch(Exception x) { if( pe != null ) { //This closes both edges: pe.Close(); } else if( e != null ) { ProtocolLog.WriteIf(ProtocolLog.Pathing, String.Format("Closing ({0}) due to: {1}", e, x)); e.Close(); } } } }
/** Handle incoming data on an Edge */ public void HandleData(MemBlock data, ISender retpath, object state) { MemBlock rest_of_data; PType p; if (state == null) { try { p = PType.Parse(data, out rest_of_data); } catch (ParseException) { ProtocolLog.WriteIf(ProtocolLog.Pathing, "Invalid PType from: " + data); return; } p = PType.Parse(data, out rest_of_data); } else { //a demux has already happened: p = (PType)state; rest_of_data = data; } if (PType.Protocol.Pathing.Equals(p)) { /* * We use a special PType to denote this transaction so * we don't confuse it with other RepRep communication */ _rrm.HandleData(rest_of_data, retpath, null); } else if (PType.Protocol.Rpc.Equals(p)) { /* * Send this to the RpcHandler */ Rpc.HandleData(rest_of_data, retpath, null); } else { /* * This is some other data * It is either: * 1) Time to announce an already created edge. * 2) Assume this is a "default path" edge creation, to be backwards * compatible */ Edge e = null; PathEdge pe = null; try { e = (Edge)retpath; PathEdgeListener pel = null; lock ( _sync ) { if (_unannounced.TryGetValue(e, out pe)) { // _unannounced.Remove(e); pel = _pel_map[pe.LocalPath]; } } if (pe == null) { if (!_pel_map.ContainsKey(Root)) { ProtocolLog.WriteIf(ProtocolLog.Pathing, "No root, can't create edge"); if (e != null) { e.Close(); } return; } /* * This must be a "default path" incoming connection */ pel = _pel_map[Root]; pe = new PathEdge(this, e, Root, Root); } pel.SendPathEdgeEvent(pe); pe.Subscribe(); pe.ReceivedPacketEvent(data); } catch (Exception x) { if (pe != null) { //This closes both edges: pe.Close(); } else if (e != null) { ProtocolLog.WriteIf(ProtocolLog.Pathing, String.Format("Closing ({0}) due to: {1}", e, x)); e.Close(); } } } }