Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        public override int GetHashCode()
        {
            int ret = 0;

            ret += NodeId == null ? 0 : NodeId.GetHashCode();
            ret += NodeAddress == null ? 0 : NodeAddress.GetHashCode();
            return(ret);
        }
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
0
        public Node()
        {
            var nodeAddress = new NodeAddress();
            var nodeId      = new NodeId();

            localBind = new NodeBind(nodeId, nodeAddress);

            _Initialize();
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        public override bool Equals(object obj)
        {
            bool ret = false;

            if (obj != null)
            {
                NodeAddress tmp = obj as NodeAddress;
                ret = IPEndPoint.Equals(tmp.IPEndPoint);
            }

            return(ret);
        }
Ejemplo n.º 7
0
        public Route SearchRoute(NodeAddress remoteNodeAddress)
        {
            Route ret = null;

            try
            {
                tableRemote.TryGetValue(remoteNodeAddress, out ret);
            }
            catch (Exception err)
            {
                Node.LogAppendLine("GetRoute: " + err.Message);
            }
            return(ret);
        }
Ejemplo n.º 8
0
        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();
        }
Ejemplo n.º 9
0
        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();
                }
            }
        }
Ejemplo n.º 10
0
        /// <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;
            }
        }
Ejemplo n.º 11
0
        /// <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);
        }
Ejemplo n.º 12
0
 public KeyRoutePair(NodeAddress localEndPoint, NodeAddress remoteEndPoint)
 {
     this.localEndPoint  = localEndPoint;
     this.remoteEndPoint = remoteEndPoint;
 }
Ejemplo n.º 13
0
 public RouteCollection(Node localNode)
 {
     this.localNode        = localNode;
     this.localNodeAddress = localNode.localBind.NodeAddress;
 }
Ejemplo n.º 14
0
        public IAsyncResult BeginConnect(NodeAddress remoteNodeAddress, AsyncCallback callback, object state)
        {
            this.remoteNodeAddress = remoteNodeAddress;

            return(socket.BeginConnect((EndPoint)remoteNodeAddress.IPEndPoint, callback, state));
        }
Ejemplo n.º 15
0
 public NodeBind(NodeId id, NodeAddress address)
 {
     this.NodeAddress = address;
     this.NodeId      = id;
 }