Skip to content

Commit

Permalink
fix: oversight on dtls.new
Browse files Browse the repository at this point in the history
  • Loading branch information
lchenut committed Jun 21, 2024
1 parent 66a2aa7 commit 24e42a9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
17 changes: 9 additions & 8 deletions webrtc/dtls/dtls_transport.nim
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type
Dtls* = ref object of RootObj
connections: Table[TransportAddress, DtlsConn]
transport: Stun
laddr: TransportAddress
laddr*: TransportAddress
started: bool
ctr_drbg: mbedtls_ctr_drbg_context
entropy: mbedtls_entropy_context
Expand All @@ -49,13 +49,13 @@ type
serverCert: mbedtls_x509_crt
localCert: seq[byte]

proc new*(T: type Dtls, transport: Stun, laddr: TransportAddress): T =
var self = T()

self.connections = initTable[TransportAddress, DtlsConn]()
self.transport = transport
self.laddr = laddr
self.started = true
proc new*(T: type Dtls, transport: Stun): T =
var self = T(
connections: initTable[TransportAddress, DtlsConn](),
transport: transport,
laddr: transport.laddr,
started: true
)

mb_ctr_drbg_init(self.ctr_drbg)
mb_entropy_init(self.entropy)
Expand All @@ -65,6 +65,7 @@ proc new*(T: type Dtls, transport: Stun, laddr: TransportAddress): T =
self.serverCert = self.ctr_drbg.generateCertificate(self.serverPrivKey)
self.localCert = newSeq[byte](self.serverCert.raw.len)
copyMem(addr self.localCert[0], self.serverCert.raw.p, self.serverCert.raw.len)
return self

proc stop*(self: Dtls) {.async.} =
if not self.started:
Expand Down
1 change: 1 addition & 0 deletions webrtc/dtls/dtls_utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import mbedtls/ctr_drbg
import mbedtls/x509_crt
import mbedtls/bignum
import mbedtls/md
import mbedtls/error

# This sequence is used for debugging.
const mb_ssl_states* = @[
Expand Down
6 changes: 4 additions & 2 deletions webrtc/stun/stun_transport.nim
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ type
Stun* = ref object
connections: Table[TransportAddress, StunConn]
pendingConn: AsyncQueue[StunConn]
readingLoop: Future[void]
readingLoop: Future[void].Raising([CancelledError])
udp: UdpTransport
laddr*: TransportAddress

usernameProvider: StunUsernameProvider
usernameChecker: StunUsernameChecker
Expand Down Expand Up @@ -106,11 +107,12 @@ proc new*(
##
var self = T(
udp: udp,
laddr: udp.laddr,
usernameProvider: usernameProvider,
usernameChecker: usernameChecker,
passwordProvider: passwordProvider,
rng: rng
)
self.readingLoop = stunReadLoop()
self.readingLoop = self.stunReadLoop()
self.pendingConn = newAsyncQueue[StunConn](StunMaxPendingConnections)
return self

0 comments on commit 24e42a9

Please sign in to comment.