Documentation ¶
Overview ¶
This package deals with UDP broadcasting to automatically discover peers and connect to them. If you see references to the "Discovery" protocol, it's this package.
Background ¶
The Pikonet discovery protocol is a simple protocol operating on port 28779.
All messages have a 4 byte "PIKO" header, a one byte command type, and then a payload of arbitrary length. Messages should be sent to the appropriate broadcast address.
The protocol was created to allow efficient automatic configuration on private networks without telling the outside world. It allows communication across the same network as without it, it would be impossible to communicate with another device on the same network ordinarily.
It was not created for security, and it could lead to denial of service; these problems *may* be solved in the future but not necessarily will be solved.
Index ¶
Constants ¶
const ( // 0x01 - Hello // Broadcasts your existance on the network. // // Payload: // - uint16: Listening port for WireGuard // - [44]byte: Base64 WireGuard public key. Hello = 0x01 // 0x02 - Hello Reply // Broadcasts your existance on the network. // // The payload of this is the same as 0x01 Hello; this type explicitly // marks this message as a reply to an earlier Hello message. // Send these as a reply to 0x01, and not in any other case. // // Payload: // - uint16: Listening port for WireGuard // - [44]byte: Base64 WireGuard public key. HelloReply = 0x02 )
Discovery message commands.
const (
// The port that Discovery communicates on.
Port = 28779
)
Variables ¶
var ( // Multicast IP for Discovery communication. // // Previously this was 239.112.110.100, but due to Windows being // Windows, it was changed to piggyback off of the SSDP address. // // To anyne who's reading this: please let me know if you have a fix // that I can do easily and programmatically that would let me // uncomment this line: // IP = net.IPv4(239, 112, 110, 100) IP = net.IPv4(239, 255, 255, 250) // IP and Port combined into a UDPAddr. Address = &net.UDPAddr{ IP: IP, Port: Port, } )
Functions ¶
Types ¶
type Discovery ¶
type Discovery struct { // Ready is a channel that is closed when messages are ready to be sent // or received. Ready chan struct{} // Notify is a function that is called upon receiving a Discovery // message. Notify func(addr *net.UDPAddr, m Message) // contains filtered or unexported fields }
Discovery holds state for local peer discovery.