expose local address

This commit is contained in:
Ludovic Chenut 2023-10-19 14:20:48 +02:00
parent 0504d86340
commit afce5cad17
No known key found for this signature in database
GPG Key ID: D9A59B1907F1D50C
3 changed files with 7 additions and 10 deletions

View File

@ -139,9 +139,9 @@ proc start*(self: Dtls, conn: StunConn, laddr: TransportAddress) =
mb_entropy_init(self.entropy) mb_entropy_init(self.entropy)
mb_ctr_drbg_seed(self.ctr_drbg, mbedtls_entropy_func, self.entropy, nil, 0) mb_ctr_drbg_seed(self.ctr_drbg, mbedtls_entropy_func, self.entropy, nil, 0)
var pkey = self.ctr_drbg.generateKey() self.serverPrivKey = self.ctr_drbg.generateKey()
var srvcert = self.ctr_drbg.generateCertificate(pkey) self.serverCert = self.ctr_drbg.generateCertificate(self.serverPrivKey)
self.localCert = newSeq[byte](srvcert.raw.len) self.localCert = newSeq[byte](self.serverCert.raw.len)
proc stop*(self: Dtls) = proc stop*(self: Dtls) =
if not self.started: if not self.started:
@ -205,10 +205,10 @@ proc accept*(self: Dtls): Future[DtlsConn] {.async.} =
res.ctr_drbg = self.ctr_drbg res.ctr_drbg = self.ctr_drbg
res.entropy = self.entropy res.entropy = self.entropy
var pkey = res.ctr_drbg.generateKey() var pkey = self.serverPrivKey
var srvcert = res.ctr_drbg.generateCertificate(pkey) var srvcert = self.serverCert
res.localCert = newSeq[byte](srvcert.raw.len) res.localCert = newSeq[byte](srvcert.raw.len)
copyMem(addr res.localCert[0], srvcert.raw.p, srvcert.raw.len) res.localCert = self.localCert
mb_ssl_config_defaults(res.config, mb_ssl_config_defaults(res.config,
MBEDTLS_SSL_IS_SERVER, MBEDTLS_SSL_IS_SERVER,

View File

@ -15,7 +15,7 @@ logScope:
type type
UdpConn* = ref object UdpConn* = ref object
laddr: TransportAddress laddr*: TransportAddress
udp: DatagramTransport udp: DatagramTransport
dataRecv: AsyncQueue[(seq[byte], TransportAddress)] dataRecv: AsyncQueue[(seq[byte], TransportAddress)]

View File

@ -25,9 +25,6 @@ type
sctp*: Sctp sctp*: Sctp
port: int port: int
proc dtlsLocalCertificate(w: WebRTC): seq[byte] =
w.dtls.localCertificate()
proc new*(T: typedesc[WebRTC], address: TransportAddress): T = proc new*(T: typedesc[WebRTC], address: TransportAddress): T =
var webrtc = T(udp: UdpConn(), stun: StunConn(), dtls: Dtls()) var webrtc = T(udp: UdpConn(), stun: StunConn(), dtls: Dtls())
webrtc.udp.init(address) webrtc.udp.init(address)