This repository was archived by the owner on Jul 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathlnd.patch
More file actions
242 lines (236 loc) · 5.76 KB
/
Copy pathlnd.patch
File metadata and controls
242 lines (236 loc) · 5.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
diff --git a/.gitignore b/.gitignore
index 39d610dc..104b2c67 100644
--- a/.gitignore
+++ b/.gitignore
@@ -53,3 +53,4 @@ profile.tmp
.DS_Store
main*
+rtx_export*
diff --git a/lnd.go b/lnd.go
index e323e95d..72852834 100644
--- a/lnd.go
+++ b/lnd.go
@@ -446,6 +446,8 @@ func lndMain() error {
// Wait for shutdown signal from either a graceful server stop or from
// the interrupt handler.
<-signal.ShutdownChannel()
+ ltndLog.Info("Shutdown complete")
+ shutdownSuccessChannel <- true
return nil
}
@@ -530,10 +532,9 @@ func genCertPair(certFile, keyFile string) error {
}
// Collect the host's names into a slice.
- host, err := os.Hostname()
- if err != nil {
- return err
- }
+ // Android doesn't allow accessing /proc/sys
+ // which is used by the os.Hostname call.
+ host := "localhost"
dnsNames := []string{host}
if host != "localhost" {
dnsNames = append(dnsNames, "localhost")
@@ -863,5 +864,9 @@ func waitForWalletPassword(grpcEndpoints, restEndpoints []net.Addr,
case <-signal.ShutdownChannel():
return nil, fmt.Errorf("shutting down")
+
+ // case <-signal.shutdownRequestChannel:
+ // shutdownSuccessChannel <- true
+ // return nil, fmt.Errorf("shutting down")
}
}
diff --git a/rtx_config.go b/rtx_config.go
new file mode 100644
index 00000000..6d9ed569
--- /dev/null
+++ b/rtx_config.go
@@ -0,0 +1,125 @@
+package main
+
+/*
+#ifdef SWIG
+%newobject InitLnd;
+#endif
+*/
+import "C"
+import (
+ "fmt"
+ "os"
+ "path/filepath"
+
+ "github.com/lightningnetwork/lnd/channeldb"
+ "github.com/lightningnetwork/lnd/signal"
+)
+
+var (
+ channelDB *channeldb.DB
+ shutdownSuccessChannel = make(chan bool, 1)
+ fout *os.File = nil
+ ferr *os.File = nil
+)
+
+type Shutdown struct{}
+
+//InitLnd initializes lnd, lndHomeDir is coming from host app.
+// lndHomeDir could be for example in android /data/user/0/com.rtxwallet/files.
+//export InitLnd
+func InitLnd(lndHomeDir *C.char) *C.char {
+ lndHomeDirString := C.GoString(lndHomeDir)
+ err := initLnd(lndHomeDirString)
+ if err != nil {
+ shutdownStdout()
+ return C.CString(err.Error())
+ }
+ return C.CString("")
+}
+
+//export SetStdout
+func SetStdout(lndHomeDir *C.char) {
+ setStdout(C.GoString(lndHomeDir))
+}
+
+//export StopLnd
+func StopLnd() bool {
+ // shutdownRequestChannel <- struct{}{}
+ signal.RequestShutdown()
+ success := <-shutdownSuccessChannel
+ shutdownStdout()
+ return success
+}
+
+//export TestPanic
+func TestPanic() {
+ panic("Testing panic!")
+}
+
+//export StartLnd
+func StartLnd() *C.char {
+ defer func() {
+ if x := recover(); x != nil {
+ ltndLog.Errorf("run time panic: %v", x)
+ }
+ }()
+ err := lndMain()
+ if err != nil {
+ return C.CString(err.Error())
+ }
+ return C.CString("")
+}
+
+func setStdout(lndHomeDir string) {
+ fileout := filepath.Join(lndHomeDir, "stdout")
+ fout, _ = os.Create(fileout)
+ os.Stdout = fout
+
+ fileerr := filepath.Join(lndHomeDir, "stdout")
+ ferr, _ = os.Create(fileerr)
+ os.Stderr = ferr
+}
+
+func shutdownStdout() {
+ if fout != nil {
+ fout.Close()
+ }
+ if ferr != nil {
+ ferr.Close()
+ }
+}
+
+func initLnd(lndHomeDir string) error {
+ setDefaultVars(lndHomeDir)
+
+ lndCfg, err := loadConfig()
+ if err != nil {
+ fmt.Println(err)
+ return err
+ }
+ cfg = lndCfg
+ return nil
+}
+
+func setDefaultVars(lndHomeDir string) {
+ if lndHomeDir == "" {
+ // If lndHomeDir is null, just leave the defaults as is.
+ return
+ }
+ defaultLndDir = lndHomeDir
+ defaultConfigFile = filepath.Join(defaultLndDir, defaultConfigFilename)
+ defaultDataDir = filepath.Join(defaultLndDir, defaultDataDirname)
+ defaultLogDir = filepath.Join(defaultLndDir, defaultLogDirname)
+
+ defaultTLSCertPath = filepath.Join(defaultLndDir, defaultTLSCertFilename)
+ defaultTLSKeyPath = filepath.Join(defaultLndDir, defaultTLSKeyFilename)
+
+ defaultBtcdDir = filepath.Join(lndHomeDir, "btcd", "default")
+ defaultBtcdRPCCertFile = filepath.Join(defaultBtcdDir, "rpc.cert")
+
+ defaultLtcdDir = filepath.Join(lndHomeDir, "ltcd", "default")
+ defaultLtcdRPCCertFile = filepath.Join(defaultLtcdDir, "rpc.cert")
+
+ defaultBitcoindDir = filepath.Join(lndHomeDir, "bitcoin", "default")
+ defaultLitecoindDir = filepath.Join(lndHomeDir, "litecoin", "default")
+}
diff --git a/rtx_utils.go b/rtx_utils.go
new file mode 100644
index 00000000..bea942a4
--- /dev/null
+++ b/rtx_utils.go
@@ -0,0 +1,37 @@
+package main
+
+// ***NOTE***
+// This file isn't actually useful because the
+// methods exposed by this file aren't actually used.
+// (maybe using getlndversion makes sense...).
+// But it's a good example of exposing different
+// kinds of functions (%newobject + C.char, etc.).
+
+/*
+#include <stdlib.h>
+
+#ifdef SWIG
+%newobject GetEnv;
+%newobject GetLndVersion;
+#endif
+
+*/
+import "C"
+import (
+ "os"
+)
+
+//export GetEnv
+func GetEnv(v *C.char) *C.char {
+ return C.CString(os.Getenv(C.GoString(v)))
+}
+
+//export SetEnv
+func SetEnv(key *C.char, val *C.char) {
+ os.Setenv(C.GoString(key), C.GoString(val))
+}
+
+//export GetLndVersion
+func GetLndVersion() *C.char {
+ return C.CString(version())
+}
diff --git a/server.go b/server.go
index 35ef3689..5b64d3a4 100644
--- a/server.go
+++ b/server.go
@@ -43,7 +43,7 @@ import (
const (
// defaultMinPeers is the minimum number of peers nodes should always be
// connected to.
- defaultMinPeers = 3
+ defaultMinPeers = 20
// defaultBackoff is the starting point for exponential backoff for
// reconnecting to persistent peers.
@@ -1278,7 +1278,7 @@ func (s *server) peerBootstrapper(numTargetPeers uint32,
//
// We'll use a 15 second backoff, and double the time every time an
// epoch fails up to a ceiling.
- const backOffCeiling = time.Minute * 5
+ const backOffCeiling = time.Minute * 1
backOff := time.Second * 15
// We'll create a new ticker to wake us up every 15 seconds so we can