turn

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package turn contains the STUN/TURN server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeCampfireMessage added in v0.1.6

func DecodeCampfireMessage(p []byte) (*v1.CampfireMessage, error)

DecodeCampfireMessage decodes a campfire message.

func EncodeCampfireMessage added in v0.1.6

func EncodeCampfireMessage(msg *v1.CampfireMessage) ([]byte, error)

EncodeCampfireMessage encodes a campfire message.

func IsCampfireMessage added in v0.1.6

func IsCampfireMessage(p []byte) bool

IsCampfireMessage returns true if the given packet is a campfire message.

func NewCampfireManager added in v0.2.2

func NewCampfireManager(pc net.PacketConn, log *slog.Logger) *campfireManager

NewCampfireManager creates a new campfire manager.

func ValidateCampfireMessage added in v0.1.6

func ValidateCampfireMessage(msg *v1.CampfireMessage) error

ValidateCampfireMessage validates a campfire message.

Types

type CampfireAnswer added in v0.1.5

type CampfireAnswer struct {
	// ID contains the ID of the negotiation. This will always be the same as the client ID.
	ID string
	// Ufrag contains the username fragment of the peer that sent the answer.
	Ufrag string
	// Pwd contains the password of the peer that sent the answer.
	Pwd string
	// SDP contains the SDP of the answer.
	SDP webrtc.SessionDescription
}

CampfireAnswer represents an answer that was received from a peer.

type CampfireCandidate added in v0.1.5

type CampfireCandidate struct {
	// ID contains the ID of the peer that initiated the negotiation.
	ID string
	// Ufrag contains the username fragment of the peer that sent the candidate.
	Ufrag string
	// Pwd contains the password of the peer that sent the candidate.
	Pwd string
	// Cand contains the candidate.
	Cand webrtc.ICECandidateInit
}

CampfireCandidate represents a candidate that was received from a peer.

type CampfireClient added in v0.1.5

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

CampfireClient represents a client that can communicate with a TURN server supporting campfire.

func NewCampfireClient added in v0.1.5

func NewCampfireClient(opts CampfireClientOptions) (*CampfireClient, error)

NewCampfireClient creates a new CampfireClient.

func (*CampfireClient) Announce added in v0.1.5

func (c *CampfireClient) Announce(ufrag, pwd string) error

Announce announces interest in offers containing the given ufrag and pwd.

func (*CampfireClient) Answers added in v0.1.5

func (c *CampfireClient) Answers() <-chan CampfireAnswer

Answers returns a channel of answers received from peers.

func (*CampfireClient) Candidates added in v0.1.5

func (c *CampfireClient) Candidates() <-chan CampfireCandidate

Candidates returns a channel of candidates received from peers.

func (*CampfireClient) Close added in v0.1.5

func (c *CampfireClient) Close() error

Close closes the client.

func (*CampfireClient) Errors added in v0.1.5

func (c *CampfireClient) Errors() <-chan error

Errors returns a channel of errors.

func (*CampfireClient) Offers added in v0.1.5

func (c *CampfireClient) Offers() <-chan CampfireOffer

Offers returns a channel of offers received from peers.

func (*CampfireClient) SendAnswer added in v0.1.5

func (c *CampfireClient) SendAnswer(offerID, ufrag, pwd string, answer webrtc.SessionDescription) error

SendAnswer sends an answer to the peer with the given ufrag and pwd.

func (*CampfireClient) SendCandidate added in v0.1.5

func (c *CampfireClient) SendCandidate(offerID, ufrag, pwd string, candidate *webrtc.ICECandidate) error

SendCandidate sends a candidate to the peer with the given ufrag and pwd. If offerID is empty, the local ID is used.

func (*CampfireClient) SendOffer added in v0.1.5

func (c *CampfireClient) SendOffer(ufrag, pwd string, offer webrtc.SessionDescription) error

SendOffer sends an offer to the peer with the given ufrag and pwd.

type CampfireClientOptions added in v0.1.5

type CampfireClientOptions struct {
	// ID is a unique identifier for the client. If left unset, a random ID will be
	// generated.
	ID string
	// Addr is the address of the STUN/TURN server.
	Addr string
	// Ufrag is the username fragment to use when communicating with the server.
	Ufrag string
	// Pwd is the password to use when communicating with the server.
	Pwd string
	// PSK is the pre-shared key used for encrypting/decrypting the data in sent/received
	// messages.
	PSK []byte
}

CampfireClientOptions represents options for a CampfireClient.

type CampfireOffer added in v0.1.5

type CampfireOffer struct {
	// ID contains the ID of the peer that sent the offer.
	ID string
	// Ufrag contains the username fragment of the peer that sent the offer.
	Ufrag string
	// Pwd contains the password of the peer that sent the offer.
	Pwd string
	// SDP contains the SDP of the offer.
	SDP webrtc.SessionDescription
}

CampfireOffer represents an offer that was received from a peer.

type Options

type Options struct {
	// PublicIP is the public IP address of the TURN server. This is used for relaying.
	PublicIP string
	// RelayAddressUDP is the binding address the TURN server uses for request handling and STUN relays.
	// Defaults to 0.0.0.0.
	RelayAddressUDP string
	// ListenUDP is the address the TURN server listens on for UDP requests.
	ListenUDP string
	// ListenTCP is the address the TURN server listens on for TCP requests.
	ListenTCP string
	// Realm is the realm used for authentication.
	Realm string
	// PortRange is the range of ports the TURN server will use for relaying.
	PortRange string
	// EnableCampfire enables relaying campfire packets.
	EnableCampfire bool
	// EnableCampfireWebsockets enables relaying campfire packets over websockets.
	// If ListenTCP is not set, ListenUDP will be used.
	EnableCampfireWebsockets bool
	// TLSCertFile is the path to the TLS certificate file when serving the TURN server over TLS.
	TLSCertFile string
	// TLSKeyFile is the path to the TLS key file when serving the TURN server over TLS.
	TLSKeyFile string
}

Options contains the options for the TURN server.

type Server

type Server struct {
	*turn.Server
	// contains filtered or unexported fields
}

Server is a TURN server.

func NewServer

func NewServer(o *Options) (*Server, error)

NewServer creates and starts a new TURN server.

func (*Server) Close added in v0.2.2

func (s *Server) Close() error

func (*Server) ListenPort added in v0.1.12

func (s *Server) ListenPort() int

ListenPort returns the UDP port the TURN server is listening on.

Jump to

Keyboard shortcuts

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