Skip to content

Commit 3d9bdfc

Browse files
authored
Merge pull request #408 from ellemouton/timeLimitFirstLNCConn
multi: add deadline for first connection of new LNC conn
2 parents 03deb1a + 955ce78 commit 3d9bdfc

File tree

13 files changed

+205
-80
lines changed

13 files changed

+205
-80
lines changed

config.go

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ const (
7777
// DefaultMacaroonFilename is the default file name for the
7878
// autogenerated lit macaroon.
7979
DefaultMacaroonFilename = "lit.macaroon"
80+
81+
defaultFirstLNCConnTimeout = 10 * time.Minute
8082
)
8183

8284
var (
@@ -153,6 +155,8 @@ type Config struct {
153155

154156
MacaroonPath string `long:"macaroonpath" description:"Path to write the macaroon for litd's RPC and REST services if it doesn't exist."`
155157

158+
FirstLNCConnDeadline time.Duration `long:"firstlncconndeadline" description:"The duration after a new LNC session will be revoked if no connection is made with it. This only applies for the first connection which is made using the pairing phrase. "`
159+
156160
// Network is the Bitcoin network we're running on. This will be parsed
157161
// before the configuration is loaded and will set the correct flag on
158162
// `lnd.bitcoin.mainnet|testnet|regtest` and also for the other daemons.
@@ -302,21 +306,22 @@ func defaultConfig() *Config {
302306
TLSCertPath: poolDefaultConfig.TLSCertPath,
303307
},
304308
},
305-
Network: DefaultNetwork,
306-
LndMode: DefaultLndMode,
307-
Lnd: &lndDefaultConfig,
308-
LitDir: DefaultLitDir,
309-
LetsEncryptListen: defaultLetsEncryptListen,
310-
LetsEncryptDir: defaultLetsEncryptDir,
311-
MacaroonPath: DefaultMacaroonPath,
312-
ConfigFile: defaultConfigFile,
313-
FaradayMode: defaultFaradayMode,
314-
Faraday: &faradayDefaultConfig,
315-
faradayRpcConfig: &frdrpcserver.Config{},
316-
LoopMode: defaultLoopMode,
317-
Loop: &loopDefaultConfig,
318-
PoolMode: defaultPoolMode,
319-
Pool: &poolDefaultConfig,
309+
Network: DefaultNetwork,
310+
LndMode: DefaultLndMode,
311+
Lnd: &lndDefaultConfig,
312+
LitDir: DefaultLitDir,
313+
LetsEncryptListen: defaultLetsEncryptListen,
314+
LetsEncryptDir: defaultLetsEncryptDir,
315+
MacaroonPath: DefaultMacaroonPath,
316+
ConfigFile: defaultConfigFile,
317+
FaradayMode: defaultFaradayMode,
318+
Faraday: &faradayDefaultConfig,
319+
faradayRpcConfig: &frdrpcserver.Config{},
320+
LoopMode: defaultLoopMode,
321+
Loop: &loopDefaultConfig,
322+
PoolMode: defaultPoolMode,
323+
Pool: &poolDefaultConfig,
324+
FirstLNCConnDeadline: defaultFirstLNCConnTimeout,
320325
}
321326
}
322327

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/improbable-eng/grpc-web v0.12.0
1212
github.com/jessevdk/go-flags v1.4.0
1313
github.com/lightninglabs/faraday v0.2.8-alpha.0.20220624141723-ddd3cd123e62
14-
github.com/lightninglabs/lightning-node-connect v0.1.11-alpha
14+
github.com/lightninglabs/lightning-node-connect v0.1.11-alpha.0.20220822151854-c072f70315d8
1515
github.com/lightninglabs/lndclient v0.15.0-10
1616
github.com/lightninglabs/loop v0.19.1-beta.0.20220623090540-08209f61e304
1717
github.com/lightninglabs/loop/swapserverrpc v1.0.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,8 @@ github.com/lightninglabs/faraday v0.2.8-alpha.0.20220624141723-ddd3cd123e62 h1:t
541541
github.com/lightninglabs/faraday v0.2.8-alpha.0.20220624141723-ddd3cd123e62/go.mod h1:9kcDuyINNf4RB6vrmPLAMGZmYgN0oPxhdt3IicL9sQY=
542542
github.com/lightninglabs/gozmq v0.0.0-20191113021534-d20a764486bf h1:HZKvJUHlcXI/f/O0Avg7t8sqkPo78HFzjmeYFl6DPnc=
543543
github.com/lightninglabs/gozmq v0.0.0-20191113021534-d20a764486bf/go.mod h1:vxmQPeIQxPf6Jf9rM8R+B4rKBqLA2AjttNxkFBL2Plk=
544-
github.com/lightninglabs/lightning-node-connect v0.1.11-alpha h1:d+jKyAvCQMLq5O1IL6ONWM/l4C7Q3Q00HkdjDIG9uTg=
545-
github.com/lightninglabs/lightning-node-connect v0.1.11-alpha/go.mod h1:dgyhE+O4GpWBhS7yIzKCm8LqFHX8/QRwJ6OWFrN+WnA=
544+
github.com/lightninglabs/lightning-node-connect v0.1.11-alpha.0.20220822151854-c072f70315d8 h1:FYZ63sERRC2RjVbsAeO55uF7kTIYCClHmd59dZSsyx0=
545+
github.com/lightninglabs/lightning-node-connect v0.1.11-alpha.0.20220822151854-c072f70315d8/go.mod h1:dgyhE+O4GpWBhS7yIzKCm8LqFHX8/QRwJ6OWFrN+WnA=
546546
github.com/lightninglabs/lightning-node-connect/hashmailrpc v1.0.2 h1:Er1miPZD2XZwcfE4xoS5AILqP1mj7kqnhbBSxW9BDxY=
547547
github.com/lightninglabs/lightning-node-connect/hashmailrpc v1.0.2/go.mod h1:antQGRDRJiuyQF6l+k6NECCSImgCpwaZapATth2Chv4=
548548
github.com/lightninglabs/lndclient v0.15.0-0/go.mod h1:ORS/YFe9hAXlzN/Uj+gvTmrnXEml6yD6dWwzCjpTJyQ=

itest/litd_mode_integrated_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,10 @@ func runLNCAuthTest(t *testing.T, hostPort, tlsCertPath, macPath string,
612612
connectPhrase := strings.Split(
613613
sessResp.Session.PairingSecretMnemonic, " ",
614614
)
615+
616+
ctxt, cancel = context.WithTimeout(ctxb, defaultTimeout)
617+
defer cancel()
618+
615619
rawLNCConn, err := connectMailbox(ctxt, connectPhrase)
616620
require.NoError(t, err)
617621

itest/litd_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,18 @@ import (
88
"time"
99

1010
"github.com/btcsuite/btcd/integration/rpctest"
11+
"github.com/lightninglabs/aperture"
12+
"github.com/lightninglabs/lightning-node-connect/gbn"
13+
"github.com/lightninglabs/lightning-node-connect/mailbox"
14+
"github.com/lightningnetwork/lnd"
15+
"github.com/lightningnetwork/lnd/build"
1116
"github.com/lightningnetwork/lnd/lntest"
17+
"github.com/lightningnetwork/lnd/signal"
1218
"github.com/stretchr/testify/require"
1319
)
1420

21+
var interceptor *signal.Interceptor
22+
1523
// TestLightningTerminal performs a series of integration tests amongst a
1624
// programmatically driven network of lnd nodes.
1725
func TestLightningTerminal(t *testing.T) {
@@ -73,6 +81,7 @@ func TestLightningTerminal(t *testing.T) {
7381
// Now we can set up our test harness (LND instance), with the chain
7482
// backend we just created.
7583
ht := newHarnessTest(t, nil)
84+
ht.setupLogging()
7685
binary := getLitdBinary()
7786
litdHarness, err = NewNetworkHarness(miner, chainBackend, binary)
7887
if err != nil {
@@ -164,3 +173,24 @@ func TestLightningTerminal(t *testing.T) {
164173
}
165174
}
166175
}
176+
177+
func (h *harnessTest) setupLogging() {
178+
logWriter := build.NewRotatingLogWriter()
179+
180+
if interceptor != nil {
181+
return
182+
}
183+
184+
ic, err := signal.Intercept()
185+
require.NoError(h.t, err)
186+
interceptor = &ic
187+
188+
aperture.SetupLoggers(logWriter, *interceptor)
189+
lnd.AddSubLogger(
190+
logWriter, mailbox.Subsystem, *interceptor, mailbox.UseLogger,
191+
)
192+
lnd.AddSubLogger(logWriter, gbn.Subsystem, *interceptor, gbn.UseLogger)
193+
194+
err = build.ParseAndSetDebugLevels("debug", logWriter)
195+
require.NoError(h.t, err)
196+
}

litrpc/lit-sessions.pb.go

Lines changed: 55 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

litrpc/lit-sessions.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ message Session {
7474
bytes local_public_key = 9;
7575

7676
bytes remote_public_key = 10;
77+
78+
uint64 created_at = 11 [jstype = JS_STRING];
7779
}
7880

7981
message ListSessionsRequest {

session/interface.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type Session struct {
4343
State State
4444
Type Type
4545
Expiry time.Time
46+
CreatedAt time.Time
4647
ServerAddr string
4748
DevServer bool
4849
MacaroonRootKey uint64
@@ -78,6 +79,7 @@ func NewSession(label string, typ Type, expiry time.Time, serverAddr string,
7879
State: StateCreated,
7980
Type: typ,
8081
Expiry: expiry,
82+
CreatedAt: time.Now(),
8183
ServerAddr: serverAddr,
8284
DevServer: devServer,
8385
MacaroonRootKey: macRootKey,

session/server.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ func newMailboxSession() *mailboxSession {
3333

3434
func (m *mailboxSession) start(session *Session,
3535
serverCreator GRPCServerCreator, authData []byte,
36-
onUpdate func(sess *Session) error) error {
36+
onUpdate func(sess *Session) error,
37+
onNewStatus func(s mailbox.ServerStatus)) error {
3738

3839
tlsConfig := &tls.Config{}
3940
if session.DevServer {
@@ -52,7 +53,7 @@ func (m *mailboxSession) start(session *Session,
5253

5354
// Start the mailbox gRPC server.
5455
mailboxServer, err := mailbox.NewServer(
55-
session.ServerAddr, keys,
56+
session.ServerAddr, keys, onNewStatus,
5657
grpc.WithTransportCredentials(credentials.NewTLS(tlsConfig)),
5758
grpc.WithKeepaliveParams(keepalive.ClientParameters{
5859
Time: 2 * time.Minute,
@@ -104,7 +105,8 @@ func NewServer(serverCreator GRPCServerCreator) *Server {
104105
}
105106

106107
func (s *Server) StartSession(session *Session, authData []byte,
107-
onUpdate func(sess *Session) error) (chan struct{}, error) {
108+
onUpdate func(sess *Session) error,
109+
onNewStatus func(s mailbox.ServerStatus)) (chan struct{}, error) {
108110

109111
s.activeSessionsMtx.Lock()
110112
defer s.activeSessionsMtx.Unlock()
@@ -121,7 +123,7 @@ func (s *Server) StartSession(session *Session, authData []byte,
121123
s.activeSessions[id] = sess
122124

123125
return sess.quit, sess.start(
124-
session, s.serverCreator, authData, onUpdate,
126+
session, s.serverCreator, authData, onUpdate, onNewStatus,
125127
)
126128
}
127129

0 commit comments

Comments
 (0)