public bool NegotiateConnection(string xmlrpc_uri) { int protos = 0; XmlRpcValue tcpros_array = new XmlRpcValue(), protos_array = new XmlRpcValue(), Params = new XmlRpcValue(); tcpros_array.Set(0, "TCPROS"); protos_array.Set(protos++, tcpros_array); Params.Set(0, this_node.Name); Params.Set(1, name); Params.Set(2, protos_array); string peer_host = ""; int peer_port = 0; if (!network.splitURI(xmlrpc_uri, ref peer_host, ref peer_port)) { EDB.WriteLine("Bad xml-rpc URI: [" + xmlrpc_uri + "]"); return(false); } XmlRpcClient c = new XmlRpcClient(peer_host, peer_port); if (!c.IsConnected || !c.ExecuteNonBlock("requestTopic", Params)) { EDB.WriteLine("Failed to contact publisher [" + peer_host + ":" + peer_port + "] for topic [" + name + "]"); c.Dispose(); return(false); } #if DEBUG EDB.WriteLine("Began asynchronous xmlrpc connection to http://" + peer_host + ":" + peer_port + "/ for topic [" + name + "]"); #endif PendingConnection conn = new PendingConnection(c, this, xmlrpc_uri, Params); lock (pending_connections_mutex) { pending_connections.Add(conn); } XmlRpcManager.Instance.addAsyncConnection(conn); return(true); }
public void pendingConnectionDone(PendingConnection conn, IntPtr res) { XmlRpcValue result = XmlRpcValue.LookUp(res); lock (shutdown_mutex) { if (shutting_down || _dropped) { return; } } XmlRpcValue proto = new XmlRpcValue(); if (!XmlRpcManager.Instance.validateXmlrpcResponse("requestTopic", result, ref proto)) { conn.failures++; EDB.WriteLine("Negotiating for " + conn.parent.name + " has failed " + conn.failures + " times"); return; } lock (pending_connections_mutex) { pending_connections.Remove(conn); } string peer_host = conn.client.Host; int peer_port = conn.client.Port; string xmlrpc_uri = "http://" + peer_host + ":" + peer_port + "/"; if (proto.Size == 0) { #if DEBUG EDB.WriteLine("Couldn't agree on any common protocols with [" + xmlrpc_uri + "] for topic [" + name + "]"); #endif return; } if (proto.Type != TypeEnum.TypeArray) { EDB.WriteLine("Available protocol info returned from " + xmlrpc_uri + " is not a list."); return; } string proto_name = proto[0].Get <string>(); if (proto_name == "UDPROS") { EDB.WriteLine("OWNED! Only tcpros is supported right now."); } else if (proto_name == "TCPROS") { if (proto.Size != 3 || proto[1].Type != TypeEnum.TypeString || proto[2].Type != TypeEnum.TypeInt) { EDB.WriteLine("publisher implements TCPROS... BADLY! parameters aren't string,int"); return; } string pub_host = proto[1].Get <string>(); int pub_port = proto[2].Get <int>(); #if DEBUG EDB.WriteLine("Connecting via tcpros to topic [" + name + "] at host [" + pub_host + ":" + pub_port + "]"); #endif TcpTransport transport = new TcpTransport(PollManager.Instance.poll_set) { _topic = name }; if (transport.connect(pub_host, pub_port)) { Connection connection = new Connection(); TransportPublisherLink pub_link = new TransportPublisherLink(this, xmlrpc_uri); connection.initialize(transport, false, null); pub_link.initialize(connection); ConnectionManager.Instance.addConnection(connection); lock (publisher_links_mutex) { addPublisherLink(pub_link); } #if DEBUG EDB.WriteLine("Connected to publisher of topic [" + name + "] at [" + pub_host + ":" + pub_port + "]"); #endif } else { EDB.WriteLine("Failed to connect to publisher of topic [" + name + "] at [" + pub_host + ":" + pub_port + "]"); } } else { EDB.WriteLine("Your xmlrpc server be talking jibber jabber, foo"); } }