How-to: deploying XML-RPC service over Brunet
From BoykinWiki
Brunet RPC has an XML-RPC interface which allows you to access it from outside .NET environment.
Contents |
Configure
To enable the service when you deploy Brunet/IPOP (SimpleNode or IPRouter), you need to go to the config file and properly set element <XmlRpcManager> (Enabled and Port). Then you will be able to access the service at:
http://localhost:port/xm.rem
In many cases you only need to start XML-RPC service on your local machine so you might want to use the XML-RPC disabled config file for other nodes.
Accessing XML-RPC services on a Brunet node with its Brunet Address
On Brunet overlay you can actually do the XML-RPC <-> Brunet <-> XML-RPC calls. Say, you have a XML-RPC service on a machine which has a XML-RPC method like get_stats() which returns some valuable information. You can plug it in the Brunet RpcManager so that clients on other nodes can access it.
Note: they don't have your IP address and the they might not be able to reach the node through regular ways because you might be behind a firewall. All they have is your Brunet address.
There are two methods to manage the work:
//register the service void AddXRHandler(string handlerName, string uri); //unregister the service void RemoveXRHandler(string handlerName, string uri);
- uri is the URI of the XML-RPC that you provide
- handlerName is the name that you give to the service in the Brunet-RPC context.
You can register the service through a XML-RPC call from your XML-RPC client written in any language. Taking get_stats service and Python client as example:
Register Service
import xmlrpclib
# You use 10000 as the port of XmlRpcManager
URL = "http://127.0.0.1:10000/xm.rem"
rpc = xmlrpclib.Server(URL)
# You have a server that we named 'host' at http://localhost:8000 that has the get_stats method
rpc.localproxy("xmlrpc.AddXRHandler", 'host','http://127.0.0.1:8000')
Now you have the service registered and people can use it from another node of the overlay. Note: You are not able to register services from a remote node. For security concerns, we block this kind of calls:
rpc.proxy(address_of_a_remote_node, 3, 1, "xmlrpc.AddXRHandler", "host", "http://127.0.0.1:8000")
Consume Service
If we call your node 'node_a', then clients on a remote node can access the get_stats method on the host by specifying the brunet address of the target node.
rpc.proxy(brunet_addr_of_node_a, 3, 1, 'host.get_stats')
Note:
- 'host.get_stats': A dot is used to separate host and method name
- this method doesn't have any argument, otherwise, specify them at the end of the arg-list
- See Brunet XML-RPC API
Unregister Service
If you wanted to stop serving the method over Brunet, you can just unregister it by using:
rpc.localproxy("xmlrpc.RemoveXRHandler", 'host','http://127.0.0.1:8000')
