/// <summary>Attempt to find the overlap in a remote RelayTransportAddress /// and our local node. This will be used to help communicate with a new /// tunneled peer.</summary> public virtual List<Connection> FindOverlap(RelayTransportAddress ta, ConnectionList cons) { List<Connection> overlap = new List<Connection>(); foreach(Connection con in cons) { if(ta.ContainsForwarder(con.Address)) { overlap.Add(con); } } return GetOldest(overlap); }
/// <summary>Constructor for a RelayEdge, RemoteID == -1 for out bound.</summary> public RelayEdge(IEdgeSendHandler send_handler, RelayTransportAddress local_ta, RelayTransportAddress remote_ta, IForwarderSelector ias, List<Connection> overlap, int remote_id) : base(send_handler, remote_id != -1) { _remote_id = remote_id; lock(_rand) { LocalID = _rand.Next(); } byte[] bid = new byte[8]; NumberSerializer.WriteInt(LocalID, bid, 0); NumberSerializer.WriteInt(_remote_id, bid, 4); _mid = MemBlock.Reference(bid); _local_ta = local_ta; _remote_ta = remote_ta; _tunnels = new List<Connection>(overlap); _ias = ias; _ias.Update(_tunnels); AHHeader ahh = new AHHeader(1, 20, local_ta.Target, remote_ta.Target, AHHeader.Options.Exact); ICopyable header = new CopyList(PType.Protocol.AH, ahh, PType.Protocol.Relaying); Header = MemBlock.Copy(header); }
public void WrapperEdgeRegressionTest() { AHAddress addr = new AHAddress(new System.Security.Cryptography.RNGCryptoServiceProvider()); TransportAddress ta = TransportAddressFactory.CreateInstance("brunet.tcp://169.0.5.1:5000"); FakeEdge fe = new FakeEdge(ta, ta); WrapperEdge we_fe = new WrapperEdge(fe); Connection fcon = new Connection(we_fe, addr, "structured", null, null); List<Connection> overlap = new List<Connection>(); overlap.Add(fcon); RelayTransportAddress tta = new RelayTransportAddress(addr, overlap); RelayEdge te1 = new RelayEdge(null, tta, tta, new SimpleForwarderSelector(), overlap); WrapperEdge we_te1 = new WrapperEdge(te1); Connection t1con = new Connection(we_te1, addr, "structured", null, null); overlap = new List<Connection>(); overlap.Add(t1con); RelayEdge te2 = new RelayEdge(null, tta, tta, new SimpleForwarderSelector(), overlap); WrapperEdge we_te2 = new WrapperEdge(te2); Connection t2con = new Connection(we_te2, addr, "structured", null, null); overlap = new List<Connection>(); overlap.Add(t2con); RelayEdge te3 = new RelayEdge(null, tta, tta, new SimpleForwarderSelector(), overlap); WrapperEdge we_te3 = new WrapperEdge(te3); Connection t3con = new Connection(we_te3, addr, "structured", null, null); overlap = new List<Connection>(); overlap.Add(t3con); RelayEdge te4 = new RelayEdge(null, tta, tta, new SimpleForwarderSelector(), overlap); WrapperEdge we_te4 = new WrapperEdge(te4); Connection t4con = new Connection(we_te4, addr, "structured", null, null); overlap = new List<Connection>(); overlap.Add(t4con); RelayEdge te5 = new RelayEdge(null, tta, tta, new SimpleForwarderSelector(), overlap); WrapperEdge we_te5 = new WrapperEdge(te5); Connection t5con = new Connection(we_te5, addr, "structured", null, null); Assert.AreEqual(te5.ShouldClose(), false, "Shouldn't close yet..."); te1.DisconnectionHandler(fcon); Assert.AreEqual(te5.ShouldClose(), true, "Should close..."); overlap.Add(t5con); overlap.Add(t3con); overlap.Add(t1con); te2.UpdateNeighborIntersection(overlap); Assert.AreEqual(te5.ShouldClose(), true, "Should close... 2"); }
/// <summary>Outgoing edge, since we don't know the RemoteID yet!</summary> public RelayEdge(IEdgeSendHandler send_handler, RelayTransportAddress local_ta, RelayTransportAddress remote_ta, IForwarderSelector ias, List<Connection> overlap) : this(send_handler, local_ta, remote_ta, ias, overlap, -1) { }
public RelayEdgeListener(Node node, IRelayOverlap ito, IForwarderSelectorFactory iasf) { _ito = ito; _iasf = iasf; _oco = new OverlapConnectionOverlord(node); _node = node; _running = 0; _started = 0; _id_to_tunnel = new Dictionary<int, RelayEdge>(); _sync = new object(); TransportAddress ta = new RelayTransportAddress(node.Address, new List<Address>()); ArrayList local_tas = new ArrayList(1); local_tas.Add(ta); _local_tas = local_tas; _node.DemuxHandler.GetTypeSource(PType.Protocol.Relaying).Subscribe(this, null); _node.ConnectionTable.ConnectionEvent += ConnectionHandler; _node.ConnectionTable.DisconnectionEvent += DisconnectionHandler; ConnectionList cons = _node.ConnectionTable.GetConnections(ConnectionType.Structured); Interlocked.Exchange(ref _connections, cons); _node.Rpc.AddHandler("tunnel", this); _oco_trim_timer = Brunet.Util.FuzzyTimer.Instance.DoEvery(OcoTrim, _oco_trim_timeout, 0); }
public RelayEdgeCallbackAction(RelayTransportAddress tta, EdgeCreationCallback ecb) { RelayTA = tta; Ecb = ecb; Exception = new WriteOnce<Exception>(); Success = new WriteOnce<bool>(); Edge = new WriteOnce<Edge>(); }
/// <summary>When a disconnection occurs, we must make sure that none of /// our tunnels use that faulty edge / connection any more.</summary> protected void DisconnectionHandler(object o, EventArgs ea) { ConnectionEventArgs cea = ea as ConnectionEventArgs; if(cea.ConnectionType != ConnectionType.Structured) { return; } ConnectionList cons = cea.CList; Interlocked.Exchange(ref _connections, cons);; IList addresses = GetNearest(_node.Address, cons); TransportAddress ta = new RelayTransportAddress(_node.Address, addresses); ArrayList tas = new ArrayList(1); tas.Add(ta); Interlocked.Exchange(ref _local_tas, tas); foreach(RelayEdge te in _tunnels) { te.DisconnectionHandler(cea.Connection); if(te.IsClosed) { continue; } IDictionary sync_message = _ito.GetSyncMessage(te.Overlap, _node.Address, cons); Channel chan = new Channel(1); _node.Rpc.Invoke(te, chan, "tunnel.Sync", sync_message); } }
/// <summary>We need to keep track of a current ConnectionList, so we /// listen to incoming connections. We also use this opportunity to /// rebuild our LocalTA.</summary> protected void ConnectionHandler(object o, EventArgs ea) { ConnectionEventArgs cea = ea as ConnectionEventArgs; if(cea.ConnectionType != ConnectionType.Structured) { return; } ConnectionList cons = cea.CList; Interlocked.Exchange(ref _connections, cons); IList addresses = GetNearest(_node.Address, cons); TransportAddress ta = new RelayTransportAddress(_node.Address, addresses); ArrayList tas = new ArrayList(1); tas.Add(ta); Interlocked.Exchange(ref _local_tas, tas); foreach(RelayEdge te in _tunnels) { IDictionary sync_message = _ito.GetSyncMessage(te.Overlap, _node.Address, cons); //Do our best here to send a sync message try { _node.Rpc.Invoke(te, null, "tunnel.Sync", sync_message); } catch {} } }