From 5df69cf93fe1bdfad6927384fce75aadcf2a347e Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Tue, 27 Apr 2021 15:47:34 +0200 Subject: [PATCH] config+lnd: make WebSocket interval/wait configurable To make it possible to adapt the WebSocket ping interval and pong wait time to custom situations, we add new configuration flags to customize them. --- config.go | 5 +++++ lnd.go | 2 +- sample-lnd.conf | 9 +++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/config.go b/config.go index 2052acda..03aef25c 100644 --- a/config.go +++ b/config.go @@ -31,6 +31,7 @@ import ( "github.com/lightningnetwork/lnd/htlcswitch/hodl" "github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/lncfg" + "github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc/routerrpc" "github.com/lightningnetwork/lnd/lnrpc/signrpc" "github.com/lightningnetwork/lnd/lnwallet" @@ -246,6 +247,8 @@ type Config struct { DisableListen bool `long:"nolisten" description:"Disable listening for incoming peer connections"` DisableRest bool `long:"norest" description:"Disable REST API"` DisableRestTLS bool `long:"no-rest-tls" description:"Disable TLS for REST connections"` + WSPingInterval time.Duration `long:"ws-ping-interval" description:"The ping interval for REST based WebSocket connections, set to 0 to disable sending ping messages from the server side"` + WSPongWait time.Duration `long:"ws-pong-wait" description:"The time we wait for a pong response message on REST based WebSocket connections before the connection is closed as inactive"` NAT bool `long:"nat" description:"Toggle NAT traversal support (using either UPnP or NAT-PMP) to automatically advertise your external IP address to the network -- NOTE this does not support devices behind multiple NATs"` MinBackoff time.Duration `long:"minbackoff" description:"Shortest backoff when reconnecting to persistent peers. Valid time units are {s, m, h}."` MaxBackoff time.Duration `long:"maxbackoff" description:"Longest backoff when reconnecting to persistent peers. Valid time units are {s, m, h}."` @@ -390,6 +393,8 @@ func DefaultConfig() Config { MaxLogFiles: defaultMaxLogFiles, MaxLogFileSize: defaultMaxLogFileSize, AcceptorTimeout: defaultAcceptorTimeout, + WSPingInterval: lnrpc.DefaultPingInterval, + WSPongWait: lnrpc.DefaultPongWait, Bitcoin: &lncfg.Chain{ MinHTLCIn: chainreg.DefaultBitcoinMinHTLCInMSat, MinHTLCOut: chainreg.DefaultBitcoinMinHTLCOutMSat, diff --git a/lnd.go b/lnd.go index 53d60601..85c27368 100644 --- a/lnd.go +++ b/lnd.go @@ -1266,7 +1266,7 @@ func startRestProxy(cfg *Config, rpcServer *rpcServer, restDialOpts []grpc.DialO // Wrap the default grpc-gateway handler with the WebSocket handler. restHandler := lnrpc.NewWebSocketProxy( - mux, rpcsLog, lnrpc.DefaultPingInterval, lnrpc.DefaultPongWait, + mux, rpcsLog, cfg.WSPingInterval, cfg.WSPongWait, lnrpc.LndClientStreamingURIs, ) diff --git a/sample-lnd.conf b/sample-lnd.conf index 4659c1ce..1a56ba42 100644 --- a/sample-lnd.conf +++ b/sample-lnd.conf @@ -184,6 +184,15 @@ ; Disable TLS for the REST API. ; no-rest-tls=true +; The ping interval for REST based WebSocket connections, set to 0 to disable +; sending ping messages from the server side. Valid time units are {s, m, h}. +; ws-ping-interval=30s + +; The time we wait for a pong response message on REST based WebSocket +; connections before the connection is closed as inactive. Valid time units are +; {s, m, h}. +; ws-pong-wait=5s + ; Shortest backoff when reconnecting to persistent peers. Valid time units are ; {s, m, h}. ; minbackoff=1s