sctp package - github.com/pion/sctp - Go Packages

Package sctp implements the SCTP spec

View Source

var (
	ErrChunk                         = errors.New("abort chunk, with following errors")
	ErrShutdownNonEstablished        = errors.New("shutdown called in non-established state")
	ErrAssociationClosedBeforeConn   = errors.New("association closed before connecting")
	ErrAssociationClosed             = errors.New("association closed")
	ErrSilentlyDiscard               = errors.New("silently discard")
	ErrInitNotStoredToSend           = errors.New("the init not stored to send")
	ErrCookieEchoNotStoredToSend     = errors.New("cookieEcho not stored to send")
	ErrSCTPPacketSourcePortZero      = errors.New("sctp packet must not have a source port of 0")
	ErrSCTPPacketDestinationPortZero = errors.New("sctp packet must not have a destination port of 0")
	ErrInitChunkBundled              = errors.New("init chunk must not be bundled with any other chunk")
	ErrInitChunkVerifyTagNotZero     = errors.New(
		"init chunk expects a verification tag of 0 on the packet when out-of-the-blue",
	)
	ErrHandleInitState            = errors.New("todo: handle Init when in state")
	ErrInitAckNoCookie            = errors.New("no cookie in InitAck")
	ErrInflightQueueTSNPop        = errors.New("unable to be popped from inflight queue TSN")
	ErrTSNRequestNotExist         = errors.New("requested non-existent TSN")
	ErrResetPacketInStateNotExist = errors.New("sending reset packet in non-established state")
	ErrParamterType               = errors.New("unexpected parameter type")
	ErrPayloadDataStateNotExist   = errors.New("sending payload data in non-established state")
	ErrChunkTypeUnhandled         = errors.New("unhandled chunk type")
	ErrHandshakeInitAck           = errors.New("handshake failed (INIT ACK)")
	ErrHandshakeCookieEcho        = errors.New("handshake failed (COOKIE ECHO)")
	ErrTooManyReconfigRequests    = errors.New("too many outstanding reconfig requests")
)

Association errors.

View Source

var (
	ErrChunkTypeNotAbort     = errors.New("ChunkType is not of type ABORT")
	ErrBuildAbortChunkFailed = errors.New("failed build Abort Chunk")
)

Abort chunk errors.

View Source

var (
	ErrChunkTypeNotCtError   = errors.New("ChunkType is not of type ctError")
	ErrBuildErrorChunkFailed = errors.New("failed build Error Chunk")
)

Error chunk errors.

Forward TSN chunk errors.

View Source

var (
	ErrChunkTypeNotHeartbeat      = errors.New("ChunkType is not of type HEARTBEAT")
	ErrHeartbeatNotLongEnoughInfo = errors.New("heartbeat is not long enough to contain Heartbeat Info")
	ErrParseParamTypeFailed       = errors.New("failed to parse param type")
	ErrHeartbeatParam             = errors.New("heartbeat should only have HEARTBEAT param")
	ErrHeartbeatChunkUnmarshal    = errors.New("failed unmarshalling param in Heartbeat Chunk")
	ErrHeartbeatMarshalNoInfo     = errors.New("heartbeat marshal requires exactly one Heartbeat Info parameter")
)

Heartbeat chunk errors.

View Source

var (
	
	ErrUnimplemented                = errors.New("unimplemented")
	ErrChunkTypeNotHeartbeatAck     = errors.New("chunk type is not of type HEARTBEAT ACK")
	ErrHeartbeatAckParams           = errors.New("heartbeat Ack must have one param")
	ErrHeartbeatAckNotHeartbeatInfo = errors.New("heartbeat Ack must have one param, and it should be a HeartbeatInfo")
	ErrHeartbeatAckMarshalParam     = errors.New("unable to marshal parameter for Heartbeat Ack")
)

Heartbeat ack chunk errors.

View Source

var (
	ErrChunkTypeNotTypeInit          = errors.New("ChunkType is not of type INIT")
	ErrChunkValueNotLongEnough       = errors.New("chunk Value isn't long enough for mandatory parameters exp")
	ErrChunkTypeInitFlagZero         = errors.New("ChunkType of type INIT flags must be all 0")
	ErrChunkTypeInitUnmarshalFailed  = errors.New("failed to unmarshal INIT body")
	ErrChunkTypeInitMarshalFailed    = errors.New("failed marshaling INIT common data")
	ErrChunkTypeInitInitateTagZero   = errors.New("ChunkType of type INIT ACK InitiateTag must not be 0")
	ErrInitInboundStreamRequestZero  = errors.New("INIT ACK inbound stream request must be > 0")
	ErrInitOutboundStreamRequestZero = errors.New("INIT ACK outbound stream request must be > 0")
	ErrInitAdvertisedReceiver1500    = errors.New("INIT ACK Advertised Receiver Window Credit (a_rwnd) must be >= 1500")
	ErrInitUnknownParam              = errors.New("INIT with unknown param")
)

Init chunk errors.

View Source

var (
	ErrChunkTypeNotInitAck              = errors.New("ChunkType is not of type INIT ACK")
	ErrChunkNotLongEnoughForParams      = errors.New("chunk Value isn't long enough for mandatory parameters exp")
	ErrChunkTypeInitAckFlagZero         = errors.New("ChunkType of type INIT ACK flags must be all 0")
	ErrInitAckUnmarshalFailed           = errors.New("failed to unmarshal INIT body")
	ErrInitCommonDataMarshalFailed      = errors.New("failed marshaling INIT common data")
	ErrChunkTypeInitAckInitateTagZero   = errors.New("ChunkType of type INIT ACK InitiateTag must not be 0")
	ErrInitAckInboundStreamRequestZero  = errors.New("INIT ACK inbound stream request must be > 0")
	ErrInitAckOutboundStreamRequestZero = errors.New("INIT ACK outbound stream request must be > 0")
	ErrInitAckAdvertisedReceiver1500    = errors.New("INIT ACK Advertised Receiver Window Credit (a_rwnd) must be >= 1500")
)

Init ack chunk errors.

View Source

var (
	ErrInitChunkParseParamTypeFailed = errors.New("failed to parse param type")
	ErrInitAckMarshalParam           = errors.New("unable to marshal parameter for INIT/INITACK")
)

Init chunk errors.

View Source

var (
	ErrChunkParseParamTypeFailed        = errors.New("failed to parse param type")
	ErrChunkMarshalParamAReconfigFailed = errors.New("unable to marshal parameter A for reconfig")
	ErrChunkMarshalParamBReconfigFailed = errors.New("unable to marshal parameter B for reconfig")
)

Reconfigure chunk errors.

View Source

var (
	ErrChunkTypeNotSack           = errors.New("ChunkType is not of type SACK")
	ErrSackSizeNotLargeEnoughInfo = errors.New("SACK Chunk size is not large enough to contain header")
	ErrSackSizeNotMatchPredicted  = errors.New("SACK Chunk size does not match predicted amount from header values")
)

Selective ack chunk errors.

View Source

var (
	ErrInvalidChunkSize     = errors.New("invalid chunk size")
	ErrChunkTypeNotShutdown = errors.New("ChunkType is not of type SHUTDOWN")
)

Shutdown chunk errors.

SCTP chunk header errors.

View Source

var (
	ErrPacketRawTooSmall           = errors.New("raw is smaller than the minimum length for a SCTP packet")
	ErrParseSCTPChunkNotEnoughData = errors.New("unable to parse SCTP chunk, not enough data for complete header")
	ErrUnmarshalUnknownChunkType   = errors.New("failed to unmarshal, contains unknown chunk type")
	ErrChecksumMismatch            = errors.New("checksum mismatch theirs")
)

SCTP packet errors.

Parameter header parse errors.

View Source

var (
	ErrUnexpectedChunkPoppedUnordered = errors.New("unexpected chunk popped (unordered)")
	ErrUnexpectedChunkPoppedOrdered   = errors.New("unexpected chunk popped (ordered)")
	ErrUnexpectedQState               = errors.New("unexpected q state (should've been selected)")

	
	ErrUnexpectedChuckPoppedUnordered = ErrUnexpectedChunkPoppedUnordered
	
	ErrUnexpectedChuckPoppedOrdered = ErrUnexpectedChunkPoppedOrdered
)

Pending queue errors.

SCTP stream errors.

Error and abort chunk errors.

Data chunk errors.

Cookie ack chunk errors.

Cookie echo chunk errors.

Shutdown ack chunk errors.

View Source

var (
	ErrChunkTypeNotShutdownComplete = errors.New("ChunkType is not of type SHUTDOWN-COMPLETE")
)

Shutdown complete chunk errors.

ErrInvalidAlgorithmType is returned if unknown auth algorithm is specified.

ErrInvalidChunkLength is returned if the chunk length is invalid.

ErrInvalidSCTPChunk is returned when an SCTP chunk is invalid.

Parameter packet errors.

ErrParamTypeUnhandled is returned if unknown parameter type is specified.

View Source

var (
	ErrProtocolViolationUnmarshal = errors.New("unable to unmarshal Protocol Violation error")
)

Abort chunk errors.

View Source

var (
	ErrReconfigRespParamTooShort = errors.New("reconfig response parameter too short")
)

Reconfiguration response errors.

Outgoing reset request parameter errors.

Zero Checksum parameter error.

func GenerateOutOfBandToken ΒΆ added in v1.9.4

func GenerateOutOfBandToken(opts ...ClientOption) ([]byte, error)

GenerateOutOfBandToken generates an out-of-band connection token (i.e. a serialized SCTP INIT chunk) for use with SNAP.

func TryMarshalUnmarshal(msg []byte) int

TryMarshalUnmarshal attempts to marshal and unmarshal a message. Added for fuzzing.

type Association struct {
	
}

Association represents an SCTP association 13.2. Parameters Necessary per Association (i.e., the TCB)

Peer        : Tag value to be sent in every packet and is received
Verification: in the INIT or INIT ACK chunk.
Tag         :
State       : A state variable indicating what state the association
            : is in, i.e., COOKIE-WAIT, COOKIE-ECHOED, ESTABLISHED,
            : SHUTDOWN-PENDING, SHUTDOWN-SENT, SHUTDOWN-RECEIVED,
            : SHUTDOWN-ACK-SENT.

Note: No "CLOSED" state is illustrated since if a association is "CLOSED" its TCB SHOULD be removed. Note: By nature of an Association being constructed with one net.Conn, it is not a multi-home supporting implementation of SCTP.

Client opens a SCTP stream over a conn.

Deprecated: Use ClientWithOptions instead.

func ClientWithOptions(opts ...ClientOption) (*Association, error)

ClientWithOptions opens a SCTP stream over a conn.

Server accepts a SCTP stream over a conn.

Deprecated: Use ServerWithOptions instead.

func ServerWithOptions(opts ...ServerOption) (*Association, error)

ServerWithOptions accepts a SCTP stream over a conn.

Abort sends the abort packet with user initiated abort and immediately closes the connection.

func (a *Association) AcceptStream() (*Stream, error)

AcceptStream accepts a stream.

func (a *Association) ActiveHeartbeat()

ActiveHeartbeat sends a HEARTBEAT chunk on the association to perform an on-demand RTT measurement without application payload.

It is safe to call from outside; it will take the association lock and be a no-op if the association is not established.

func (a *Association) BufferedAmount() int

BufferedAmount returns total amount (in bytes) of currently buffered user data.

BytesReceived returns the number of bytes received.

BytesSent returns the number of bytes sent.

CWND returns the association's current congestion window (cwnd).

Close ends the SCTP Association and cleans up any state.

MTU returns the association's current MTU.

MaxMessageSize returns the maximum message size you can send.

func (a *Association) OpenStream(
	streamIdentifier uint16,
	defaultPayloadType PayloadProtocolIdentifier,
) (*Stream, error)

OpenStream opens a stream.

RWND returns the association's current receiver window (rwnd).

SRTT returns the latest smoothed round-trip time (srrt).

func (a *Association) SetMaxMessageSize(maxMsgSize uint32)

SetMaxMessageSize sets the maximum message size you can send.

Shutdown initiates the shutdown sequence. The method blocks until the shutdown sequence is completed and the connection is closed, or until the passed context is done, in which case the context's error is returned.

type AssociationOption interface {
	ServerOption
	ClientOption
}

AssociationOption applies to both client and server.

WithBlockWrite sets whether the association should use blocking writes. By default this is false.

func WithCwndCAStep(cwndCAStep uint32) AssociationOption

WithCwndCAStep sets the congestion window congestion avoidance step for the association.

func WithEnableZeroChecksum(b bool) AssociationOption

WithEnableZeroChecksum sets whether the association should accept zero as a valid checksum. By default this is false.

func WithFastRtxWnd(fastRtxWnd uint32) AssociationOption

WithFastRtxWnd sets the fast retransmission window for the association.

WithLoggerFactory sets the logger factory for the association.

WithMTU sets the MTU size for the association. By default this is 1228.

WithMaxMessageSize sets the maximum message size for the association. By default this is 65536.

func WithMaxReceiveBufferSize(size uint32) AssociationOption

WithMaxReceiveBufferSize sets the maximum receive buffer size for the association. By default this is 1024 * 1024 = 1048576.

WithMinCwnd sets the minimum congestion window for the association.

WithName sets the name of the association.

WithNetConn sets the net.Conn used by the association.

func WithRACKOptions(opts ...AssociationRACKOption) AssociationOption

WithRACKOptions configures optional RACK settings using the above options. This also creates the new windowedMin slice used for tracking the minRTT.

WithRTOMax sets the max retransmission timeout in ms for the association.

type AssociationRACKOption func(*rackSettings) error

AssociationRACKOption represents a function that can be used to configure an Association's RACK options.

WithRackMinRTTWnd sets the length of the local minimum window used to determine the minRTT. By default this is 30 seconds.

WithRackReoWndFloor sets the RACK reordering window floor for the association. By default this is 0.

WithRackWCDelAck sets the receiver worst-case delayed-ACK for PTO when only 1 packet is in flight. By default this is 200 ms.

type ClientOption interface {
	
}

ClientOption configures a Client.

Config collects the arguments to createAssociation construction into a single structure.

type PayloadProtocolIdentifier uint32

PayloadProtocolIdentifier is an enum for DataChannel payload types.

type ServerOption interface {
	
}

ServerOption configures a Server.

Stream represents an SCTP stream.

func (s *Stream) BufferedAmount() uint64

BufferedAmount returns the number of bytes of data currently queued to be sent over this stream.

func (s *Stream) BufferedAmountLowThreshold() uint64

BufferedAmountLowThreshold returns the number of bytes of buffered outgoing data that is considered "low." Defaults to 0.

Close closes the write-direction of the stream. Future calls to Write are not permitted after calling Close.

func (s *Stream) OnBufferedAmountLow(f func())

OnBufferedAmountLow sets the callback handler which would be called when the number of bytes of outgoing data buffered is lower than the threshold.

Read reads a packet of len(p) bytes, dropping the Payload Protocol Identifier. Returns EOF when the stream is reset or an error if the stream is closed otherwise.

ReadSCTP reads a packet of len(payload) bytes and returns the associated Payload Protocol Identifier. Returns EOF when the stream is reset or an error if the stream is closed otherwise.

func (s *Stream) SetBufferedAmountLowThreshold(th uint64)

SetBufferedAmountLowThreshold is used to update the threshold. See BufferedAmountLowThreshold().

SetDeadline sets the read and write deadlines in an identical way to net.Conn.

func (s *Stream) SetDefaultPayloadType(defaultPayloadType PayloadProtocolIdentifier)

SetDefaultPayloadType sets the default payload type used by Write.

SetReadDeadline sets the read deadline in an identical way to net.Conn.

func (s *Stream) SetReliabilityParams(unordered bool, relType byte, relVal uint32)

SetReliabilityParams sets reliability parameters for this stream.

SetWriteDeadline sets the write deadline in an identical way to net.Conn, it will only work for blocking writes.

func (s *Stream) State() StreamState

State return the stream state.

func (s *Stream) StreamIdentifier() uint16

StreamIdentifier returns the Stream identifier associated to the stream.

Write writes len(payload) bytes from payload with the default Payload Protocol Identifier.

WriteSCTP writes len(payload) bytes from payload to the DTLS connection.

StreamState is an enum for SCTP Stream state field This field identifies the state of stream.

const (
	StreamStateOpen    StreamState = iota 
	StreamStateClosing                    
	StreamStateClosed                     
)

StreamState enums.