Documentation ¶
Index ¶
- Variables
- func Ping(addr Address) bool
- type Address
- type TCPServer
- func (tcps *TCPServer) AddPeer(addr Address) error
- func (tcps *TCPServer) Address() Address
- func (tcps *TCPServer) AddressBook() []Address
- func (tcps *TCPServer) Bootstrap() (err error)
- func (tcps *TCPServer) Broadcast(name string, arg, resp interface{})
- func (tcps *TCPServer) RandomPeer() Address
- func (tcps *TCPServer) RegisterRPC(name string, fn interface{}) error
- func (tcps *TCPServer) RemovePeer(addr Address) error
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoPeers = errors.New("no peers") // hard-coded addresses used when bootstrapping BootstrapPeers = []Address{ "23.239.14.98:9988", } )
Functions ¶
Types ¶
type Address ¶
type Address string
An Address contains the information needed to contact a peer over TCP.
func (Address) Call ¶
Call establishes a TCP connection to the Address, calls the provided function on it, and closes the connection.
type TCPServer ¶
type TCPServer struct { net.Listener // used to protect addressbook and handlerMap sync.RWMutex // contains filtered or unexported fields }
A TCPServer sends and receives messages. It also maintains an address book of peers to broadcast to and make requests of.
func NewTCPServer ¶
NewTCPServer creates a TCPServer that listens on the specified address.
func (*TCPServer) AddressBook ¶
AddressBook returns the server's address book as a slice.
func (*TCPServer) Bootstrap ¶
Bootstrap discovers the external IP of the TCPServer, requests peers from the initial peer list, and announces itself to those peers.
func (*TCPServer) RandomPeer ¶
RandomPeer selects and returns a random peer from the address book.
func (*TCPServer) RegisterRPC ¶
RegisterRPC registers a function as an RPC handler for a given identifier. The function must be one of four possible types:
func(net.Conn) error func(Type) (Type, error) func(Type) error func() (Type, error)
To call an RPC, use Address.RPC, supplying the same identifier given to RegisterRPC. Identifiers should always use PascalCase.
func (*TCPServer) RemovePeer ¶
Remove safely removes a peer from the address book.