Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add flag to set wss port #297

Merged
merged 1 commit into from
Aug 26, 2022
Merged
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
9 changes: 8 additions & 1 deletion waku.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 12 additions & 2 deletions waku/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -150,11 +152,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 {
Expand Down Expand Up @@ -479,6 +481,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))
Expand Down
3 changes: 2 additions & 1 deletion waku/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions waku/v2/node/wakuoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down