feat: add flag to set wss port

This commit is contained in:
Richard Ramos 2022-08-25 16:36:04 -04:00
parent e201528da7
commit a1e5b587a2
4 changed files with 27 additions and 4 deletions

View File

@ -44,7 +44,14 @@ func main() {
Aliases: []string{"ws-port"},
Value: 60001,
Usage: "Libp2p TCP listening port for websocket connection (0 for random)",
Destination: &options.Websocket.Port,
Destination: &options.Websocket.WSPort,
},
&cli.IntFlag{
Name: "websocket-secure-port",
Aliases: []string{"wss-port"},
Value: 6443,
Usage: "Libp2p TCP listening port for secure websocket connection (0 for random, binding to 443 requires root access)",
Destination: &options.Websocket.WSSPort,
},
&cli.StringFlag{
Name: "websocket-address",

View File

@ -26,9 +26,11 @@ import (
"github.com/libp2p/go-libp2p-core/discovery"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p/config"
"github.com/libp2p/go-libp2p/p2p/transport/tcp"
"github.com/libp2p/go-libp2p-peerstore/pstoreds"
pubsub "github.com/libp2p/go-libp2p-pubsub"
ws "github.com/libp2p/go-libp2p/p2p/transport/websocket"
"github.com/multiformats/go-multiaddr"
rendezvous "github.com/status-im/go-waku-rendezvous"
"github.com/status-im/go-waku/logging"
@ -152,11 +154,11 @@ func Execute(options Options) {
}
if options.Websocket.Enable {
nodeOpts = append(nodeOpts, node.WithWebsockets(options.Websocket.Address, options.Websocket.Port))
nodeOpts = append(nodeOpts, node.WithWebsockets(options.Websocket.Address, options.Websocket.WSPort))
}
if options.Websocket.Secure {
nodeOpts = append(nodeOpts, node.WithSecureWebsockets(options.Websocket.Address, options.Websocket.Port, options.Websocket.CertPath, options.Websocket.KeyPath))
nodeOpts = append(nodeOpts, node.WithSecureWebsockets(options.Websocket.Address, options.Websocket.WSSPort, options.Websocket.CertPath, options.Websocket.KeyPath))
}
if options.ShowAddresses {
@ -487,6 +489,14 @@ func printListeningAddresses(ctx context.Context, nodeOpts []node.WakuNodeOption
libp2p.ListenAddrs(params.MultiAddresses()...),
)
if options.Websocket.Secure {
transports := libp2p.ChainOptions(
libp2p.Transport(tcp.NewTCPTransport),
libp2p.Transport(ws.New, ws.WithTLSConfig(params.TLSConfig())),
)
libp2pOpts = append(libp2pOpts, transports)
}
addrFactory := params.AddressFactory()
if addrFactory != nil {
libp2pOpts = append(libp2pOpts, libp2p.AddrsFactory(addrFactory))

View File

@ -138,7 +138,8 @@ type RESTServerOptions struct {
// support
type WSOptions struct {
Enable bool
Port int
WSPort int
WSSPort int
Address string
Secure bool
KeyPath string

View File

@ -121,6 +121,11 @@ func (w WakuNodeParameters) Identity() config.Option {
return libp2p.Identity(*w.GetPrivKey())
}
// TLSConfig returns the TLS config used for setting up secure websockets
func (w WakuNodeParameters) TLSConfig() *tls.Config {
return w.tlsConfig
}
// AddressFactory returns the address factory used by the node's host
func (w WakuNodeParameters) AddressFactory() basichost.AddrsFactory {
return w.addressFactory