network

package
v0.0.0-...-058445b Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2014 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address struct {
	Host string
	Port uint16
	ID   Identifier
}

An Address couples an Identifier with its network address.

type Identifier

type Identifier byte

An Identifier uniquely identifies a participant on a host.

type Message

type Message struct {
	Dest Address
	Proc string
	Args interface{}
	Resp interface{}
}

A Message is for sending requests over the network. It consists of an Address and an RPC.

type RPCServer

type RPCServer struct {
	// contains filtered or unexported fields
}

An RPCServer handles all RPCs for a given hostname and port. It routes each RPC according to its Identifier. Objects must register themselves with the RPCServer in order to receive an Address. This implementation currently uses the JSON codec over TCP.

func NewRPCServer

func NewRPCServer(port uint16) (rpcs *RPCServer, err error)

NewRPCServer creates and initializes a server that listens for TCP connections on a specified port. It then spawns a serverHandler with a specified message. It is the caller's responsibility to close the TCP listener, via RPCServer.Close().

func (*RPCServer) Close

func (rpcs *RPCServer) Close()

Close closes the connection associated with the TCP server. This causes tcpServ.Accept() to return an err, ending the serverHandler process.

func (*RPCServer) LearnHostname

func (rpcs *RPCServer) LearnHostname() (err error)

LearnHostname determines the external IP of the RPCserver by asking an external source. This will be updated in the future to ask a Participant instead of a third-party service.

func (*RPCServer) Ping

func (rpcs *RPCServer) Ping(a Address) error

Ping calls the Participant.Ping method on the specified address. Note that neither Ping nor any of the SendMessage functions really need to be methods of RPCServer. This may change in the future.

func (*RPCServer) RegisterHandler

func (rpcs *RPCServer) RegisterHandler(handler interface{}) Address

RegisterHandler registers a message handler to the RPC server. The handler is assigned an Identifier, which is returned to the caller. The Identifier is appended to the service name before registration.

func (*RPCServer) SendAsyncMessage

func (rpcs *RPCServer) SendAsyncMessage(m Message) chan error

SendAsyncMessage (asynchronously) delivers a Message to its recipient. It returns a channel that will contain an error value when the request completes. Like SendMessage, it times out after 'timeout' seconds.

func (*RPCServer) SendMessage

func (rpcs *RPCServer) SendMessage(m Message) error

SendMessage synchronously delivers a Message to its recipient and returns any errors. It times out after waiting for 'timeout' seconds.

Jump to

Keyboard shortcuts

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