Skip to content

webrtc transport breaks compilation for WASM even if it not specified in transports #3359

@talentlessguy

Description

@talentlessguy

Currently if you try to compile the most basic libp2p host with 0 transports and no listeners like this:

package main

import (
	"log"

	"github.com/libp2p/go-libp2p"
	"github.com/libp2p/go-libp2p/core/crypto"
	"github.com/libp2p/go-libp2p/p2p/security/noise"
)

func main() {
	priv, _, err := crypto.GenerateKeyPair(
		crypto.Ed25519,
		-1,
	)
	if err != nil {
		panic(err)
	}

	if err != nil {
		panic(err)
	}
	h2, err := libp2p.NewWithoutDefaults(
		libp2p.Identity(priv),
		libp2p.NoListenAddrs,
		libp2p.Security(noise.ID, noise.New),
		libp2p.NoTransports,
	)
	if err != nil {
		panic(err)
	}
	defer h2.Close()
}

it will fail during compilation:

GOOS=js GOARCH=wasm go build
# github.com/libp2p/go-libp2p/p2p/transport/webrtc
/home/v1rtl/go/pkg/mod/github.com/libp2p/[email protected]/p2p/transport/webrtc/connection.go:109:12: pc.SCTP().OnClose undefined (type *webrtc.SCTPTransport has no field or method OnClose)
/home/v1rtl/go/pkg/mod/github.com/libp2p/[email protected]/p2p/transport/webrtc/listener.go:68:35: config.Certificates undefined (type webrtc.Configuration has no field or method Certificates)
/home/v1rtl/go/pkg/mod/github.com/libp2p/[email protected]/p2p/transport/webrtc/listener.go:199:40: unknown field LoggerFactory in struct literal of type webrtc.SettingEngine
/home/v1rtl/go/pkg/mod/github.com/libp2p/[email protected]/p2p/transport/webrtc/listener.go:200:16: settingEngine.SetAnsweringDTLSRole undefined (type webrtc.SettingEngine has no field or method SetAnsweringDTLSRole)
// ...

my guess is that it fails because webrtc transport is imported in multiple places (or maybe hust here) which breaks compilation:

/home/v1rtl/Coding/forks/go-libp2p/p2p/protocol/autonatv2/client.go:17: libp2pwebrtc "github.com/libp2p/go-libp2p/p2p/transport/webrtc"

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions