sap

package module
v0.0.5-alpha Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2023 License: MIT Imports: 7 Imported by: 0

README

sap

Package sap provides SAP (Session Announcement Protocol) parsing compliant with RFC 2974

This package is still experimental, breaking changes can happen.

Usage

Get the Module go get github.com/openaudiocollective/sap

Use the NewPacket function to create a Packet or create it manually. Unmarshal the packet to a byte slice or Marshal the packet into a structured Packet object.

Check the examples folder

Documentation

Head to the documentation page for more information.

TODO

  • Encryption/Decryption
  • Compression
  • Authentication

Inspired by pion/sdp and pion/rtp. Thanks!

Documentation

Overview

Package sap provides SAP (Session Announcement Protocol) parsing

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeMsgIdHash

func ComputeMsgIdHash(payload []byte) uint16

Types

type AddressType

type AddressType uint8

If the origination source is from an IPv4 or IPv6 address

const (
	IPv4 AddressType = 0
	IPv6 AddressType = 1
)
type Header struct {
	// The version number field MUST be set to 1
	Version uint8

	// If the A bit is 0, the originating source field contains a 32-bit IPv4 address.
	// If the A bit is 1, the originating source contains a 128-bit IPv6 address.
	AddressType AddressType

	// SAP announcers MUST set this to 0, SAP listeners MUST ignore the contents of this field.
	Reserved uint8

	// If this bit is set to 0 this is a session announcement packet
	// If this bit is set to 1 this is a session deletion packet.
	MessageType MessageType

	// If the encryption bit is set to 1, the payload of the SAP packet is encrypted.
	// If this bit is 0 the packet is not encrypted.
	Encrypted uint8

	// If the compressed bit is set to 1, the payload is
	// compressed using the zlib compression algorithm (https://datatracker.ietf.org/doc/html/rfc2974#ref-3)
	Compressed uint8

	// An 8 bit unsigned quantity giving the number of 32 bit words following the main SAP header that contain aauthentication data.
	// If it is zero, no authentication header is present.
	AuthenticationLength uint8

	// Digital signature of the packet, with length as specified by the authentication length header field.
	AuthenticationData []uint32

	// A 16 bit quantity that, used in combination with the originating source, provides a globally unique identifier
	// indicating the precise version of this announcement.
	//
	// It MUST be unique for each session announced by a particular SAP announcer
	// and it MUST be changed if the session description is modified
	// (and a session deletion message SHOULD be sent for the old version of the session).
	//
	// SAP listeners MAY silently discard messages if the message
	// identifier hash is set to zero.
	MessageIDHash uint16

	// This gives the IP address of the original source
	// of the message.  This is an IPv4 address if the A field is set to
	// zero, else it is an IPv6 address. The address is stored in
	// network byte order.
	OriginatingSource net.IP

	// The payload type field is a MIME content type specifier, describing the format of the payload.
	//
	// This is a variable length ASCII text string, followed by a single zero byte (ASCII NUL).
	// The payload type SHOULD be included in all packets.
	// If the payload type is `application/sdp' both the payload type and its terminating zero byte MAY be omitted
	//
	// Technically, it is part of the Payload, but makes more sense to parse it with the rest of the header
	PayloadType string
}

Header represents an SAP packet header

func (Header) Clone

func (h Header) Clone() Header

Clone returns a deep copy of h.

func (Header) Marshal

func (h Header) Marshal() (buf []byte, err error)

Marshal serializes the header into bytes.

func (Header) MarshalSize

func (h Header) MarshalSize() int

MarshalSize returns the size of the header once marshaled.

func (Header) MarshalTo

func (h Header) MarshalTo(buf []byte) (n int, err error)

MarshalTo serializes the header and writes to the buffer. It returns the number of bytes read n and any error.

func (*Header) Unmarshal

func (h *Header) Unmarshal(buf []byte) error

Unmarshal parses the passed byte slice and stores the result in the Header.

type MessageType

type MessageType uint8

If this is an announcement or deletion packet

const (
	Announcement MessageType = 0
	Deletion     MessageType = 1
)

type Option

type Option func(*Header)

func WithMessageType

func WithMessageType(msgType MessageType) Option

Set the MessageType of the Header struct

func WithPayloadType

func WithPayloadType(payloadType string) Option

Set the PayloadType of the Header struct

type Packet

type Packet struct {
	Header
	Payload []byte
}

Packet represents an SAP Packet

func NewPacket

func NewPacket(payload []byte, originatingSource net.UDPAddr, opts ...Option) (Packet, error)

Factory function for creating a new SAP packet Creates an IPv4, unencrypted, uncompressed, unauthenticated, SAP/SDP announcement packet by default

func (Packet) Clone

func (p Packet) Clone() *Packet

Clone returns a deep copy of p.

func (Packet) Marshal

func (p Packet) Marshal() (buf []byte, err error)

Marshal serializes the packet into bytes.

func (Packet) MarshalSize

func (p Packet) MarshalSize() int

MarshalSize returns the size of the packet once marshaled.

func (Packet) MarshalTo

func (p Packet) MarshalTo(buf []byte) (n int, err error)

MarshalTo serializes the packet and writes to the buffer. It returns the number of bytes read and any error.

func (Packet) String

func (p Packet) String() string

String helps with debugging by printing packet information in a readable way

func (*Packet) Unmarshal

func (p *Packet) Unmarshal(buf []byte) error

Unmarshal parses the passed byte slice and stores the result in the Packet.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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