Skip to content

Commit

Permalink
docs: SctpConn and SctpMessageParameters field
Browse files Browse the repository at this point in the history
  • Loading branch information
lchenut committed Oct 4, 2024
1 parent 7d612aa commit 5adb9ae
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions webrtc/sctp/sctp_connection.nim
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,46 @@ type
SctpClosed

SctpMessageParameters* = object
# This object is used to help manage messages exchanged over SCTP
# within the DataChannel stack.
protocolId*: uint32
# protocolId is used to distinguish different protocols within
# SCTP stream. In WebRTC, this is used to define the type of application
# data being transferred (text data, binary data...).
streamId*: uint16
# streamId identifies the specific SCTP stream. In WebRTC, each
# DataChannel corresponds to a different stream, so the streamId is
# used to map the message to the appropriate DataChannel.
endOfRecord*: bool
# endOfRecord indicates whether the current SCTP message is the
# final part of a record or not. This is related to the
# fragmentation and reassembly of messages.
unordered*: bool
# The unordered flag determines whether the message should be
# delivered in order or not. SCTP allows for both ordered and
# unordered delivery of messages.

SctpMessage* = ref object
data*: seq[byte]
info*: sctp_recvv_rn
params*: SctpMessageParameters

SctpConn* = ref object
conn: DtlsConn
state*: SctpState
onClose: seq[SctpConnOnClose]
connectEvent*: AsyncEvent
acceptEvent*: AsyncEvent
conn: DtlsConn # Underlying DTLS Connection
sctpSocket*: ptr socket # Current usrsctp socket


state*: SctpState # Current Sctp State
onClose: seq[SctpConnOnClose] # List of procedure to run while closing a connection

connectEvent*: AsyncEvent # Event fired when the connection is connected
acceptEvent*: AsyncEvent # Event fired when the connection is accepted

# Infinite loop reading on the underlying DTLS Connection.
readLoop: Future[void].Raising([CancelledError, WebRtcError])
sctpSocket*: ptr socket
dataRecv: AsyncQueue[SctpMessage]
sendQueue: seq[byte]

dataRecv: AsyncQueue[SctpMessage] # Queue of messages to be read
sendQueue: seq[byte] # Queue of messages to be sent

proc remoteAddress*(self: SctpConn): TransportAddress =
if self.conn.isNil():
Expand Down Expand Up @@ -106,7 +126,6 @@ proc recvCallback*(sock: ptr socket, data: pointer, flags: cint) {.cdecl.} =
warn "usrsctp_recvv", error = sctpStrerror()
return
elif n > 0:
# It might be necessary to check if infotype == SCTP_RECVV_RCVINFO
message.data.delete(n ..< message.data.len())
trace "message info from handle upcall", msginfo = message.info
message.params = SctpMessageParameters(
Expand Down

0 comments on commit 5adb9ae

Please sign in to comment.