Example #1
0
 /// <summary>
 /// send message to other node
 /// </summary>
 /// <param name="msg"></param>
 /// <param name="dest"></param>
 /// <param name="callback"></param>
 internal void SendMessageAsync(NodeBind dest, Message msg, RouteContCallback callback)
 {
     // tasks before sending
     msg.MessageSourceHook(this);
     // send by wire
     mailboxOut.BeginSend(localBind, dest, msg, callback);
 }
Example #2
0
        public override void Execute(Node localNode)
        {
            try
            {
                // Failed to send the message. Try routing again.
                retryCount++;

                if (!msg.Cancelled)
                {
                    // Find the next hop for this message
                    nextHop = msg.GetNextHop(localNode);

                    // el numero de saltos está limitado
                    if (nextHop == localNode.localBind)
                    {
                        // Message has arrived at its destination
                        msg.MessageArrivedHook(localNode);
                    }
                    else if (nextHop != null)
                    {
                        // Send on to next hop
                        var cb = new RouteContCallback(Callback);
                        localNode.SendMessageAsync(nextHop, msg, cb);
                    }
                    else
                    {
                        msg.Dispose();
                    }
                }
            }
            catch (Exception err)
            {
                msg.MessageSourceHook(localNode, err);
            }
        }
Example #3
0
 internal SendItemThread(NodeBind source, NodeBind dest, Message msg, RouteContCallback cb)
 {
     this.source = source;
     this.dest   = dest;
     this.msg    = msg;
     this.cb     = cb;
 }
Example #4
0
        public void BeginSend(NodeBind source, NodeBind dest, Message msg, RouteContCallback cb)
        {
            wgSendFrames.QueueWorkItem(new WorkItemCallback(BeginSend_tt),
                                       (object)new SendItemThread(source, dest, msg, cb),
                                       WorkItemPriority.Normal);

            //-- BeginSend_tt((object)new SendItemThread(source, dest, msg, cb));
        }
Example #5
0
        /// <summary>
        /// envia un mensaje troceado en paquetes
        /// </summary>
        internal object BeginSend_tt(object state)
        {
            Route     route     = null;
            bool      success   = true;
            Exception exception = null;

            SendItemThread tmp = (SendItemThread)state;

            NodeBind          source = tmp.source;
            NodeBind          dest   = tmp.dest;
            Message           msg    = tmp.msg;
            RouteContCallback cb     = tmp.cb;

            try
            {
                // firewall
                if (localNode.blockedAddresses.IndexOf(dest.NodeId) > -1)
                {
                    throw new Exception("Dirección bloqueada");
                }

                // conseguir la ruta para mandar los datos al destino
                route = localNode.RouteTable.GetRoute(dest.NodeAddress);

                byte[] buf = new byte[8192];
                int    bytesRead;

                IHttpMessage httpMsg = msg.Serialize();

                using (var sourceStream = new HttpSenderStream(httpMsg))
                {
                    sourceStream.Position = 0;
                    // copy all data from in to out via the buffer layer
                    while ((bytesRead = sourceStream.Read(buf, 0, buf.Length)) > 0 &&
                           !msg.Cancelled)
                    {
                        route.Send(buf, 0, bytesRead);
                        totalBytesSent += (uint)bytesRead;
                    }

                    if (msg.Cancelled)
                    {
                        Node.LogAppendLine("Envio cancelado {0}");
                    }
                }
            }
            catch (Exception err)
            {
                exception = err;
                success   = false;
            }
            finally
            {
                try
                {
                    // llamamos al callback
                    if (cb != null)
                    {
                        cb(localNode, msg, route, success, exception);
                    }
                }
                catch { }
            }
            return(null);
        }
Example #6
0
 public void BeginSendKeepAlive(NodeBind source, NodeBind dest, RouteContCallback cb)
 {
     wgKeepAlive.QueueWorkItem(new WorkItemCallback(BeginSendKeepAlive_tt),
                               new object[] { source, dest, cb }, WorkItemPriority.Highest);
 }