Use quic and use tls by default in restapi and restapi client
(cherry picked from commit 7ab1cd66ed17fda923b149628cae18ea96d1cf45)
This commit is contained in:
parent
1214aabf5b
commit
c7f37ce9f4
|
@ -14,6 +14,9 @@ import (
|
|||
ipnet "github.com/libp2p/go-libp2p-core/pnet"
|
||||
p2phttp "github.com/libp2p/go-libp2p-http"
|
||||
pnet "github.com/libp2p/go-libp2p-pnet"
|
||||
libp2pquic "github.com/libp2p/go-libp2p-quic-transport"
|
||||
secio "github.com/libp2p/go-libp2p-secio"
|
||||
libp2ptls "github.com/libp2p/go-libp2p-tls"
|
||||
madns "github.com/multiformats/go-multiaddr-dns"
|
||||
)
|
||||
|
||||
|
@ -63,7 +66,17 @@ func (c *defaultClient) enableLibp2p() error {
|
|||
}
|
||||
}
|
||||
|
||||
h, err := libp2p.New(c.ctx, libp2p.PrivateNetwork(prot))
|
||||
h, err := libp2p.New(c.ctx,
|
||||
libp2p.PrivateNetwork(prot),
|
||||
libp2p.ChainOptions(
|
||||
libp2p.Security(libp2ptls.ID, libp2ptls.New),
|
||||
libp2p.Security(secio.ID, secio.New),
|
||||
),
|
||||
libp2p.ChainOptions(
|
||||
libp2p.Transport(libp2pquic.NewTransport),
|
||||
libp2p.DefaultTransports,
|
||||
),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -35,6 +35,9 @@ import (
|
|||
rpc "github.com/libp2p/go-libp2p-gorpc"
|
||||
gostream "github.com/libp2p/go-libp2p-gostream"
|
||||
p2phttp "github.com/libp2p/go-libp2p-http"
|
||||
libp2pquic "github.com/libp2p/go-libp2p-quic-transport"
|
||||
secio "github.com/libp2p/go-libp2p-secio"
|
||||
libp2ptls "github.com/libp2p/go-libp2p-tls"
|
||||
ma "github.com/multiformats/go-multiaddr"
|
||||
manet "github.com/multiformats/go-multiaddr-net"
|
||||
|
||||
|
@ -238,6 +241,14 @@ func (api *API) setupLibp2p() error {
|
|||
context.Background(),
|
||||
libp2p.Identity(api.config.PrivateKey),
|
||||
libp2p.ListenAddrs([]ma.Multiaddr{api.config.Libp2pListenAddr}...),
|
||||
libp2p.ChainOptions(
|
||||
libp2p.Security(libp2ptls.ID, libp2ptls.New),
|
||||
libp2p.Security(secio.ID, secio.New),
|
||||
),
|
||||
libp2p.ChainOptions(
|
||||
libp2p.Transport(libp2pquic.NewTransport),
|
||||
libp2p.DefaultTransports,
|
||||
),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -9,10 +9,10 @@ import (
|
|||
autonat "github.com/libp2p/go-libp2p-autonat-svc"
|
||||
relay "github.com/libp2p/go-libp2p-circuit"
|
||||
connmgr "github.com/libp2p/go-libp2p-connmgr"
|
||||
ipnet "github.com/libp2p/go-libp2p-core/pnet"
|
||||
routing "github.com/libp2p/go-libp2p-core/routing"
|
||||
crypto "github.com/libp2p/go-libp2p-crypto"
|
||||
host "github.com/libp2p/go-libp2p-host"
|
||||
ipnet "github.com/libp2p/go-libp2p-interface-pnet"
|
||||
dht "github.com/libp2p/go-libp2p-kad-dht"
|
||||
pnet "github.com/libp2p/go-libp2p-pnet"
|
||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||
|
@ -86,8 +86,8 @@ func newHost(ctx context.Context, secret []byte, priv crypto.PrivKey, opts ...li
|
|||
}
|
||||
}
|
||||
|
||||
finalOpts := []libp2p.Option{
|
||||
libp2p.Identity(priv),
|
||||
// common options between libp2p host and autonat service
|
||||
commonOpts := []libp2p.Option{
|
||||
libp2p.PrivateNetwork(prot),
|
||||
libp2p.ChainOptions(
|
||||
libp2p.Security(libp2ptls.ID, libp2ptls.New),
|
||||
|
@ -98,18 +98,20 @@ func newHost(ctx context.Context, secret []byte, priv crypto.PrivKey, opts ...li
|
|||
libp2p.DefaultTransports,
|
||||
),
|
||||
}
|
||||
finalOpts = append(finalOpts, opts...)
|
||||
|
||||
hOpts := append([]libp2p.Option{libp2p.Identity(priv)}, commonOpts...)
|
||||
hOpts = append(hOpts, opts...)
|
||||
|
||||
h, err := libp2p.New(
|
||||
ctx,
|
||||
finalOpts...,
|
||||
hOpts...,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// need this for auto relay
|
||||
_, err = autonat.NewAutoNATService(ctx, h, libp2p.PrivateNetwork(prot))
|
||||
_, err = autonat.NewAutoNATService(ctx, h, commonOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user