diff --git a/tests/testsctp.nim b/tests/testsctp.nim index 7d381f2..448714f 100644 --- a/tests/testsctp.nim +++ b/tests/testsctp.nim @@ -29,9 +29,9 @@ suite "SCTP": dtls: Dtls sctp: Sctp - proc initSctpStack(localAddress: TransportAddress): SctpStackForTest = - result.localAddress = localAddress - result.udp = UdpTransport.new(result.localAddress) + proc initSctpStack(la: TransportAddress): SctpStackForTest = + result.udp = UdpTransport.new(la) + result.localAddress = result.udp.localAddress() result.stun = Stun.new(result.udp) result.dtls = Dtls.new(result.stun) result.sctp = Sctp.new(result.dtls) @@ -45,8 +45,8 @@ suite "SCTP": asyncTest "Two SCTP nodes connecting to each other, then sending/receiving data": var - sctpServer = initSctpStack(initTAddress("127.0.0.1:4444")) - sctpClient = initSctpStack(initTAddress("127.0.0.1:5555")) + sctpServer = initSctpStack(initTAddress("127.0.0.1:0")) + sctpClient = initSctpStack(initTAddress("127.0.0.1:0")) let serverConnFut = sctpServer.sctp.accept() clientConn = await sctpClient.sctp.connect(sctpServer.localAddress) @@ -68,9 +68,9 @@ suite "SCTP": asyncTest "Two DTLS nodes connecting to the same DTLS server, sending/receiving data": var - sctpServer = initSctpStack(initTAddress("127.0.0.1:4444")) - sctpClient1 = initSctpStack(initTAddress("127.0.0.1:5555")) - sctpClient2 = initSctpStack(initTAddress("127.0.0.1:6666")) + sctpServer = initSctpStack(initTAddress("127.0.0.1:0")) + sctpClient1 = initSctpStack(initTAddress("127.0.0.1:0")) + sctpClient2 = initSctpStack(initTAddress("127.0.0.1:0")) let serverConn1Fut = sctpServer.sctp.accept() serverConn2Fut = sctpServer.sctp.accept() diff --git a/webrtc/stun/stun_connection.nim b/webrtc/stun/stun_connection.nim index 9d661a2..d732041 100644 --- a/webrtc/stun/stun_connection.nim +++ b/webrtc/stun/stun_connection.nim @@ -201,7 +201,7 @@ proc new*( ## var self = T( udp: udp, - laddr: udp.laddr, + laddr: udp.localAddress(), raddr: raddr, closed: false, dataRecv: newAsyncQueue[seq[byte]](StunMaxQueuingMessages), diff --git a/webrtc/stun/stun_transport.nim b/webrtc/stun/stun_transport.nim index becc593..3d52f53 100644 --- a/webrtc/stun/stun_transport.nim +++ b/webrtc/stun/stun_transport.nim @@ -108,7 +108,7 @@ proc new*( ## var self = T( udp: udp, - laddr: udp.laddr, + laddr: udp.localAddress(), usernameProvider: usernameProvider, usernameChecker: usernameChecker, passwordProvider: passwordProvider, diff --git a/webrtc/udp_transport.nim b/webrtc/udp_transport.nim index e458a5e..1f1625c 100644 --- a/webrtc/udp_transport.nim +++ b/webrtc/udp_transport.nim @@ -23,7 +23,7 @@ type raddr: TransportAddress UdpTransport* = ref object - laddr*: TransportAddress + laddr: TransportAddress udp: DatagramTransport dataRecv: AsyncQueue[UdpPacketInfo] closed: bool @@ -33,7 +33,7 @@ const UdpTransportTrackerName* = "webrtc.udp.transport" proc new*(T: type UdpTransport, laddr: TransportAddress): T = ## Initialize an Udp Transport ## - var self = T(laddr: laddr, closed: false) + var self = T(closed: false) proc onReceive( udp: DatagramTransport, @@ -49,6 +49,7 @@ proc new*(T: type UdpTransport, laddr: TransportAddress): T = self.dataRecv = newAsyncQueue[UdpPacketInfo]() self.udp = newDatagramTransport(onReceive, local = laddr) + self.laddr = self.udp.localAddress() trackCounter(UdpTransportTrackerName) return self @@ -87,3 +88,6 @@ proc read*(self: UdpTransport): Future[UdpPacketInfo] {.async: (raises: [Cancell return trace "UDP read" return await self.dataRecv.popFirst() + +proc localAddress*(self: UdpTransport): TransportAddress = + self.laddr