Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Discovered ¶
type Discovered struct { // Address is the local address of a discovered peer. Address string // Payload is the associated payload from discovered peer. Payload []byte Metadata *Metadata }
Discovered is the structure of the discovered peers, which holds their local address (port removed) and a payload if there is one.
func Discover ¶ added in v1.0.0
func Discover(settings ...Settings) (discoveries []Discovered, err error)
Discover will use the created settings to scan for LAN peers. It will return an array of the discovered peers and their associate payloads. It will not return broadcasts sent to itself.
func (Discovered) String ¶ added in v1.4.0
func (d Discovered) String() string
type IPVersion ¶ added in v1.3.0
type IPVersion uint
IPVersion specifies the version of the Internet Protocol to be used.
type Metadata ¶ added in v1.7.0
type Metadata struct {
Data interface{}
}
Metadata is the metadata associated with a discovered peer. To update the metadata, assign your own metadata to the Metadata.Data field. The metadata is not protected by a mutex, so you must do this yourself. The metadata update happens by pointer, to keep the library backwards compatible.
type NetPacketConn ¶ added in v1.5.0
type PacketConn4 ¶ added in v1.5.0
type PacketConn4 struct {
*ipv4.PacketConn
}
type PacketConn6 ¶ added in v1.5.0
type PacketConn6 struct {
*ipv6.PacketConn
}
func (PacketConn6) ReadFrom ¶ added in v1.5.0
ReadFrom wraps the ipv6 ReadFrom without a control message
func (PacketConn6) SetMulticastTTL ¶ added in v1.5.0
func (pc6 PacketConn6) SetMulticastTTL(i int) error
SetMulticastTTL wraps the hop limit of ipv6
type PeerDiscovery ¶
PeerDiscovery is the object that can do the discovery for finding LAN peers.
func NewPeerDiscovery ¶ added in v1.7.0
func NewPeerDiscovery(settings ...Settings) (pd *PeerDiscovery, err error)
func (*PeerDiscovery) ActivePeers ¶ added in v1.7.0
func (p *PeerDiscovery) ActivePeers() (peers []*PeerState)
func (*PeerDiscovery) Shutdown ¶ added in v1.7.0
func (p *PeerDiscovery) Shutdown()
type PeerState ¶ added in v1.7.0
type PeerState struct { Address string // contains filtered or unexported fields }
PeerState is the state of a peer that has been discovered. It contains the address of the peer, the last time it was seen, the last payload it sent, and the metadata associated with it. To update the metadata, assign your own metadata to the Metadata.Data field. The metadata is not protected by a mutex, so you must do this yourself.
type Settings ¶
type Settings struct { // Limit is the number of peers to discover, use < 1 for unlimited. Limit int // Port is the port to broadcast on (the peers must also broadcast using the same port). // The default port is 9999. Port string // MulticastAddress specifies the multicast address. // You should be able to use any of 224.0.0.0/4 or ff00::/8. // By default it uses the Simple Service Discovery Protocol // address (239.255.255.250 for IPv4 or ff02::c for IPv6). MulticastAddress string // Payload is the bytes that are sent out with each broadcast. Must be short. Payload []byte // PayloadFunc is the function that will be called to dynamically generate payload // before every broadcast. If this pointer is nil `Payload` field will be broadcasted instead. PayloadFunc func() []byte // Delay is the amount of time between broadcasts. The default delay is 1 second. Delay time.Duration // TimeLimit is the amount of time to spend discovering, if the limit is not reached. // A negative limit indiciates scanning until the limit was reached or, if an // unlimited scanning was requested, no timeout. // The default time limit is 10 seconds. TimeLimit time.Duration // StopChan is a channel to stop the peer discvoery immediatley after reception. StopChan chan struct{} // AllowSelf will allow discovery the local machine (default false) AllowSelf bool // DisableBroadcast will not allow sending out a broadcast DisableBroadcast bool // IPVersion specifies the version of the Internet Protocol (default IPv4) IPVersion IPVersion // Notify will be called each time a new peer was discovered. // The default is nil, which means no notification whatsoever. Notify func(Discovered) // NotifyLost will be called each time a peer was lost. // The default is nil, which means no notification whatsoever. // This function should not take too long to execute, as it is called // from the peer garbage collector. NotifyLost func(LostPeer) // contains filtered or unexported fields }
Settings are the settings that can be specified for doing peer discovery.