DRb method access

2019-08-01 19:16发布

问题:

I am writing a simple distributed system in DRb.

I have all the peers, and one server to do the bootstrapping. In that server, I have a few methods like "suggest_peer", and "start_service" and "stop_service".

When a peer connects to the server, he is able to call all three methods. I want him to be able to call only the first one.

Also, I have a file that initializes the server, and has a little cmd line so I can start the service, debug, log and all that. I want that cmd line to be able to call the second and third methods, as well as the first one.

How can I do that? How can I prevent peers from stopping the service?
If I put the service methods as private, I can't call them from the cmd line.

回答1:

This is what I got.

Thread.current['DRb']['client'].peeraddr

This returns a little array with 4 items. first one is the protocol, second is the port, third is host(name) and forth is the address(same as host if no name).

Thanks to Brian Candler from http://www.ruby-forum.com/topic/1962357