qrp

package module
v0.0.0-...-d0296b0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2012 License: GPL-3.0 Imports: 12 Imported by: 0

README

QRP: A simple packet-based RPC protocol

QRP is a simple packet-based RPC protocol. The design is based off KRPC (BitTorrent), and subsequent implementation is based off the net/rpc library of Go.

This project is licensed under GPLv3 to Liam (liamzebedee) Edwards-Playne.

View the documentation here and see an example in rpc_test.go

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

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 Message

type Message struct {
	Query *Query `bencode:"Q,omitempty"`
	Reply *Reply `bencode:"R,omitempty"`
}

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

func CreateNodeUDP(net, addr string, mtu int32) (*Node, error)

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

func (node *Node) ListenAndServe() (err error)

Listens for queries and replies, serving procedures registered by Register Returns an error if there was a failure serving or we are already serving

func (*Node) Register

func (node *Node) Register(receiver interface{}) error

Registers method as a procedure, which must satisfy the following conditions:

  • exported
  • has a receiver
  • two arguments, both pointers to exported structs
  • one return value, of type error

It returns an error if the method does not satisfy these conditions

func (*Node) Stop

func (node *Node) Stop() error

Stops the server. Returns an error if the server isn't running.

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

type UDPConn

type UDPConn struct {
	net.UDPConn
	// contains filtered or unexported fields
}

func (*UDPConn) ReadNextPacket

func (conn *UDPConn) ReadNextPacket() (buffer []byte, read int, addr net.Addr, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL