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

move go-ws-transport here #1422

Merged
merged 124 commits into from
Apr 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
124 commits
Select commit Hold shift + click to select a range
f928ecc
first working commit
whyrusleeping May 16, 2016
83015ba
complete parsers
whyrusleeping May 16, 2016
5d09bed
gx publish version 1.0.2
whyrusleeping Aug 24, 2016
6cb2231
gx publish version 1.0.3
whyrusleeping Aug 24, 2016
10b6a10
some cleanup
whyrusleeping Aug 24, 2016
f87a840
gx publish version 1.0.5, use builtin context
whyrusleeping Aug 24, 2016
598f265
fix: use binary frames instead of text frames
dignifiedquire Sep 15, 2016
594a7ef
Merge pull request #3 from dignifiedquire/patch-1
whyrusleeping Sep 15, 2016
b80c128
gx publish v1.2.0
whyrusleeping Sep 16, 2016
f5f0af8
update libp2p-transport
whyrusleeping Sep 25, 2016
fa8d0d2
gx publish 1.4.0
whyrusleeping Oct 5, 2016
398fcd5
feat: upgrade to use gorilla/websocket
dignifiedquire Jul 1, 2017
0cb827d
gxified gorilla/websocket
dignifiedquire Jul 4, 2017
32c4c20
first round of cr fixes
dignifiedquire Jul 4, 2017
f5d0996
more cr fixes
dignifiedquire Jul 4, 2017
661ec22
use more pointers
dignifiedquire Jul 5, 2017
be25e2e
another import fix
dignifiedquire Jul 5, 2017
fd70584
gx unwrite
dignifiedquire Jul 5, 2017
84a5d64
refactor: simplify and split into multiple files
dignifiedquire Jul 9, 2017
3280392
more tests
dignifiedquire Jul 9, 2017
9b327a6
add dialer.Matches test
dignifiedquire Jul 9, 2017
35370ce
Merge pull request #17 from libp2p/feat/gorilla
whyrusleeping Jul 10, 2017
efba554
fix reading from conn and addresses
whyrusleeping Sep 5, 2017
cb1cdda
fix review and tests
whyrusleeping Sep 5, 2017
e57234e
Merge pull request #18 from libp2p/fix/reading-addrs
whyrusleeping Sep 5, 2017
a293989
Make close thread safe
Stebalien Sep 5, 2017
b863f44
test concurrent connection closing
Stebalien Sep 5, 2017
a88b185
Add write-zero test.
Stebalien Sep 5, 2017
da59505
don't explicitly nil err
Stebalien Sep 5, 2017
a34b3e7
Merge pull request #19 from libp2p/fix/thread-safe-close
Stebalien Sep 5, 2017
f455930
fix requests from other origins
Stebalien Sep 5, 2017
16f6845
Merge pull request #20 from libp2p/fix/ipfs/go-ipfs/4202
Stebalien Sep 5, 2017
2d2035f
close connections we fail to wrap
Stebalien Nov 29, 2017
1424a22
Merge pull request #25 from libp2p/fix/close-failed
Stebalien Nov 29, 2017
250a23c
close connections we fail to dial
Stebalien Dec 3, 2017
3093dfd
Merge pull request #27 from libp2p/fix/close-failed-dial
Stebalien Dec 3, 2017
4278028
fixup for transport refactor
Stebalien Feb 16, 2018
c1eeb0c
Merge pull request #31 from libp2p/feat/refactor
Stebalien Jun 6, 2018
16e9eb2
modernize request handling
Stebalien Apr 4, 2019
e1669e2
Merge pull request #41 from libp2p/fix/modernize
Stebalien Apr 4, 2019
b7f9522
dep: import go-smux-* into the libp2p org
Stebalien May 22, 2019
d43aa73
Merge pull request #43 from libp2p/dep/import-smux
Stebalien May 22, 2019
a2d70a7
fix: don't try to write an error _twice_.
Stebalien May 25, 2019
8eef3f7
Merge pull request #44 from libp2p/fix/double-error-write
Stebalien May 25, 2019
3255249
migrate to consolidated types. (#45)
raulk May 26, 2019
7b972a0
move multiaddr protocol definitions to go-multiaddr
Stebalien Sep 19, 2019
44c0579
Merge pull request #52 from libp2p/fix/global-multiaddr-registry
Stebalien Sep 19, 2019
6de8743
dep: update and switch to go-multiaddr-fmt
Stebalien Sep 19, 2019
ac7f16b
Merge pull request #53 from libp2p/dep/update
Stebalien Sep 19, 2019
7f87ef8
fix: close gracefully
Stebalien Sep 26, 2019
4b1b551
Merge pull request #54 from libp2p/fix/graceful-close
Stebalien Sep 30, 2019
a767672
Implement bare bones Wasm support (needs to be cleaned up)
albrow Aug 8, 2019
486168b
Make it possible to run browser tests with a single go test command
albrow Aug 8, 2019
4979f94
Guarantee reading happens in order and add some comments
albrow Aug 14, 2019
ee5c829
return os.ErrNoDeadline where appropriate
albrow Aug 14, 2019
31e5ba4
Change go and js suffixes to native and browser
albrow Aug 14, 2019
a52e415
Revert to returning nil instead of os.ErrNoDeadline
albrow Aug 17, 2019
7fcd449
Cache local and remote address
albrow Aug 19, 2019
9f09979
Optimize readBlob by using the readAsBinaryString method
albrow Aug 19, 2019
49b017b
Add better error handling to readBlob
albrow Aug 19, 2019
f85474b
Revert back to using readAsArrayBuffer
albrow Aug 19, 2019
4273289
Preserve message order by not using a goroutine in messageHandler
albrow Aug 19, 2019
2eb6cb2
Use ArrayBuffer type for binary data
albrow Aug 20, 2019
e327fad
Use a buffer of 1 for dataSignal channel
albrow Aug 20, 2019
eda7468
Add TODO for returning os.ErrNoDeadline
albrow Aug 20, 2019
38b0b7f
Add proper error handling
albrow Aug 20, 2019
b8d9682
Expand comment about time.Sleep hack
albrow Sep 17, 2019
e08426c
Call conn.Close if waitForOpen returns an error
albrow Sep 17, 2019
fe9ccdf
Simplify Conn.Read logic
albrow Sep 17, 2019
169c516
Simplify iteration over Uint8Array
albrow Sep 17, 2019
b4e7083
Set handlers to nil after releasing them
albrow Sep 17, 2019
a4d3db5
Use a sync.Once in Conn.Close
albrow Sep 17, 2019
9ec4977
Recover from uncaught JavaScript exceptions in Conn.Write
albrow Sep 17, 2019
badfe1f
Switch order of Call("close") and signalClose()
albrow Sep 17, 2019
391b41e
Remove unused constant
albrow Sep 17, 2019
9da7d27
Set firstErr before signaling the connection close
Stebalien Sep 30, 2019
908e0da
Handle connection errors before handling data.
Stebalien Sep 30, 2019
88b65ce
test: auto-install wasm test dependency
Stebalien Sep 30, 2019
7dc7d95
Merge pull request #55 from libp2p/wasm-support
Stebalien Oct 8, 2019
3d337a9
add mutex for write/close
vyzo Dec 17, 2019
4102c54
feat: faster copy in wasm
Stebalien Jan 9, 2020
e7abe4d
Merge pull request #68 from libp2p/feat/fast-copy
Stebalien Jan 9, 2020
6463b1c
add licenses. (#69)
raulk Jan 22, 2020
df4b7d6
Revert "add mutex for write/close"
Stebalien Feb 4, 2020
a29417b
Merge pull request #73 from libp2p/fix/revert-mutex
Stebalien Feb 5, 2020
d0bf192
fix: restrict dials to IP + TCP
Stebalien Apr 3, 2020
ccea036
Merge pull request #84 from libp2p/fix/dns-dial
Stebalien Apr 3, 2020
ee27334
fix: add read/write locks
Stebalien Apr 22, 2020
60c73bf
Merge pull request #85 from libp2p/fix/deadline-race
Stebalien Apr 22, 2020
5a6d40c
Update for go 1.14 Wasm changes
Oct 15, 2020
d4006ef
Merge pull request #96 from steamraven/issue_95
Stebalien Oct 19, 2020
94f5bc4
Dependancy: Remove depricated multiaddr-net
Oct 21, 2020
a0f24eb
go fmt
Oct 21, 2020
abec414
Merge pull request #97 from steamraven/dep-net
Stebalien Oct 26, 2020
bc54bc2
pass a context to OpenStream in tests
marten-seemann Dec 17, 2020
8dbaa4b
Merge pull request #98 from libp2p/open-stream-context
marten-seemann Dec 19, 2020
9cbaa8d
chore: various cleanups required to get vet/staticcheck/test to pass
Stebalien Jul 15, 2021
f17510b
Merge pull request #100 from libp2p/chore/cleanup
Stebalien Jul 15, 2021
7a30929
ci: make the "tools" directory a valid go package
Stebalien Jul 15, 2021
3864f33
test: disable wasm test on windows
Stebalien Jul 15, 2021
1763fae
Merge pull request #101 from libp2p/web3-bot/sync
Stebalien Jul 15, 2021
6957d57
remove deprecated type
marten-seemann Jul 22, 2021
830023a
Merge pull request #102 from libp2p/remove-deprecated-type
marten-seemann Jul 22, 2021
cdd2cf7
chore: update go-libp2p-transport-upgrader and go-libp2p-core
marten-seemann Jul 24, 2021
2e25e49
Merge pull request #103 from libp2p/update-transport-upgrader
marten-seemann Jul 24, 2021
9647169
sync: update CI config files (#106)
web3-bot Aug 17, 2021
75dda2b
update deps and fix deprecated calls
marten-seemann Dec 30, 2021
081817c
use the transport.Upgrader interface
marten-seemann Jan 2, 2022
2e12799
Merge pull request #110 from libp2p/upgrader-interface
marten-seemann Jan 4, 2022
b074ba4
unexport WebsocketTransport.Upgrader
marten-seemann Jan 4, 2022
abde7f4
use the resource manager
marten-seemann Jan 4, 2022
2d29093
Merge pull request #109 from libp2p/rcmgr
marten-seemann Jan 18, 2022
2d53c8f
remove wasm support (#114)
marten-seemann Feb 14, 2022
a55402d
add support for wss dialing
albrow Jan 23, 2020
dd44db2
Merge pull request #115 from libp2p/feat/wss-dialing
marten-seemann Feb 17, 2022
5717985
remove unused origin function parameteter in wrapListener
marten-seemann Feb 13, 2022
c6eb1b4
only initialize the ws multiaddr component once
marten-seemann Feb 13, 2022
3384493
introduce a constructor for the listener
marten-seemann Feb 13, 2022
c3eae93
wait for the http server to shutdown before returning from Close
marten-seemann Feb 13, 2022
292e430
add an option to use encrypted websockets for listening
marten-seemann Feb 13, 2022
08298bb
Merge pull request #116 from libp2p/tls
marten-seemann Feb 18, 2022
67782ff
don't resolve dns addresses for Listener.Multiaddr (#117)
marten-seemann Feb 21, 2022
c32e485
move go-ws-transport here
marten-seemann Apr 22, 2022
690a16c
switch from github.com/libp2p/go-ws-transport to p2p/transport/websocket
marten-seemann Apr 22, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/libp2p/go-libp2p/p2p/net/connmgr"
"github.com/libp2p/go-libp2p/p2p/transport/tcp"
ws "github.com/libp2p/go-libp2p/p2p/transport/websocket"

"github.com/libp2p/go-libp2p-core/crypto"

Expand All @@ -16,7 +17,6 @@ import (
rcmgr "github.com/libp2p/go-libp2p-resource-manager"
tls "github.com/libp2p/go-libp2p-tls"
yamux "github.com/libp2p/go-libp2p-yamux"
ws "github.com/libp2p/go-ws-transport"
"github.com/multiformats/go-multiaddr"
)

Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/benbjohnson/clock v1.3.0
github.com/gogo/protobuf v1.3.2
github.com/golang/mock v1.6.0
github.com/gorilla/websocket v1.5.0
github.com/hashicorp/golang-lru v0.5.4
github.com/ipfs/go-cid v0.1.0
github.com/ipfs/go-datastore v0.5.1
Expand All @@ -32,7 +33,6 @@ require (
github.com/libp2p/go-reuseport v0.1.0
github.com/libp2p/go-reuseport-transport v0.1.0
github.com/libp2p/go-stream-muxer-multistream v0.4.0
github.com/libp2p/go-ws-transport v0.6.0
github.com/libp2p/zeroconf/v2 v2.1.1
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd
github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b
Expand Down Expand Up @@ -70,7 +70,6 @@ require (
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/gopacket v1.1.19 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/huin/goupnp v1.0.3 // indirect
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect
Expand Down
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
Expand Down Expand Up @@ -517,8 +516,6 @@ github.com/libp2p/go-tcp-transport v0.4.0/go.mod h1:0y52Rwrn4076xdJYu/51/qJIdxz+
github.com/libp2p/go-tcp-transport v0.5.0/go.mod h1:UPPL0DIjQqiWRwVAb+CEQlaAG0rp/mCqJfIhFcLHc4Y=
github.com/libp2p/go-tcp-transport v0.5.1 h1:edOOs688VLZAozWC7Kj5/6HHXKNwi9M6wgRmmLa8M6Q=
github.com/libp2p/go-tcp-transport v0.5.1/go.mod h1:UPPL0DIjQqiWRwVAb+CEQlaAG0rp/mCqJfIhFcLHc4Y=
github.com/libp2p/go-ws-transport v0.6.0 h1:326XBL6Q+5CQ2KtjXz32+eGu02W/Kz2+Fm4SpXdr0q4=
github.com/libp2p/go-ws-transport v0.6.0/go.mod h1:dXqtI9e2JV9FtF1NOtWVZSKXh5zXvnuwPXfj8GPBbYU=
github.com/libp2p/go-yamux v1.4.1 h1:P1Fe9vF4th5JOxxgQvfbOHkrGqIZniTLf+ddhZp8YTI=
github.com/libp2p/go-yamux v1.4.1/go.mod h1:fr7aVgmdNGJK+N1g+b6DW6VxzbRCjCOejR/hkmpooHE=
github.com/libp2p/go-yamux/v3 v3.0.1/go.mod h1:s2LsDhHbh+RfCsQoICSYt58U2f8ijtPANFD8BmE74Bo=
Expand Down
5 changes: 5 additions & 0 deletions p2p/transport/websocket/LICENSE-APACHE
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
19 changes: 19 additions & 0 deletions p2p/transport/websocket/LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
137 changes: 137 additions & 0 deletions p2p/transport/websocket/addrs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package websocket

import (
"fmt"
"net"
"net/url"
"strconv"

ma "github.com/multiformats/go-multiaddr"
manet "github.com/multiformats/go-multiaddr/net"
)

// Addr is an implementation of net.Addr for WebSocket.
type Addr struct {
*url.URL
}

var _ net.Addr = (*Addr)(nil)

// Network returns the network type for a WebSocket, "websocket".
func (addr *Addr) Network() string {
return "websocket"
}

// NewAddr creates an Addr with `ws` scheme (insecure).
//
// Deprecated. Use NewAddrWithScheme.
func NewAddr(host string) *Addr {
// Older versions of the transport only supported insecure connections (i.e.
// WS instead of WSS). Assume that is the case here.
return NewAddrWithScheme(host, false)
}

// NewAddrWithScheme creates a new Addr using the given host string. isSecure
// should be true for WSS connections and false for WS.
func NewAddrWithScheme(host string, isSecure bool) *Addr {
scheme := "ws"
if isSecure {
scheme = "wss"
}
return &Addr{
URL: &url.URL{
Scheme: scheme,
Host: host,
},
}
}

func ConvertWebsocketMultiaddrToNetAddr(maddr ma.Multiaddr) (net.Addr, error) {
url, err := parseMultiaddr(maddr)
if err != nil {
return nil, err
}
return &Addr{URL: url}, nil
}

func ParseWebsocketNetAddr(a net.Addr) (ma.Multiaddr, error) {
wsa, ok := a.(*Addr)
if !ok {
return nil, fmt.Errorf("not a websocket address")
}

var (
tcpma ma.Multiaddr
err error
port int
host = wsa.Hostname()
)

// Get the port
if portStr := wsa.Port(); portStr != "" {
port, err = strconv.Atoi(portStr)
if err != nil {
return nil, fmt.Errorf("failed to parse port '%q': %s", portStr, err)
}
} else {
return nil, fmt.Errorf("invalid port in url: '%q'", wsa.URL)
}

// NOTE: Ignoring IPv6 zones...
// Detect if host is IP address or DNS
if ip := net.ParseIP(host); ip != nil {
// Assume IP address
tcpma, err = manet.FromNetAddr(&net.TCPAddr{
IP: ip,
Port: port,
})
if err != nil {
return nil, err
}
} else {
// Assume DNS name
tcpma, err = ma.NewMultiaddr(fmt.Sprintf("/dns/%s/tcp/%d", host, port))
if err != nil {
return nil, err
}
}

wsma, err := ma.NewMultiaddr("/" + wsa.Scheme)
if err != nil {
return nil, err
}

return tcpma.Encapsulate(wsma), nil
}

func parseMultiaddr(maddr ma.Multiaddr) (*url.URL, error) {
// Only look at the _last_ component.
maddr, wscomponent := ma.SplitLast(maddr)
if maddr == nil || wscomponent == nil {
return nil, fmt.Errorf("websocket addrs need at least two components")
}

var scheme string
switch wscomponent.Protocol().Code {
case ma.P_WS:
scheme = "ws"
case ma.P_WSS:
scheme = "wss"
default:
return nil, fmt.Errorf("not a websocket multiaddr")
}

network, host, err := manet.DialArgs(maddr)
if err != nil {
return nil, err
}
switch network {
case "tcp", "tcp4", "tcp6":
default:
return nil, fmt.Errorf("unsupported websocket network %s", network)
}
return &url.URL{
Scheme: scheme,
Host: host,
}, nil
}
81 changes: 81 additions & 0 deletions p2p/transport/websocket/addrs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package websocket

import (
"net/url"
"testing"

"github.com/stretchr/testify/require"

ma "github.com/multiformats/go-multiaddr"
)

func TestMultiaddrParsing(t *testing.T) {
addr, err := ma.NewMultiaddr("/ip4/127.0.0.1/tcp/5555/ws")
if err != nil {
t.Fatal(err)
}

wsaddr, err := parseMultiaddr(addr)
if err != nil {
t.Fatal(err)
}
if wsaddr.String() != "ws://127.0.0.1:5555" {
t.Fatalf("expected ws://127.0.0.1:5555, got %s", wsaddr)
}
}

type httpAddr struct {
*url.URL
}

func (addr *httpAddr) Network() string {
return "http"
}

func TestParseWebsocketNetAddr(t *testing.T) {
notWs := &httpAddr{&url.URL{Host: "http://127.0.0.1:1234"}}
_, err := ParseWebsocketNetAddr(notWs)
if err.Error() != "not a websocket address" {
t.Fatalf("expect \"not a websocket address\", got \"%s\"", err)
}

wsAddr := NewAddrWithScheme("127.0.0.1:5555", false)
parsed, err := ParseWebsocketNetAddr(wsAddr)
if err != nil {
t.Fatal(err)
}

if parsed.String() != "/ip4/127.0.0.1/tcp/5555/ws" {
t.Fatalf("expected \"/ip4/127.0.0.1/tcp/5555/ws\", got \"%s\"", parsed.String())
}
}

func TestConvertWebsocketMultiaddrToNetAddr(t *testing.T) {
addr, err := ma.NewMultiaddr("/ip4/127.0.0.1/tcp/5555/ws")
if err != nil {
t.Fatal(err)
}

wsaddr, err := ConvertWebsocketMultiaddrToNetAddr(addr)
if err != nil {
t.Fatal(err)
}
if wsaddr.String() != "ws://127.0.0.1:5555" {
t.Fatalf("expected ws://127.0.0.1:5555, got %s", wsaddr)
}
if wsaddr.Network() != "websocket" {
t.Fatalf("expected network: \"websocket\", got \"%s\"", wsaddr.Network())
}
}

func TestListeningOnDNSAddr(t *testing.T) {
ln, err := newListener(ma.StringCast("/dns/localhost/tcp/0/ws"), nil)
require.NoError(t, err)
addr := ln.Multiaddr()
first, rest := ma.SplitFirst(addr)
require.Equal(t, first.Protocol().Code, ma.P_DNS)
require.Equal(t, first.Value(), "localhost")
next, _ := ma.SplitFirst(rest)
require.Equal(t, next.Protocol().Code, ma.P_TCP)
require.NotEqual(t, next.Value(), "0")
}
Loading