Documentation
¶
Overview ¶
Package tsnet is the network library support for tsync (discovery/registration and communication).
Index ¶
- Constants
- func GetInternetInterface(ctx context.Context, target string) (*net.Interface, *net.UDPAddr, error)
- func PeerKVSort(a, b smap.KV[Peer, PeerData]) int
- func PeerLess(a, b Peer) bool
- type Config
- type ConnectionStatus
- type Peer
- type PeerData
- type Server
- func (s *Server) ConnectToPeer(peer Peer) error
- func (s *Server) MCastMessageDecode(buf []byte) (string, string, int32, error)
- func (s *Server) MCastMessageSend(epoch int32) error
- func (s *Server) OurAddress() *net.UDPAddr
- func (s *Server) PeersCleanup()
- func (s *Server) Start(ctx context.Context) error
- func (s *Server) Stop()
- func (s *Server) Stopped() bool
- type Source
Constants ¶
View Source
const ( // BufSize is the max size of messages (safe size). // 576 byte IP packet - 60 byte IP header - 8 byte UDP header = 508 bytes. BufSize = 576 - 60 - 8 // DefaultTarget: which udp address we try by default to find our interface and ip. DefaultTarget = "8.8.8.8:53" DefaultBroadcastInterval = 1500 * time.Millisecond TimeFormat = "15:04:05.000" // time only + millis. DefaultPeerTimeout = 10 * time.Second DefaultDiscoveryPort = 29556 // "ts" in ascii. )
View Source
const ( DiscoveryMessageFormat = "tsync1 %q %s e %d" // name, public key, epoch ConnectMessageFormat = "connect1 %q %q" // requester_name, target_name AcceptMessageFormat = "accept1 %q" // target_name RejectMessageFormat = "reject1 %q %q" // target_name, reason DataMessageFormat = "data1 %q %s" // target_name, signed_data )
Variables ¶
This section is empty.
Functions ¶
func GetInternetInterface ¶
GetInternetInterface returns the interface used to reach a public IP (default route). Windows tend to pick somehow the wrong interface instead of listening to all/correct default one so we try to guess the right one by connecting to an external address.
func PeerKVSort ¶ added in v0.8.0
PeerKVSort sort function for slices.SortFunc of smap.KV[Peer, PeerData]. Sorts by IP, then name, then public key.
Types ¶
type Config ¶
type Config struct {
// Name to use, if empty hostname will be used.
Name string
Port int
Mcast string
// Which ip:port we try to resolve to find our address and interface.
Target string
// Callback called when a the Server Peers map has changed, a new peer is detected
// or old one removed or updated. Must not block for long or
// it will delay processing of incoming messages.
OnChange func(version uint64)
Identity *tcrypto.Identity // long term identity for this server
BaseBroadcastInterval time.Duration // default to 1.5s if 0
PeerTimeout time.Duration // default to 10s if 0
}
type ConnectionStatus ¶ added in v0.9.0
type ConnectionStatus int
const ( // NotLinked is the initial state once discovered. NotLinked ConnectionStatus = iota // SentConn is the state when a connection is being established. SentConn // ReceivedConn is the state when a connection request has been received. ReceivedConn // Connected is the state when a connection has been established. Connected // Failed is the state when a connection has failed. Failed )
type Server ¶
type Server struct {
// Our copy of the input config.
Config
Peers *smap.Map[Peer, PeerData]
Sources *smap.Map[Source, Peer] // maps ip,port to peer
// contains filtered or unexported fields
}
func (*Server) ConnectToPeer ¶ added in v0.9.0
ConnectToPeer initiates a connection to the specified peer.
func (*Server) MCastMessageDecode ¶ added in v0.9.0
func (*Server) MCastMessageSend ¶ added in v0.9.1
func (*Server) OurAddress ¶
func (*Server) PeersCleanup ¶ added in v0.5.0
func (s *Server) PeersCleanup()
Click to show internal directories.
Click to hide internal directories.