Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: webrtc-direct transport #960

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from
Draft
9 changes: 6 additions & 3 deletions .pinned
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
bearssl;https://github.com/status-im/nim-bearssl@#e4157639db180e52727712a47deaefcbbac6ec86
binary_serialization;https://github.com/status-im/nim-binary-serialization.git@#38a73a70fd43f3835ca01a877353858b19e39d70
chronicles;https://github.com/status-im/nim-chronicles@#32ac8679680ea699f7dbc046e8e0131cac97d41a
chronos;https://github.com/status-im/nim-chronos@#ba143e029f35fd9b4cd3d89d007cc834d0d5ba3c
dnsclient;https://github.com/ba0f3/dnsclient.nim@#23214235d4784d24aceed99bbfe153379ea557c8
faststreams;https://github.com/status-im/nim-faststreams@#720fc5e5c8e428d9d0af618e1e27c44b42350309
httputils;https://github.com/status-im/nim-http-utils@#3b491a40c60aad9e8d3407443f46f62511e63b18
httputils;https://github.com/status-im/nim-http-utils@#87b7cbf032c90b9e6b446081f4a647e950362cec
json_serialization;https://github.com/status-im/nim-json-serialization@#85b7ea093cb85ee4f433a617b97571bd709d30df
mbedtls;https://github.com/status-im/nim-mbedtls.git@#308f3edaa0edcc880b54ce22156fb2f4e2a2bcc7
metrics;https://github.com/status-im/nim-metrics@#6142e433fc8ea9b73379770a788017ac528d46ff
nimcrypto;https://github.com/cheatfate/nimcrypto@#1c8d6e3caf3abc572136ae9a1da81730c4eb4288
nimcrypto;https://github.com/cheatfate/nimcrypto@#a079df92424968d46a6ac258299ce9380aa153f2
results;https://github.com/arnetheduck/nim-results@#f3c666a272c69d70cb41e7245e7f6844797303ad
secp256k1;https://github.com/status-im/nim-secp256k1@#7246d91c667f4cc3759fdd50339caa45a2ecd8be
serialization;https://github.com/status-im/nim-serialization@#4bdbc29e54fe54049950e352bb969aab97173b35
stew;https://github.com/status-im/nim-stew@#3159137d9a3110edb4024145ce0ba778975de40e
testutils;https://github.com/status-im/nim-testutils@#dfc4c1b39f9ded9baf6365014de2b4bfb4dafc34
unittest2;https://github.com/status-im/nim-unittest2@#2300fa9924a76e6c96bc4ea79d043e3a0f27120c
webrtc;https://github.com/status-im/nim-webrtc.git@#d525da3d62ed65e989d782e4cbb7edf221128568
websock;https://github.com/status-im/nim-websock@#f8ed9b40a5ff27ad02a3c237c4905b0924e3f982
zlib;https://github.com/status-im/nim-zlib@#38b72eda9d70067df4a953f56b5ed59630f2a17b
zlib;https://github.com/status-im/nim-zlib@#a2f44bb7f65571a894227ff6fde9298a104e03a5
1 change: 1 addition & 0 deletions libp2p.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ requires "nim >= 1.6.0",
"secp256k1",
"stew#head",
"websock",
"https://github.com/status-im/nim-webrtc.git",
"unittest2 >= 0.0.5 & <= 0.1.0"

let nimc = getEnv("NIMC", "nim") # Which nim compiler to use
Expand Down
47 changes: 45 additions & 2 deletions libp2p/multiaddress.nim
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,33 @@ proc dnsVB(vb: var VBuffer): bool =
if s.find('/') == -1:
result = true

proc certHashStB(s: string, vb: var VBuffer): bool =
## CertHash address stringToBuffer() implementation.
var data = MultiBase.decode(s).valueOr:
return false
var mh: MultiHash
if MultiHash.decode(data, mh).isOk:
vb.writeSeq(data)
result = true

proc certHashBtS(vb: var VBuffer, s: var string): bool =
## CertHash address bufferToString() implementation.
var address = newSeq[byte]()
if vb.readSeq(address) > 0:
var mh: MultiHash
if MultiHash.decode(address, mh).isOk:
s = MultiBase.encode("base64url", address).valueOr:
return false
result = true

proc certHashVB(vb: var VBuffer): bool =
## CertHash address validateBuffer() implementation.
var address = newSeq[byte]()
if vb.readSeq(address) > 0:
var mh: MultiHash
if MultiHash.decode(address, mh).isOk:
result = true

proc mapEq*(codec: string): MaPattern =
## ``Equal`` operator for pattern
result.operator = Eq
Expand Down Expand Up @@ -358,6 +385,11 @@ const
bufferToString: dnsBtS,
validateBuffer: dnsVB
)
TranscoderCertHash* = Transcoder(
stringToBuffer: certHashStB,
bufferToString: certHashBtS,
validateBuffer: certHashVB
)
ProtocolsList = [
MAProtocol(
mcodec: multiCodec("ip4"), kind: Fixed, size: 4,
Expand Down Expand Up @@ -458,7 +490,17 @@ const
),
MAProtocol(
mcodec: multiCodec("p2p-webrtc-direct"), kind: Marker, size: 0
)
),
MAProtocol(
mcodec: multiCodec("webrtc"), kind: Marker, size: 0
),
MAProtocol(
mcodec: multiCodec("webrtc-direct"), kind: Marker, size: 0
),
MAProtocol(
mcodec: multiCodec("certhash"), kind: Length, size: 0,
coder: TranscoderCertHash
),
]

DNSANY* = mapEq("dns")
Expand Down Expand Up @@ -489,6 +531,7 @@ const
WebSockets_DNS* = mapOr(WS_DNS, WSS_DNS)
WebSockets_IP* = mapOr(WS_IP, WSS_IP)
WebSockets* = mapOr(WS, WSS)
WebRtcDirect2* = mapAnd(UDP, mapEq("webrtc-direct"), mapEq("certhash"))
Onion3* = mapEq("onion3")
TcpOnion3* = mapAnd(TCP, Onion3)

Expand All @@ -512,7 +555,7 @@ const
mapAnd(DNS, mapEq("https"))
)

WebRTCDirect* = mapOr(
WebRTCDirect* {.deprecated.} = mapOr(
mapAnd(HTTP, mapEq("p2p-webrtc-direct")),
mapAnd(HTTPS, mapEq("p2p-webrtc-direct"))
)
Expand Down
3 changes: 3 additions & 0 deletions libp2p/multicodec.nim
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,14 @@ const MultiCodecList = [
("https", 0x01BB),
("tls", 0x01C0),
("quic", 0x01CC),
("certhash", 0x01D2),
("ws", 0x01DD),
("wss", 0x01DE),
("p2p-websocket-star", 0x01DF), # not in multicodec list
("p2p-webrtc-star", 0x0113), # not in multicodec list
("p2p-webrtc-direct", 0x0114), # not in multicodec list
("webrtc-direct", 0x0118),
("webrtc", 0x0119),
("onion", 0x01BC),
("onion3", 0x01BD),
("p2p-circuit", 0x0122),
Expand Down
2 changes: 1 addition & 1 deletion libp2p/protocols/secure/noise.nim
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ type
localPrivateKey: PrivateKey
localPublicKey: seq[byte]
noiseKeys: KeyPair
commonPrologue: seq[byte]
commonPrologue*: seq[byte]
outgoing: bool

NoiseConnection* = ref object of SecureConn
Expand Down
2 changes: 1 addition & 1 deletion libp2p/transports/tcptransport.nim
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ method start*(

self.servers &= server

trace "Listening on", address = ma
trace "Listening on", address = self.addrs[i]

method stop*(self: TcpTransport) {.async, gcsafe.} =
## stop the transport
Expand Down
Loading
Loading