From 6df4a53ec37134fda2a465bfbb8e18b5fce56741 Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Fri, 15 Nov 2024 14:07:38 +0100 Subject: [PATCH] fix: password provider --- .pinned | 2 +- libp2p/transports/webrtctransport.nim | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.pinned b/.pinned index e5cd3f3f4..863f4c6e8 100644 --- a/.pinned +++ b/.pinned @@ -18,6 +18,6 @@ stew;https://github.com/status-im/nim-stew@#3159137d9a3110edb4024145ce0ba778975d testutils;https://github.com/status-im/nim-testutils@#dfc4c1b39f9ded9baf6365014de2b4bfb4dafc34 unittest2;https://github.com/status-im/nim-unittest2@#2300fa9924a76e6c96bc4ea79d043e3a0f27120c 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 zlib;https://github.com/status-im/nim-zlib@#a2f44bb7f65571a894227ff6fde9298a104e03a5 diff --git a/libp2p/transports/webrtctransport.nim b/libp2p/transports/webrtctransport.nim index c4907a053..69a0db4a7 100644 --- a/libp2p/transports/webrtctransport.nim +++ b/libp2p/transports/webrtctransport.nim @@ -12,7 +12,7 @@ {.push raises: [].} -import std/[sequtils] +import std/[sequtils, strutils] import stew/[endians2, byteutils, objects, results] import chronos, chronicles import transport, @@ -435,6 +435,14 @@ proc new*( 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*( self: WebRtcTransport, addrs: seq[MultiAddress]) {.async.} = @@ -456,7 +464,7 @@ method start*( let transportAddress = initTAddress(ma[0..1].tryGet()).tryGet() - server = WebRtc.new(transportAddress) + server = WebRtc.new(transportAddress, passwordProvider = stunpwprovider) server.listen() self.servers &= server