Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 libp2p_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func TestTransportConstructorWithWrongOpts(t *testing.T) {
Transport(quic.NewTransport, tcp.DisableReuseport()),
DisableRelay(),
)
require.EqualError(t, err, "transport constructor doesn't take any options")
require.EqualError(t, err, "transport option of type tcp.Option not assignable to libp2pquic.Option")
}

func TestSecurityConstructor(t *testing.T) {
Expand Down
19 changes: 19 additions & 0 deletions p2p/transport/quic/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package libp2pquic

import p2ptls "github.com/libp2p/go-libp2p/p2p/security/tls"

// Option is a function that configures the QUIC transport.
type Option func(o *transportConfig) error

type transportConfig struct {
tlsIdentityOpts []p2ptls.IdentityOption
}

// WithTLSIdentityOption passes the given p2ptls.IdentityOption through to the
// TLS identity used by the QUIC transport.
func WithTLSIdentityOption(opt p2ptls.IdentityOption) Option {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: callers wanting several must call it N times. A variadic WithTLSIdentityOptions(opts ...p2ptls.IdentityOption) would read slightly better and match the surrounding variadic style (but fine either way)

return func(c *transportConfig) error {
c.tlsIdentityOpts = append(c.tlsIdentityOpts, opt)
return nil
}
}
10 changes: 8 additions & 2 deletions p2p/transport/quic/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,22 @@ type activeHolePunch struct {
}

// NewTransport creates a new QUIC transport
func NewTransport(key ic.PrivKey, connManager *quicreuse.ConnManager, psk pnet.PSK, gater connmgr.ConnectionGater, rcmgr network.ResourceManager) (tpt.Transport, error) {
func NewTransport(key ic.PrivKey, connManager *quicreuse.ConnManager, psk pnet.PSK, gater connmgr.ConnectionGater, rcmgr network.ResourceManager, opts ...Option) (tpt.Transport, error) {
if len(psk) > 0 {
log.Error("QUIC doesn't support private networks yet.")
return nil, errors.New("QUIC doesn't support private networks yet")
}
var cfg transportConfig
for _, opt := range opts {
if err := opt(&cfg); err != nil {
return nil, err
}
}
localPeer, err := peer.IDFromPrivateKey(key)
if err != nil {
return nil, err
}
identity, err := p2ptls.NewIdentity(key)
identity, err := p2ptls.NewIdentity(key, cfg.tlsIdentityOpts...)
if err != nil {
return nil, err
}
Expand Down
Loading