/// <summary> /// devuelve una direccion acp que conserva solo puerto /// </summary> /// <param name="nodeAddress"></param> /// <returns></returns> public NodeAddress SubstIP(IPAddress newIP) { NodeAddress ret = new NodeAddress( new IPEndPoint(newIP, IPEndPoint.Port)); return(ret); }
public override int GetHashCode() { int ret = 0; ret += NodeId == null ? 0 : NodeId.GetHashCode(); ret += NodeAddress == null ? 0 : NodeAddress.GetHashCode(); return(ret); }
public ItemOutQueue(Route route, Packet packet, OutQueue outQueue) { this.route = route; this.dest = route.remoteNodeAddress; this.packet = packet; this.packetSent = new ManualResetEvent(false); this.outQueue = outQueue; }
public Node() { var nodeAddress = new NodeAddress(); var nodeId = new NodeId(); localBind = new NodeBind(nodeId, nodeAddress); _Initialize(); }
public MailboxIn(Node localNode, NodeAddress nodeAddress) { // oficina this.localNode = localNode; // creamos una ruta para crearnos una direccion de la oficina de correos inRoute = new Route(localNode); inRoute.BufferStream.HandledMessage += new HttpMessageHandler(localNode.HandledReceiveMessageFromRoute); inRoute.Build(nodeAddress); }
public override bool Equals(object obj) { bool ret = false; if (obj != null) { NodeAddress tmp = obj as NodeAddress; ret = IPEndPoint.Equals(tmp.IPEndPoint); } return(ret); }
public Route SearchRoute(NodeAddress remoteNodeAddress) { Route ret = null; try { tableRemote.TryGetValue(remoteNodeAddress, out ret); } catch (Exception err) { Node.LogAppendLine("GetRoute: " + err.Message); } return(ret); }
public Route(Node localNode, Socket socket) { this.socket = socket; this.localNode = localNode; st = new NetworkStream(socket) as Stream; localNodeAddress = new NodeAddress((IPEndPoint)socket.LocalEndPoint); remoteNodeAddress = new NodeAddress((IPEndPoint)socket.RemoteEndPoint); BufferStream = new HttpReceiverStream(localNode, this); InitCommon(); UpdateActivity(); }
public void EndConnect(IAsyncResult asyncResult) { socket.EndConnect(asyncResult); if (socket.Connected) { st = new NetworkStream(socket) as Stream; localNodeAddress = new NodeAddress((IPEndPoint)socket.LocalEndPoint); // remoteNodeAddress = new NodeAddress((IPEndPoint)socket.RemoteEndPoint); if (remoteNodeAddress.IsSecureLayer) { EstablishSSLAsClient(); } } }
/// <summary> /// contruimos entrada de la ruta /// </summary> public void Build(NodeAddress nodeAddress) { try { socket.Bind((EndPoint)nodeAddress.IPEndPoint); socket.Listen(TcpConfig.Backlog); localNodeAddress = nodeAddress; localNodeAddress.IPEndPoint = (IPEndPoint)socket.LocalEndPoint; } catch (NullReferenceException err) { Node.LogAppendLine(err); throw err; } catch (Exception err) { Node.LogAppendLine(err); throw err; } }
/// <summary> /// comprueba cual ruta podemos utilizar para enviar el item /// si la ruta estuviera mal o no existiera crea una ruta nueva /// </summary> /// <param name="item"></param> public Route GetRoute(NodeAddress remoteNodeAddress) { Route route = null; object syncLocal = null; try { bool toconnected = false; lock (sync) { if (pendingConnections.ContainsKey(remoteNodeAddress)) { syncLocal = pendingConnections[remoteNodeAddress]; } else { syncLocal = new object(); pendingConnections.Add(remoteNodeAddress, syncLocal); } } lock (syncLocal) { try { // verificacin route = SearchRoute(remoteNodeAddress); if (route == null) { toconnected = true; } else { toconnected |= !route.Connected; toconnected |= route.Failed; } if (toconnected) { RemoveRoute(route); route = new Route(localNode); route.BufferStream.HandledMessage += new DodoNet.Http.HttpMessageHandler(localNode.HandledReceiveMessageFromRoute); AsyncCallback cb = new AsyncCallback(CreateRouteCB); IAsyncResult ar = route.BeginConnect(remoteNodeAddress, cb, route); if (route.ConnectDone.WaitOne(TcpConfig.ConnectionTimeout, false)) { route.EndConnect(ar); if (route.Connected) { // escuchamos mensajes que nos llegen por esta ruta localNode.mailboxIn.BeginReceive(route); AddRoute(route); } else { throw new Exception(string.Format("GetRoute: Imposible conectar a {0}", remoteNodeAddress)); } } else { throw new Exception(string.Format("GetRoute: Imposible conectar a {0} tiempo max excedido {1}ms", remoteNodeAddress, TcpConfig.ConnectionTimeout)); } } } catch (Exception err) { throw err; } finally { lock (sync) { if (pendingConnections.ContainsKey(remoteNodeAddress)) { pendingConnections.Remove(remoteNodeAddress); } } } } } catch (Exception err) { if (route != null) { route.Dispose(); } throw err; } return(route); }
public KeyRoutePair(NodeAddress localEndPoint, NodeAddress remoteEndPoint) { this.localEndPoint = localEndPoint; this.remoteEndPoint = remoteEndPoint; }
public RouteCollection(Node localNode) { this.localNode = localNode; this.localNodeAddress = localNode.localBind.NodeAddress; }
public IAsyncResult BeginConnect(NodeAddress remoteNodeAddress, AsyncCallback callback, object state) { this.remoteNodeAddress = remoteNodeAddress; return(socket.BeginConnect((EndPoint)remoteNodeAddress.IPEndPoint, callback, state)); }
public NodeBind(NodeId id, NodeAddress address) { this.NodeAddress = address; this.NodeId = id; }