Commit 319266a5 authored by Janoš Guljaš's avatar Janoš Guljaš Committed by GitHub

use only libp2p default security to avoid websockets data race (#19)

parent 0244bad5
......@@ -13,8 +13,8 @@ require (
github.com/libp2p/go-libp2p-core v0.3.0
github.com/libp2p/go-libp2p-peerstore v0.1.4
github.com/libp2p/go-libp2p-quic-transport v0.2.2
github.com/libp2p/go-libp2p-secio v0.2.1
github.com/libp2p/go-libp2p-tls v0.1.3
github.com/libp2p/go-tcp-transport v0.1.1
github.com/libp2p/go-ws-transport v0.2.0
github.com/multiformats/go-multiaddr v0.2.0
github.com/multiformats/go-multistream v0.1.0
github.com/prometheus/client_golang v1.3.0
......
......@@ -250,6 +250,7 @@ github.com/libp2p/go-libp2p-testing v0.0.4/go.mod h1:gvchhf3FQOtBdr+eFUABet5a4MB
github.com/libp2p/go-libp2p-testing v0.1.0/go.mod h1:xaZWMJrPUM5GlDBxCeGUi7kI4eqnjVyavGroI2nxEM0=
github.com/libp2p/go-libp2p-testing v0.1.1 h1:U03z3HnGI7Ni8Xx6ONVZvUFOAzWYmolWf5W5jAOPNmU=
github.com/libp2p/go-libp2p-testing v0.1.1/go.mod h1:xaZWMJrPUM5GlDBxCeGUi7kI4eqnjVyavGroI2nxEM0=
github.com/libp2p/go-libp2p-tls v0.1.1 h1:tjW7njTM8JX8FbEvqr8/VSKBdZYZ7CtGtv3i6NiFf10=
github.com/libp2p/go-libp2p-tls v0.1.1/go.mod h1:wZfuewxOndz5RTnCAxFliGjvYSDA40sKitV4c50uI1M=
github.com/libp2p/go-libp2p-tls v0.1.3 h1:twKMhMu44jQO+HgQK9X8NHO5HkeJu2QbhLzLJpa8oNM=
github.com/libp2p/go-libp2p-tls v0.1.3/go.mod h1:wZfuewxOndz5RTnCAxFliGjvYSDA40sKitV4c50uI1M=
......
......@@ -28,8 +28,8 @@ import (
protocol "github.com/libp2p/go-libp2p-core/protocol"
"github.com/libp2p/go-libp2p-peerstore/pstoremem"
libp2pquic "github.com/libp2p/go-libp2p-quic-transport"
secio "github.com/libp2p/go-libp2p-secio"
libp2ptls "github.com/libp2p/go-libp2p-tls"
"github.com/libp2p/go-tcp-transport"
ws "github.com/libp2p/go-ws-transport"
ma "github.com/multiformats/go-multiaddr"
"github.com/multiformats/go-multistream"
)
......@@ -102,17 +102,12 @@ func New(ctx context.Context, o Options) (*Service, error) {
}
}
security := libp2p.DefaultSecurity
libp2pPeerstore := pstoremem.NewPeerstore()
opts := []libp2p.Option{
// Multiple listen addresses
libp2p.ListenAddrStrings(listenAddrs...),
// support TLS connections
libp2p.Security(libp2ptls.ID, libp2ptls.New),
// support secio connections
libp2p.Security(secio.ID, secio.New),
// support any other default transports (TCP)
libp2p.DefaultTransports,
security,
// Attempt to open ports using uPNP for NATed hosts.
libp2p.NATPortMap(),
// Use dedicated peerstore instead the global DefaultPeerstore
......@@ -125,13 +120,20 @@ func New(ctx context.Context, o Options) (*Service, error) {
)
}
transports := []libp2p.Option{
libp2p.Transport(tcp.NewTCPTransport),
}
if !o.DisableWS {
transports = append(transports, libp2p.Transport(ws.New))
}
if !o.DisableQUIC {
opts = append(opts,
// support QUIC - experimental
libp2p.Transport(libp2pquic.NewTransport),
)
transports = append(transports, libp2p.Transport(libp2pquic.NewTransport))
}
opts = append(opts, transports...)
h, err := libp2p.New(ctx, opts...)
if err != nil {
return nil, err
......@@ -143,10 +145,7 @@ func New(ctx context.Context, o Options) (*Service, error) {
if _, err = autonat.NewAutoNATService(ctx, h,
// Support same non default security and transport options as
// original host.
libp2p.Security(libp2ptls.ID, libp2ptls.New),
libp2p.Security(secio.ID, secio.New),
libp2p.Transport(libp2pquic.NewTransport),
libp2p.DefaultTransports,
append(transports, security)...,
); err != nil {
return nil, fmt.Errorf("autonat: %w", err)
}
......
......@@ -27,13 +27,6 @@ import (
func newService(t *testing.T, o libp2p.Options) (s *libp2p.Service, overlay swarm.Address, cleanup func()) {
t.Helper()
// disable ws until the race condition in:
// github.com/gorilla/websocket@v1.4.1/conn.go:614
// github.com/gorilla/websocket@v1.4.1/conn.go:781
// using github.com/libp2p/go-libp2p-transport-upgrader@v0.1.1
// is solved
o.DisableWS = true
if o.PrivateKey == nil {
var err error
o.PrivateKey, err = crypto.GenerateSecp256k1Key()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment