Documentation ¶
Overview ¶
Package qrp provides access to the exported methods of an object across a packet-based connection. QRP is designed to work with multiple packet-based protocols such as UDP and SCTP.
Firstly you must create a node using any of the network specific CreateNode? methods:
CreateNode CreateNodeUDP
e.g.
node, err := CreateNodeUDP("udp", ":50060", 512)
Nodes serve procedures. Procedures are installed using the Register function, which takes an object and registers the exported methods of that object.
type AddService struct {} type AddArgs struct { A, B int32 } type AddReply struct { Result int32 } func (s *AddService) Add(args *AddArgs, reply *AddReply) { reply.Result = args.A + args.B } node.Register(AddService{})
For more infomation on how to use QRP, see rpc_test.go. Most of this library follows the same standards in go/net/rpc.
For more information on the design of the protocol, see doc.go.
Index ¶
- type BadProcedureError
- type Connection
- type InvalidMessageError
- type InvalidMessageMappingError
- type Message
- type Node
- func (node *Node) Call(procedure string, addr net.Addr, args interface{}, reply interface{}, ...) (err error)
- func (node *Node) CallUDP(procedure string, addrString string, args interface{}, reply interface{}, ...) (err error)
- func (node *Node) ListenAndServe() (err error)
- func (node *Node) Register(receiver interface{}) error
- func (node *Node) Stop() error
- type Query
- type Reply
- type TimeoutError
- type UDPConn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BadProcedureError ¶
type BadProcedureError struct {
// contains filtered or unexported fields
}
func (*BadProcedureError) Error ¶
func (err *BadProcedureError) Error() string
type Connection ¶
type Connection interface { // QRP is inherently a packet-based protocol net.PacketConn // Reads the next packet from the connection and returns the buffer, bytes read and any errors // This is designed so we can work with multiple protocols, without having to specify buffer sizes ReadNextPacket() ([]byte, int, net.Addr, error) }
type InvalidMessageError ¶
type InvalidMessageError struct{}
func (*InvalidMessageError) Error ¶
func (err *InvalidMessageError) Error() string
type InvalidMessageMappingError ¶
type InvalidMessageMappingError struct {
// contains filtered or unexported fields
}
func (*InvalidMessageMappingError) Error ¶
func (err *InvalidMessageMappingError) Error() string
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Our local node
func CreateNode ¶
func CreateNode(connection Connection) (*Node, error)
Creates a node that performs IO on connection
func CreateNodeUDP ¶
Creates a node using UDP, returning an error if failure
func (*Node) Call ¶
func (node *Node) Call(procedure string, addr net.Addr, args interface{}, reply interface{}, timeout int) (err error)
Tries to call 'procedure' on remote node, with supplied 'args' and allocated return values 'reply'. 'timeout' can be used to specify a maximum time to wait for a reply (in seconds). If timeout is 0, we wait forever. The reliability of this completing successfully is dependent on the network protocol (UDP is unreliable) Returns an error if there is a timeout
func (*Node) CallUDP ¶
func (node *Node) CallUDP(procedure string, addrString string, args interface{}, reply interface{}, timeout int) (err error)
Calls a procedure on a node using the UDP protocol see Node.Call
func (*Node) ListenAndServe ¶
Listens for queries and replies, serving procedures registered by Register Returns an error if there was a failure serving or we are already serving
type Query ¶
type Query struct { ProcedureName string `bencode:"N"` // Name of the procedure being executed ProcedureData bencode.RawMessage `bencode:"D"` // Procedure argument(s) MessageID uint32 `bencode:"I"` // ID to make this transaction unique }
type Reply ¶
type Reply struct { ReturnData bencode.RawMessage `bencode:"D"` // Procedure return value(s) MessageID uint32 `bencode:"I"` // ID of query we are responding to }
type TimeoutError ¶
type TimeoutError struct{}
func (*TimeoutError) Error ¶
func (err *TimeoutError) Error() string