/// <summary> /// buscar una ruta a partir del identificador remoto del nodo al que pertenece /// </summary> /// <param name="nodeId"></param> /// <returns></returns> public Route SearchRoute(NodeBind remoteNodeBind) { Route ret = null; try { // si existe nodeAddress if (remoteNodeBind.NodeAddress != null) { ret = SearchRoute(remoteNodeBind.NodeAddress); } if (ret == null) { KeyRoutePair key = null; if (tableNodeId.TryGetValue(remoteNodeBind.NodeId, out key)) { table.TryGetValue(key, out ret); } } } catch (Exception err) { Node.LogAppendLine("GetRoute: " + err.Message); } return(ret); }
public bool Equals(KeyRoutePair key) { if (localEndPoint.Equals(key.localEndPoint) && remoteEndPoint.Equals(key.remoteEndPoint)) { return(true); } return(false); }
/// <summary> /// desvincular una ruta de un identificador de nodo /// </summary> /// <param name="route"></param> /// <param name="nodeId"></param> public void UnlinkRoute(Route r, NodeId remoteNodeId) { try { lock (sync) { KeyRoutePair key = new KeyRoutePair(r.localNodeAddress, r.remoteNodeAddress); tableNodeId.Remove(remoteNodeId); } } catch { } }
public Route this[KeyRoutePair key] { get { return(table[key]); } set { lock (sync) { table[key] = value; } } }
public void RemoveRoute(Route r) { try { if (r != null) { lock (sync) { Node.LogAppendLine("Eliminar ruta: {0}", r.remoteNodeAddress); KeyRoutePair key = new KeyRoutePair(r.localNodeAddress, r.remoteNodeAddress); if (table.ContainsKey(key)) { table.Remove(key); tableRemote.Remove(r.remoteNodeAddress); // detruir ruta r.Dispose(); // elimina r vinculos UnlinkRoute(r); /* * int y = 0; * * StackTrace st = new StackTrace(true); * * for (int x = 0; x < st.FrameCount; x++) * { * y++; * StackFrame sf = st.GetFrame(x); * Node.LogAppendLine("({0:000})\t {1} Line: {2} File:{3}", * y, sf.GetMethod().Name, sf.GetFileLineNumber(), sf.GetFileName()); * } * * Node.LogAppendLine("NodoId: {0} Eliminada ruta local:{1} remote:{2}", * localNode.localBind.NodeId, r.localNodeAddress, r.remoteNodeAddress); */ } } } } catch (Exception err) { Node.LogAppendLine(err); } }
/// <summary> /// vicular una ruta a un identificador de nodo /// </summary> /// <param name="route"></param> /// <param name="nodeId"></param> public void LinkRoute(Route r, NodeId remoteNodeId) { try { lock (sync) { KeyRoutePair key = new KeyRoutePair(r.localNodeAddress, r.remoteNodeAddress); if (table.ContainsKey(key) && !tableNodeId.ContainsKey(remoteNodeId)) { tableNodeId.Add(remoteNodeId, key); } } } catch { } }
public void UnlinkRoute(Route r) { try { lock (sync) { KeyRoutePair key = new KeyRoutePair(r.localNodeAddress, r.remoteNodeAddress); foreach (KeyValuePair <NodeId, KeyRoutePair> kvp in tableNodeId) { if (kvp.Value.Equals(key)) { tableNodeId.Remove(kvp.Key); } } } } catch { } }
public void AddRoute(Route r) { try { lock (sync) { KeyRoutePair key = new KeyRoutePair(r.localNodeAddress, r.remoteNodeAddress); table.Add(key, r); tableRemote.Add(r.remoteNodeAddress, r); Node.LogAppendLine("NodoId: {0} Nueva ruta local:{1} remote:{2}", localNode.localBind.NodeId, r.localNodeAddress, r.remoteNodeAddress); } } catch (Exception err) { Node.LogAppendLine("AddRoute: " + err.Message); } }