meshconn

package
v0.0.0-...-dc2e7af Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2017 License: Apache-2.0 Imports: 7 Imported by: 0

README

meshconn

meshconn implements net.PacketConn on top of mesh. Think of it as UDP with benefits: NAT and bastion host (DMZ) traversal, broadcast/multicast in networks where this is normally not possible e.g. EC2, and an up-to-date, queryable memberlist.

meshconn supports net.Addr of the form weavemesh://<PeerName>. By default, <PeerName> is a hardware address of the form 01:02:03:FD:FE:FF. Other forms of PeerName e.g. hashes are supported.

meshconn itself is largely stateless and has best-effort delivery semantics. As a future experiment, it could easily be amended to have basic resiliency guarantees. Also, at the moment, PacketConn read and write deadlines are not supported.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrShortRead is returned by ReadFrom when the
	// passed buffer is too small for the packet.
	ErrShortRead = errors.New("short read")

	// ErrPeerClosed is returned by ReadFrom and WriteTo
	// when the peer is closed during the operation.
	ErrPeerClosed = errors.New("peer closed")

	// ErrGossipNotRegistered is returned by Write to when attempting
	// to write before a mesh.Gossip has been registered in the peer.
	ErrGossipNotRegistered = errors.New("gossip not registered")

	// ErrNotMeshAddr is returned by WriteTo when attempting
	// to write to a non-mesh address.
	ErrNotMeshAddr = errors.New("not a mesh addr")

	// ErrNotSupported is returned by methods that are not supported.
	ErrNotSupported = errors.New("not supported")
)

Functions

This section is empty.

Types

type MeshAddr

type MeshAddr struct {
	mesh.PeerName // stable across invocations
	mesh.PeerUID  // new with each invocation
}

MeshAddr implements net.Addr for mesh peers.

func (MeshAddr) Network

func (a MeshAddr) Network() string

Network returns weavemesh.

func (MeshAddr) String

func (a MeshAddr) String() string

String returns weavemesh://<PeerName>.

type Peer

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

Peer implements mesh.Gossiper and net.PacketConn.

func NewPeer

func NewPeer(name mesh.PeerName, uid mesh.PeerUID, logger mesh.Logger) *Peer

NewPeer returns a Peer, which can be used as a net.PacketConn. Clients must Register a mesh.Gossip before calling ReadFrom or WriteTo. Clients should aggressively consume from ReadFrom.

func (*Peer) Close

func (p *Peer) Close() error

Close implements net.PacketConn.

func (*Peer) Gossip

func (p *Peer) Gossip() (complete mesh.GossipData)

Gossip implements mesh.Gossiper.

func (*Peer) LocalAddr

func (p *Peer) LocalAddr() net.Addr

LocalAddr implements net.PacketConn.

func (*Peer) OnGossip

func (p *Peer) OnGossip(buf []byte) (delta mesh.GossipData, err error)

OnGossip implements mesh.Gossiper. The buf is a single pkt.

func (*Peer) OnGossipBroadcast

func (p *Peer) OnGossipBroadcast(_ mesh.PeerName, buf []byte) (received mesh.GossipData, err error)

OnGossipBroadcast implements mesh.Gossiper. The buf is a single pkt

func (*Peer) OnGossipUnicast

func (p *Peer) OnGossipUnicast(_ mesh.PeerName, buf []byte) error

OnGossipUnicast implements mesh.Gossiper. The buf is a single pkt.

func (*Peer) ReadFrom

func (p *Peer) ReadFrom(b []byte) (n int, remote net.Addr, err error)

ReadFrom implements net.PacketConn. Clients should consume from ReadFrom without blocking.

func (*Peer) Register

func (p *Peer) Register(gossip mesh.Gossip)

Register injects the mesh.Gossip and enables full-duplex communication. Clients should consume from ReadFrom without blocking.

func (*Peer) SetDeadline

func (p *Peer) SetDeadline(time.Time) error

SetDeadline implements net.PacketConn. SetDeadline is not supported.

func (*Peer) SetReadDeadline

func (p *Peer) SetReadDeadline(time.Time) error

SetReadDeadline implements net.PacketConn. SetReadDeadline is not supported.

func (*Peer) SetWriteDeadline

func (p *Peer) SetWriteDeadline(time.Time) error

SetWriteDeadline implements net.PacketConn. SetWriteDeadline is not supported.

func (*Peer) WriteTo

func (p *Peer) WriteTo(b []byte, dst net.Addr) (n int, err error)

WriteTo implements net.PacketConn.

Jump to

Keyboard shortcuts

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