Skip to content

Commit 9979529

Browse files
committed
Add ability to pass through TLS options to the QUIC transport.
1 parent 062200b commit 9979529

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

libp2p_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ func TestTransportConstructorWithWrongOpts(t *testing.T) {
261261
Transport(quic.NewTransport, tcp.DisableReuseport()),
262262
DisableRelay(),
263263
)
264-
require.EqualError(t, err, "transport constructor doesn't take any options")
264+
require.EqualError(t, err, "transport option of type tcp.Option not assignable to libp2pquic.Option")
265265
}
266266

267267
func TestSecurityConstructor(t *testing.T) {

p2p/transport/quic/options.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package libp2pquic
2+
3+
import p2ptls "github.com/libp2p/go-libp2p/p2p/security/tls"
4+
5+
// Option is a function that configures the QUIC transport.
6+
type Option func(o *transportConfig) error
7+
8+
type transportConfig struct {
9+
tlsIdentityOpts []p2ptls.IdentityOption
10+
}
11+
12+
// WithTLSIdentityOption passes the given p2ptls.IdentityOption through to the
13+
// TLS identity used by the QUIC transport.
14+
func WithTLSIdentityOption(opt p2ptls.IdentityOption) Option {
15+
return func(c *transportConfig) error {
16+
c.tlsIdentityOpts = append(c.tlsIdentityOpts, opt)
17+
return nil
18+
}
19+
}

p2p/transport/quic/transport.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,22 @@ type activeHolePunch struct {
7070
}
7171

7272
// NewTransport creates a new QUIC transport
73-
func NewTransport(key ic.PrivKey, connManager *quicreuse.ConnManager, psk pnet.PSK, gater connmgr.ConnectionGater, rcmgr network.ResourceManager) (tpt.Transport, error) {
73+
func NewTransport(key ic.PrivKey, connManager *quicreuse.ConnManager, psk pnet.PSK, gater connmgr.ConnectionGater, rcmgr network.ResourceManager, opts ...Option) (tpt.Transport, error) {
7474
if len(psk) > 0 {
7575
log.Error("QUIC doesn't support private networks yet.")
7676
return nil, errors.New("QUIC doesn't support private networks yet")
7777
}
78+
var cfg transportConfig
79+
for _, opt := range opts {
80+
if err := opt(&cfg); err != nil {
81+
return nil, err
82+
}
83+
}
7884
localPeer, err := peer.IDFromPrivateKey(key)
7985
if err != nil {
8086
return nil, err
8187
}
82-
identity, err := p2ptls.NewIdentity(key)
88+
identity, err := p2ptls.NewIdentity(key, cfg.tlsIdentityOpts...)
8389
if err != nil {
8490
return nil, err
8591
}

0 commit comments

Comments
 (0)