fix: password provider

This commit is contained in:
Ludovic Chenut 2024-11-15 14:07:38 +01:00
parent 255bf740ea
commit 6df4a53ec3
No known key found for this signature in database
GPG Key ID: D9A59B1907F1D50C
2 changed files with 11 additions and 3 deletions

View File

@ -18,6 +18,6 @@ stew;https://github.com/status-im/nim-stew@#3159137d9a3110edb4024145ce0ba778975d
testutils;https://github.com/status-im/nim-testutils@#dfc4c1b39f9ded9baf6365014de2b4bfb4dafc34 testutils;https://github.com/status-im/nim-testutils@#dfc4c1b39f9ded9baf6365014de2b4bfb4dafc34
unittest2;https://github.com/status-im/nim-unittest2@#2300fa9924a76e6c96bc4ea79d043e3a0f27120c unittest2;https://github.com/status-im/nim-unittest2@#2300fa9924a76e6c96bc4ea79d043e3a0f27120c
usrsctp;https://github.com/status-im/nim-usrsctp@#c6a8d4bab44447df790e97dfc8099f7af93d435e usrsctp;https://github.com/status-im/nim-usrsctp@#c6a8d4bab44447df790e97dfc8099f7af93d435e
webrtc;https://github.com/status-im/nim-webrtc.git@#10d2389ab4d314ababe9544f71e462497d8c8dea webrtc;https://github.com/status-im/nim-webrtc.git@#497aea7e6c2e73d81456e60f26a49281d0b8c87f
websock;https://github.com/status-im/nim-websock@#f8ed9b40a5ff27ad02a3c237c4905b0924e3f982 websock;https://github.com/status-im/nim-websock@#f8ed9b40a5ff27ad02a3c237c4905b0924e3f982
zlib;https://github.com/status-im/nim-zlib@#a2f44bb7f65571a894227ff6fde9298a104e03a5 zlib;https://github.com/status-im/nim-zlib@#a2f44bb7f65571a894227ff6fde9298a104e03a5

View File

@ -12,7 +12,7 @@
{.push raises: [].} {.push raises: [].}
import std/[sequtils] import std/[sequtils, strutils]
import stew/[endians2, byteutils, objects, results] import stew/[endians2, byteutils, objects, results]
import chronos, chronicles import chronos, chronicles
import transport, import transport,
@ -435,6 +435,14 @@ proc new*(
return transport return transport
proc stunpwprovider(usernameBytes: seq[byte]): seq[byte] =
let username = string.fromBytes(usernameBytes)
let usersplit = username.split(":")
if usersplit.len() <= 2 and usersplit[0].startsWith("libp2p+webrtc+v1/"):
return toBytes(usersplit[0])
else:
return @[]
method start*( method start*(
self: WebRtcTransport, self: WebRtcTransport,
addrs: seq[MultiAddress]) {.async.} = addrs: seq[MultiAddress]) {.async.} =
@ -456,7 +464,7 @@ method start*(
let let
transportAddress = initTAddress(ma[0..1].tryGet()).tryGet() transportAddress = initTAddress(ma[0..1].tryGet()).tryGet()
server = WebRtc.new(transportAddress) server = WebRtc.new(transportAddress, passwordProvider = stunpwprovider)
server.listen() server.listen()
self.servers &= server self.servers &= server