Documentation ¶
Index ¶
- Variables
- func IsTemporary(err error) bool
- type BinaryMarshaler
- type BinaryUnmarshaler
- type Conn
- type FaultyHost
- type GoConn
- func (c *GoConn) Close()
- func (c *GoConn) Closed() bool
- func (c *GoConn) Connect() error
- func (c *GoConn) Get(bum BinaryUnmarshaler) error
- func (c *GoConn) Name() string
- func (c *GoConn) PubKey() abstract.Point
- func (c *GoConn) Put(data BinaryMarshaler) error
- func (c *GoConn) SetPubKey(pk abstract.Point)
- type GoDirectory
- type GoHost
- func (h *GoHost) AddChildren(view int, cs ...string)
- func (h *GoHost) AddParent(view int, c string)
- func (h *GoHost) AddPeerToHostlist(view int, name string)
- func (h *GoHost) AddPeerToPending(p string)
- func (h *GoHost) AddPeers(cs ...string)
- func (h *GoHost) AddPendingPeer(view int, name string) error
- func (h *GoHost) Children(view int) map[string]Conn
- func (h *GoHost) Close()
- func (h *GoHost) Closed() bool
- func (h *GoHost) Connect(view int) error
- func (h *GoHost) ConnectTo(parent string) error
- func (h *GoHost) Get() chan NetworkMessg
- func (h *GoHost) GetDirectory() *GoDirectory
- func (h *GoHost) HostListOn(view int) []string
- func (h *GoHost) IsChild(view int, peer string) bool
- func (h *GoHost) IsParent(view int, peer string) bool
- func (h *GoHost) IsRoot(view int) bool
- func (h *GoHost) Listen() error
- func (h *GoHost) NChildren(view int) int
- func (h *GoHost) Name() string
- func (h *GoHost) NewView(view int, parent string, children []string, hoslist []string)
- func (h *GoHost) NewViewFromPrev(view int, parent string)
- func (h *GoHost) Parent(view int) string
- func (h *GoHost) Peers() map[string]Conn
- func (h *GoHost) Pending() map[string]bool
- func (h *GoHost) Pool() *sync.Pool
- func (h *GoHost) PubKey() abstract.Point
- func (h *GoHost) PutDown(ctx context.Context, view int, data []BinaryMarshaler) error
- func (h *GoHost) PutTo(ctx context.Context, host string, data BinaryMarshaler) error
- func (h *GoHost) PutUp(ctx context.Context, view int, data BinaryMarshaler) error
- func (h *GoHost) RemovePeer(view int, name string) bool
- func (h *GoHost) RemovePeerFromHostlist(view int, name string)
- func (h *GoHost) RemovePendingPeer(peer string)
- func (h *GoHost) SetHostList(view int, hostlist []string)
- func (h *GoHost) SetPool(p *sync.Pool)
- func (h *GoHost) SetPubKey(pk abstract.Point)
- func (h *GoHost) SetSuite(s abstract.Suite)
- func (h *GoHost) Views() *Views
- type Host
- type HostState
- type NetworkMessg
- type StringMarshaler
- type TCPConn
- func (tc *TCPConn) Close()
- func (tc *TCPConn) Closed() bool
- func (tc *TCPConn) Connect() error
- func (tc *TCPConn) Get(bum BinaryUnmarshaler) error
- func (tc *TCPConn) Name() string
- func (tc *TCPConn) PubKey() abstract.Point
- func (tc *TCPConn) Put(bm BinaryMarshaler) error
- func (tc *TCPConn) SetName(name string)
- func (tc *TCPConn) SetPubKey(pk abstract.Point)
- type TCPHost
- func (h *TCPHost) AddChildren(view int, cs ...string)
- func (h *TCPHost) AddParent(view int, c string)
- func (h *TCPHost) AddPeerToHostlist(view int, name string)
- func (h *TCPHost) AddPeerToPending(p string)
- func (h *TCPHost) AddPeers(cs ...string)
- func (h *TCPHost) AddPendingPeer(view int, name string) error
- func (h *TCPHost) Children(view int) map[string]Conn
- func (h *TCPHost) Close()
- func (h *TCPHost) Closed() bool
- func (h *TCPHost) Connect(view int) error
- func (h *TCPHost) ConnectTo(parent string) error
- func (h *TCPHost) Get() chan NetworkMessg
- func (h *TCPHost) HostListOn(view int) []string
- func (h *TCPHost) IsChild(view int, peer string) bool
- func (h *TCPHost) IsParent(view int, peer string) bool
- func (h *TCPHost) IsRoot(view int) bool
- func (h *TCPHost) Listen() error
- func (h *TCPHost) NChildren(view int) int
- func (h *TCPHost) Name() string
- func (h *TCPHost) NewView(view int, parent string, children []string, hostlist []string)
- func (h *TCPHost) NewViewFromPrev(view int, parent string)
- func (h *TCPHost) Parent(view int) string
- func (h *TCPHost) Peers() map[string]Conn
- func (h *TCPHost) Pending() map[string]bool
- func (h *TCPHost) Pool() *sync.Pool
- func (h *TCPHost) PubKey() abstract.Point
- func (h *TCPHost) PutDown(ctx context.Context, view int, data []BinaryMarshaler) error
- func (h *TCPHost) PutTo(ctx context.Context, host string, data BinaryMarshaler) error
- func (h *TCPHost) PutUp(ctx context.Context, view int, data BinaryMarshaler) error
- func (h *TCPHost) RemovePeer(view int, name string) bool
- func (h *TCPHost) RemovePeerFromHostlist(view int, name string)
- func (h *TCPHost) RemovePendingPeer(peer string)
- func (h *TCPHost) SetHostList(view int, hostlist []string)
- func (h *TCPHost) SetPool(p *sync.Pool)
- func (h *TCPHost) SetPubKey(pk abstract.Point)
- func (h *TCPHost) SetSuite(s abstract.Suite)
- func (h *TCPHost) Views() *Views
- type View
- func (v *View) AddChildren(children ...string)
- func (v *View) AddParent(parent string)
- func (v *View) AddPeerToHostlist(name string)
- func (v *View) RemoveChild(child string) bool
- func (v *View) RemovePeer(name string) bool
- func (v *View) RemovePeerFromHostlist(name string)
- func (v *View) SetHostList(hostlist []string)
- type Views
- func (v *Views) AddChildren(view int, children ...string)
- func (v *Views) AddParent(view int, parent string)
- func (vs *Views) AddPeerToHostlist(view int, name string)
- func (v *Views) Children(view int) []string
- func (v *Views) HostList(view int) []string
- func (v *Views) NChildren(view int) int
- func (v *Views) NewView(view int, parent string, children []string, hostlist []string)
- func (v *Views) NewViewFromPrev(view int, parent string)
- func (v *Views) Parent(view int) string
- func (v *Views) RemoveChild(view int, child string)
- func (v *Views) RemovePeer(view int, child string) bool
- func (vs *Views) RemovePeerFromHostlist(view int, name string)
- func (v *Views) SetHostList(view int, hostlist []string)
Constants ¶
This section is empty.
Variables ¶
var ErrClosed = errors.New("connection closed")
ErrClosed indicates that the connection has been closed.
var ErrNotEstablished = errors.New("connection not established")
ErrNotEstablished indicates that the connection has not been successfully established through a call to Connect yet. It does not indicate whether the failure was permanent or temporary.
var ErrPeerExists = errors.New("peer already exists in given directory")
ErrPeerExists is an ignorable error that says that this peer has already been registered to this directory.
var Latency = 100
Functions ¶
func IsTemporary ¶
IsTemporary returns true if it is a temporary error.
Types ¶
type BinaryMarshaler ¶
Taken from: http://golang.org/pkg/encoding/#BinaryMarshaler All messages passing through our conn must implement their own BinaryMarshaler
type BinaryUnmarshaler ¶
Taken from: http://golang.org/pkg/encoding/#BinaryMarshaler All messages passing through our conn must implement their own BinaryUnmarshaler
type Conn ¶
type Conn interface { // Name returns the name of the "to" end of the connectio. Name() string // PubKey returns the public key associated with the peer. PubKey() abstract.Point SetPubKey(abstract.Point) // Put puts data to the connection, calling the MarshalBinary method as needed. Put(data BinaryMarshaler) error // Get gets data from the connection, calling the UnmarshalBinary method as needed. // It blocks until it successfully receives data or there was a network error. // It returns io.EOF if the channel has been closed. Get(data BinaryUnmarshaler) error // Connect establishes the connection. Before using the Put and Get // methods of a Conn, Connect must first be called. Connect() error // Close closes the connection. Any blocked Put or Get operations will // be unblocked and return errors. Close() // Indicates whether the connection has been closed Closed() bool }
Conn is an abstract bidirectonal connection. It abstracts away the network layer as well as the data-format for communication.
type FaultyHost ¶
type FaultyHost struct { Host State HostState // DeadFor[x]=true is Host muslt play dead when x occurs // ex: DeadFor["commit"] is set true if host must fail on commit DeadFor map[string]bool }
func NewFaultyHost ¶
func NewFaultyHost(host Host, state ...HostState) *FaultyHost
func (*FaultyHost) Die ¶
func (fh *FaultyHost) Die()
func (*FaultyHost) IsDead ¶
func (fh *FaultyHost) IsDead() bool
returns true is host has failed (for simulating failures)
func (*FaultyHost) IsDeadFor ¶
func (fh *FaultyHost) IsDeadFor(x string) bool
returns true is host should play dead in a specific case ex: DeadFor["commit"] is set true if host must fail on commit
func (*FaultyHost) SetDeadFor ¶
func (fh *FaultyHost) SetDeadFor(x string, val bool)
ex: DeadFor["commit"] is set true if host must fail on commit
type GoConn ¶
type GoConn struct {
// contains filtered or unexported fields
}
GoConn implements the Conn interface. It emulates connections by using channels. uses channels for communication.
func NewGoConn ¶
func NewGoConn(dir *GoDirectory, from, to string) (*GoConn, error)
NewGoConn creates a GoConn registered in the given directory with the given hostname. It returns an ignorable ErrPeerExists error if this peer already exists.
func (*GoConn) Get ¶
func (c *GoConn) Get(bum BinaryUnmarshaler) error
Get receives data from the sender.
func (*GoConn) Name ¶
Name implements the Conn Name interface. It returns the To end of the connection.
func (*GoConn) Put ¶
func (c *GoConn) Put(data BinaryMarshaler) error
Put puts data on the connection.
type GoDirectory ¶
type GoDirectory struct { // protects accesses to channel and nameToPeer sync.RWMutex // contains filtered or unexported fields }
GoDirectory is a testing structure for the goConn. It allows us to simulate tcp network connections locally (and is easily adaptable for network connections). A single directory should be shared between all goConns's that are operating in the same network 'space'. If they are on the same tree they should share a directory.
func NewGoDirectory ¶
func NewGoDirectory() *GoDirectory
NewGoDirectory creates a new directory for registering GoConns.
func (*GoDirectory) Close ¶
func (d *GoDirectory) Close()
type GoHost ¶
type GoHost struct { PeerLock sync.RWMutex Ready map[string]bool // Peers asking to join overall tree structure of nodes // via connection to current host node PendingPeers map[string]bool Pubkey abstract.Point // own public key // contains filtered or unexported fields }
GoHost is an implementation of the Host interface, that uses GoConns as its underlying connection type.
func NewGoHost ¶
func NewGoHost(hostname string, dir *GoDirectory) *GoHost
NewGoHost creates a new GoHost with the given hostname, and registers it in the given directory.
func (*GoHost) AddChildren ¶
AddChildren adds children to the specified view.
func (*GoHost) AddPeerToHostlist ¶
func (*GoHost) AddPeerToPending ¶
func (*GoHost) Get ¶
func (h *GoHost) Get() chan NetworkMessg
Get returns two channels. One of messages that are received, and another of errors associated with each message.
func (*GoHost) GetDirectory ¶
func (h *GoHost) GetDirectory() *GoDirectory
GetDirectory returns the underlying directory used for GoHosts.
func (*GoHost) HostListOn ¶
func (*GoHost) NewView ¶
NewView creates a new view with the given view number, parent, and children.
func (*GoHost) NewViewFromPrev ¶
func (*GoHost) Pool ¶
Pool returns the underlying pool of objects for creating new BinaryUnmarshalers, when Getting from network connections.
func (*GoHost) PutDown ¶
PutDown sends messages to its children on the given view, potentially timing out.
func (*GoHost) PutUp ¶
PutUp sends a message to the parent on the given view, potentially timing out.
func (*GoHost) RemovePeerFromHostlist ¶
func (*GoHost) RemovePendingPeer ¶
func (*GoHost) SetHostList ¶
func (*GoHost) SetPool ¶
SetPool sets the pool of underlying objects for creating new BinaryUnmarshalers, when Getting from network connections.
type Host ¶
type Host interface { // Name returns the name of this host. Name() string Parent(view int) string // Peers returns a mapping from peer names to Connections. Peers() map[string]Conn // AddPeers adds new peers to the host, but does not make it either child or parent. AddPeers(hostnames ...string) // NewView creates a NewView to operate on. // It creates a view with the given view number, which corresponds to the tree // with the specified parent and children. NewView(view int, parent string, children []string, hostlist []string) NewViewFromPrev(view int, parent string) // Returns map of this host's views Views() *Views // AddParent adds a parent to the view specified. // Used for building a view incrementally. AddParent(view int, hostname string) // AddChildren adds children to the view specified. // Used for building a view incrementally. AddChildren(view int, hostname ...string) // NChildren returns the number of children for the given view. NChildren(view int) int // Children returns the children for a given view. Children(view int) map[string]Conn // Returns list of hosts available on a specific view HostListOn(view int) []string // Set the hoslist on a specific view SetHostList(view int, hostlist []string) // IsRoot returns true if this host is the root for the given view. IsRoot(view int) bool // IsParent returns true if the given peer is the parent for a specified view. IsParent(view int, peer string) bool // IsChild returns true if the given peer is the child for a specified view. IsChild(view int, peer string) bool // PutUp puts the given data up to the parent in the specified view. // The context is used to timeout the request. PutUp(ctx context.Context, view int, data BinaryMarshaler) error // PutDown puts the given data down to the children in the specified view. // The context is used to timeout the request. PutDown(ctx context.Context, view int, data []BinaryMarshaler) error PutTo(ctx context.Context, host string, data BinaryMarshaler) error // Get returns a channel on which all received messages will be put. // It always returns a reference to the same channel. // Multiple listeners will receive disjoint sets of messages. // When receiving from the channels always recieve from both the network // messages channel as well as the error channel. Get() chan NetworkMessg // Connect connects to the parent in the given view. Connect(view int) error ConnectTo(host string) error // Listen listens for incoming connections. Listen() error // Close closes all the connections in the Host. Close() // SetSuite sets the suite to use for the Host. SetSuite(abstract.Suite) // PubKey returns the public key of the Host. PubKey() abstract.Point // SetPubKey sets the public key of the Host. SetPubKey(abstract.Point) // Pool is a pool of BinaryUnmarshallers to use when generating NetworkMessg's. Pool() *sync.Pool // SetPool sets the pool of the Host. SetPool(*sync.Pool) // Functions to allow group evolution AddPeerToPending(h string) AddPendingPeer(view int, name string) error RemovePeer(view int, name string) bool Pending() map[string]bool AddPeerToHostlist(view int, name string) RemovePeerFromHostlist(view int, name string) }
Host is an abstract node on the Host tree. Representing this tree, it has the ability to PutUp and PutDown to its parent and children respectively. It also can Get from all its connections. It is up to the caller to de-multiplex the messages sent back from Get.
A Host also implements multiple views of this tree. Each view is a unique tree (parent, children) configuration. Applications using Hosts can specify which view to use for operations.
type NetworkMessg ¶
type NetworkMessg struct { Data BinaryUnmarshaler // data From string // name of server data came from Err error }
func (*NetworkMessg) MarshalBinary ¶
func (nm *NetworkMessg) MarshalBinary() ([]byte, error)
func (*NetworkMessg) UnmarshalBinary ¶
func (nm *NetworkMessg) UnmarshalBinary(data []byte) error
type StringMarshaler ¶
type StringMarshaler string
StringMarshaler is a wrapper type to allow strings to be marshalled and unmarshalled.
func (*StringMarshaler) MarshalBinary ¶
func (s *StringMarshaler) MarshalBinary() ([]byte, error)
MarshalBinary implements the BinaryMarshaler interface for the StringMarshaler.
func (*StringMarshaler) UnmarshalBinary ¶
func (s *StringMarshaler) UnmarshalBinary(b []byte) error
UnmarshalBinary implements the BinaryUnmarshaler interface for the StringMarshaler.
type TCPConn ¶
type TCPConn struct {
// contains filtered or unexported fields
}
TCPConn is an implementation of the Conn interface for TCP network connections.
func NewTCPConn ¶
NewTCPConn takes a hostname and creates TCPConn. Before calling Get or Put Connect must first be called to establish the connection.
func NewTCPConnFromNet ¶
NewTCPConnFromNet wraps a net.Conn creating a new TCPConn using conn as the underlying connection. After creating a TCPConn in this fashion, it might be necessary to call SetName, in order to give it an understandable name.
func (*TCPConn) Get ¶
func (tc *TCPConn) Get(bum BinaryUnmarshaler) error
Get gets data from the connection. Returns io.EOF on an irrecoveralbe error. Returns given error if it is Temporary.
func (*TCPConn) Put ¶
func (tc *TCPConn) Put(bm BinaryMarshaler) error
Put puts data to the connection. Returns io.EOF on an irrecoverable error. Returns actual error if it is Temporary.
type TCPHost ¶
type TCPHost struct { PeerLock sync.RWMutex Ready map[string]bool // Peers asking to join overall tree structure of nodes // via connection to current host node PendingPeers map[string]bool Pubkey abstract.Point // own public key // contains filtered or unexported fields }
func NewTCPHost ¶
NewTCPHost creates a new TCPHost with a given hostname.
func (*TCPHost) AddChildren ¶
AddChildren adds children to the specified view.
func (*TCPHost) AddPeerToHostlist ¶
func (*TCPHost) AddPeerToPending ¶
func (*TCPHost) Connect ¶
Connect connects to the parent in the given view. It connects to the parent by establishing a TCPConn. It then sends its name and public key to initialize the connection.
func (*TCPHost) Get ¶
func (h *TCPHost) Get() chan NetworkMessg
Get gets from all of the Peers and sends the responses to a channel of NetworkMessg and errors that it returns.
TODO: each of these goroutines could be spawned when we initally connect to them instead.
func (*TCPHost) HostListOn ¶
func (*TCPHost) IsChild ¶
IsChild returns true f the given peer is the child for the specified view.
func (*TCPHost) IsParent ¶
IsParent returns true if the given peer is the parent for the specified view.
func (*TCPHost) IsRoot ¶
IsRoot returns true if the TCPHost is the root of it's tree for the given view..
func (*TCPHost) Listen ¶
Listen listens for incoming TCP connections. It is a non-blocking call that runs in the background. It accepts incoming connections and establishes Peers. When a peer attempts to connect it must send over its name (as a StringMarshaler), as well as its public key. Only after that point can be communicated with.
func (*TCPHost) NewView ¶
NewView creates a new view with the given view number, parent and children.
func (*TCPHost) NewViewFromPrev ¶
func (*TCPHost) PutDown ¶
PutDown sends a message (an interface{} value) up to all children through whatever 'network' interface each child Peer implements.