Ejemplo n.º 1
0
        public bool handleHeader(Header header)
        {
            if (!header.Values.Contains("md5sum") || !header.Values.Contains("service") || !header.Values.Contains("callerid"))
            {
                string bbq = "Bogus tcpros header. did not have required elements: md5sum, service, callerid";
                ROS.Error(bbq);
                connection.sendHeaderError(ref bbq);
                return false;
            }
            string md5sum = (string) header.Values["md5sum"];
            string service = (string) header.Values["service"];
            string client_callerid = (string) header.Values["client_callerid"];

            if (header.Values.Contains("persistent") && ((string) header.Values["persistent"] == "1" || (string) header.Values["persistent"] == "true"))
                persistent = true;

            ROS.Debug("Service client [{0}] wants service [{1}] with md5sum [{2}]", client_callerid, service, md5sum);
            IServicePublication isp = ServiceManager.Instance.lookupServicePublication(service);
            if (isp == null)
            {
                string bbq = string.Format("received a tcpros connection for a nonexistent service [{0}]", service);
                ROS.Error(bbq);
                connection.sendHeaderError(ref bbq);
                return false;
            }

            if (isp.md5sum != md5sum && md5sum != "*" && isp.md5sum != "*")
            {
                string bbq = "client wants service " + service + " to have md5sum " + md5sum + " but it has " + isp.md5sum + ". Dropping connection";
                ROS.Error(bbq);
                connection.sendHeaderError(ref bbq);
                return false;
            }

            if (isp.isDropped)
            {
                string bbq = "received a tcpros connection for a nonexistent service [" + service + "]";
                ROS.Error(bbq);
                connection.sendHeaderError(ref bbq);
                return false;
            }

            parent = isp;
            IDictionary m = new Hashtable();
            m["request_type"] = isp.req_datatype;
            m["response_type"] = isp.res_datatype;
            m["type"] = isp.datatype;
            m["md5sum"] = isp.md5sum;
            m["callerid"] = this_node.Name;

            connection.writeHeader(m, onHeaderWritten);

            isp.addServiceClientLink(this);
            return true;
        }
        public bool handleHeader(Header header)
        {
            if (!header.Values.Contains("topic"))
            {
                string msg = "Header from subscriber did not have the required element: topic";
                EDB.WriteLine(msg);
                connection.sendHeaderError(ref msg);
                return false;
            }
            string name = (string) header.Values["topic"];
            string client_callerid = (string) header.Values["callerid"];
            Publication pt = TopicManager.Instance.lookupPublication(name);
            if (pt == null)
            {
                string msg = "received a connection for a nonexistent topic [" + name + "] from [" +
                             connection.transport + "] [" + client_callerid + "]";
                EDB.WriteLine(msg);
                connection.sendHeaderError(ref msg);
                return false;
            }
            string error_message = "";
            if (!pt.validateHeader(header, ref error_message))
            {
                connection.sendHeaderError(ref error_message);
                EDB.WriteLine(error_message);
                return false;
            }
            destination_caller_id = client_callerid;
            connection_id = ConnectionManager.Instance.GetNewConnectionID();
            name = pt.Name;
            parent = pt;
            lock (parent)
            {
                max_queue = parent.MaxQueue;
            }
            IDictionary m = new Hashtable();
            m["type"] = pt.DataType;
            m["md5sum"] = pt.Md5sum;
            m["message_definition"] = pt.MessageDefinition;
            m["callerid"] = this_node.Name;
            m["latching"] = pt.Latch;
            connection.writeHeader(m, onHeaderWritten);
            pt.addSubscriberLink(this);
#if DEBUG
            EDB.WriteLine("Finalize transport subscriber link for " + name);
#endif
            return true;
        }
Ejemplo n.º 3
0
 public bool setHeader(Header h)
 {
     CallerID = (string) h.Values["callerid"];
     if (!h.Values.Contains("md5sum"))
         return false;
     md5sum = (string) h.Values["md5sum"];
     Latched = false;
     if (!h.Values.Contains("latching"))
         return false;
     if ((string) h.Values["latching"] == "1")
         Latched = true;
     ConnectionID = ConnectionManager.Instance.GetNewConnectionID();
     header = h;
     parent.headerReceived(this, header);
     return true;
 }
Ejemplo n.º 4
0
        public static bool exists(string service_name, bool print_failure_reason)
        {
            string mapped_name = names.resolve(service_name);

            string host = "";
            int port = 0;

            if (ServiceManager.Instance.lookUpService(mapped_name, ref host, ref port))
            {
                TcpTransport transport = new TcpTransport();

                IDictionary m = new Hashtable
                {
                    {"probe", "1"},
                    {"md5sum", "*"},
                    {"callerid", this_node.Name},
                    {"service", mapped_name}
                };

                byte[] headerbuf = null;
                int size = 0;
                Header h = new Header();
                h.Write(m, ref headerbuf, ref size);

                if (transport.connect(host, port))
                {
                    byte[] sizebuf = BitConverter.GetBytes(size);

                    transport.write(sizebuf, 0, sizebuf.Length);
                    transport.write(headerbuf, 0, size);

                    return true;
                }
                if (print_failure_reason)
                {
                    ROS.Info("waitForService: Service[{0}] could not connect to host [{1}:{2}], waiting...", mapped_name, host, port);
                }
            }
            else if (print_failure_reason)
            {
                ROS.Info("waitForService: Service[{0}] has not been advertised, waiting...", mapped_name);
            }
            return false;
        }
Ejemplo n.º 5
0
        public bool validateHeader(Header header, ref string error_message)
        {
            string md5sum = "", topic = "", client_callerid = "";
            if (!header.Values.Contains("md5sum") || !header.Values.Contains("topic") ||
                !header.Values.Contains("callerid"))
            {
                const string msg = "Header from subscriber did not have the required elements: md5sum, topic, callerid";
                EDB.WriteLine(msg);
                error_message = msg;
                return false;
            }
            md5sum = (string) header.Values["md5sum"];
            topic = (string) header.Values["topic"];
            client_callerid = (string) header.Values["callerid"];
            if (Dropped)
            {
                string msg = "received a tcpros connection for a nonexistent topic [" + topic + "] from [" +
                             client_callerid + "].";
                EDB.WriteLine(msg);
                error_message = msg;
                return false;
            }

            if (Md5sum != md5sum && (md5sum != "*") && Md5sum != "*")
            {
                string datatype = header.Values.Contains("type") ? (string) header.Values["type"] : "unknown";
                string msg = "Client [" + client_callerid + "] wants topic [" + topic + "] to hava datatype/md5sum [" +
                             datatype + "/" + md5sum + "], but our version has [" + DataType + "/" + Md5sum +
                             "]. Dropping connection";
                EDB.WriteLine(msg);
                error_message = msg;
                return false;
            }
            return true;
        }
Ejemplo n.º 6
0
 public void parseHeader(Header header)
 {
     if (_topic == null)
     {
         if (header.Values.Contains("topic"))
             _topic = header.Values["topic"].ToString();
     }
     string nodelay = "";
     if (header.Values.Contains("tcp_nodelay"))
         nodelay = (string) header.Values["tcp_nodelay"];
     if (nodelay == "1")
     {
         setNoDelay(true);
     }
 }
Ejemplo n.º 7
0
 public void parseHeader(Header header)
 {
     string nodelay = "";
     if (header.Values.Contains("tcp_nodelay"))
         nodelay = (string) header.Values["tcp_nodelay"];
     if (nodelay == "1")
     {
         setNoDelay(true);
     }
 }