Documentation ¶
Overview ¶
Package ezmesh wraps github.com/weaveworks/mesh into a more user-friendly library
Index ¶
- Constants
- type Config
- type Logger
- type Peer
- func (p *Peer) Broadcast(message []byte)
- func (p *Peer) Connect(addrs []*net.TCPAddr) []error
- func (p *Peer) NickNameFromPeerName(name PeerName) (nickname string, ok bool)
- func (p *Peer) PeerNameFromNickName(nickname string) (name PeerName, ok bool)
- func (p *Peer) Send(dst PeerName, message []byte) error
- type PeerName
Constants ¶
const PROTOVERSION = 2
PROTOVERSION is the protocol version used by this package.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // Address and Port specify the IP address and port on which to listen // for connections from other peers. The address may be the empty // string, in which case a listener won't be started. Address string Port uint16 // Key provides an encryption key which must be the same for all peers. Key []byte // AutoConnect controls whether or not connections are automatically // attempted to other peers. AutoConnect bool // ConnLimit specifies the maximum number of peer connections. A value // <= 0 allows unlimited connections. ConnLimit int // Nickname is the human-friendly name by which this peer will be known. NickName string // Name is the 8-byte name which represents this peer. It is common // to use a MAC address (via PeerNameFromHardwareAddr). If Name is // nil, it will be generated from NickName. Name *PeerName // InitialPeers is a slice of addresses containing other peers to which // to connect. This slice may be empty. More peers may be added with // Peer's Connect method. InitialPeers []*net.TCPAddr // OnMessage sets the OnMessage field in the generated Peer OnMessage func(p *Peer, src PeerName, message []byte) error // OnBroadcast sets the OnBroadcast field in the generated Peer OnBroadcast func(p *Peer, src PeerName, message []byte) error }
Config contains parameters needed to connect to the mesh network.
type Logger ¶
type Logger interface {
Printf(format string, args ...interface{})
}
Logger is a simple logging interface. It can be satisfied by *log.Logger.
type Peer ¶
type Peer struct { // OnMessage is called when a unicast (peer-to-peer) message is // received, if it is not nil. A pointer to this struct is passed in. OnMessage func(p *Peer, src PeerName, message []byte) error // OnBroadcast is called when a broadcast (peer-to-everybody) message // is received, if it is not nil. A pointer to this struct is passed // in. OnBroadcast func(p *Peer, src PeerName, message []byte) error // The following provide access to the underlying mesh structures. // Please see https://godoc.org/github.com/weaveworks/mesh for more // information. TX mesh.Gossip RX mesh.Gossiper Router *mesh.Router }
Peer represents the local peer in the mesh network.
func New ¶
New creates a new peer joined to the mesh network. The returned slice of errors will only contain errors from the initial connections. If there are fewer errors than initial peers, then at least one connection succeeded. Even if all of the initial connections failed, the returned *Peer's Connect method may be used to attempt more connections.
The returned error is non-nil if the returned peer is unusable.
Unfortunately, due to the underlying library, there's no good way to know if listening for connections succeeded.
func (*Peer) Connect ¶
Connect makes connections to the given addresses. Please see New for the meaning of the returned error slice.
func (*Peer) NickNameFromPeerName ¶
NickNameFromPeerName returns the NickName of the peer in the peer mesh with the given PeerName. It is an O(n) operation over the set of known peers. If the name is not found, ok will be false.
func (*Peer) PeerNameFromNickName ¶
PeerNameFromNickName returns the PeerName of a peer in the mesh network from with the given NickName. It is an O(n) operation over the set of known peers. If the NickName is not found, ok will be false.
type PeerName ¶
type PeerName uint64
PeerName uniquely identifies a peer in the mesh network. It is common to use the peer's network adapter's MAC address. Only the lower six bytes are used.
func PeerNameFromHardwareAddr ¶
func PeerNameFromHardwareAddr(h net.HardwareAddr) (PeerName, error)
PeerNameFromHardwareAddr return a PeerName made from the given hardware address.
func PeerNameFromMACAddr ¶
PeerNameFromMACAddr transforms a MAC address (or any other colon-separated series of hex-encoded bytes) into a PeerName. Contiguous 0x00's may be elided, as in IPv6 addresses. At most 6 colon-separated hex-encoded bytes may be turned into a PeerName. This is a wrapper around mesh.PeerNameFromString.
func PeerNameFromStringHash ¶
PeerNameFromStringHash transforms s into a PeerName using the first 8 bytes of the SHA512 hash of the string.
func RandomPeerName ¶
RandomPeerName generates a random PeerName.
func UnStringPeerName ¶
UnStringPeerName reverses the output of PeerName's String() method. It accepts a hex-digits-and-colon name.