Skip to content

Better RPC

Luke Champine requested to merge rpc into master

RPC is a lot more sophisticated now, much closer to the standard library's net/rpc package. The main difference is that you register individual functions, not objects. And you can register four types of function:

// low-level, for when you need direct access to the net.Conn
func(net.Conn, []byte) error
// standard RPC
func(Type, *Type) error
// RPC with no return value (broadcast)
func(Type) error
// RPC with no argument (request)
func(*Type) error

To call an RPC, use NetAddress.RPC:

// standard RPC
addr.RPC('R', blocks, &resp)
// no return value
addr.RPC('R', blocks, nil)
// no argument
addr.RPC('R', nil, &resp)

However, error values are not yet returned. And I'm probably going to switch to longer procedure names; one byte is manageable, but not very self-documenting. "SendBlocks" would be much better than 'B'.

I also reorganized the network package a bit, moving the RPC stuff into its own file and condensing existing RPCs with the new abstractions. Plus a bunch of minor bugfixes.

Merge request reports