-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
multi: move challenger and secrets files to new packages so they can …
…be imported elsewhere. This commit: - Moves challenger and secrets files to new packages so they can be imported elsewhere. - Alters NewLndChallenger so that it takes the lnd client in as a parameter. (This is useful in the case of using NewLndChallenger in the lnd watchtower project, to avoid having to import lndclient, which leads to` an import cycle.)
- Loading branch information
1 parent
b952e4e
commit c43f4a8
Showing
10 changed files
with
135 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package challenger | ||
|
||
import ( | ||
"github.com/btcsuite/btclog" | ||
"github.com/lightningnetwork/lnd/build" | ||
) | ||
|
||
const Subsystem = "CHAL" | ||
|
||
// log is a logger that is initialized with no output filters. This | ||
// means the package will not perform any logging by default until the caller | ||
// requests it. | ||
var log btclog.Logger | ||
|
||
// The default amount of logging is none. | ||
func init() { | ||
UseLogger(build.NewSubLogger(Subsystem, nil)) | ||
} | ||
|
||
// DisableLog disables all library log output. Logging output is disabled | ||
// by default until UseLogger is called. | ||
func DisableLog() { | ||
UseLogger(btclog.Disabled) | ||
} | ||
|
||
// UseLogger uses a specified Logger to output package logging info. | ||
// This should be used in preference to SetLogWriter if the caller is also | ||
// using btclog. | ||
func UseLogger(logger btclog.Logger) { | ||
log = logger | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package secrets | ||
|
||
import ( | ||
"io/ioutil" | ||
"net/url" | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
clientv3 "go.etcd.io/etcd/client/v3" | ||
"go.etcd.io/etcd/server/v3/embed" | ||
) | ||
|
||
// EtcdSetup is a helper that instantiates a new etcd cluster along with a | ||
// client connection to it. A cleanup closure is also returned to free any | ||
// allocated resources required by etcd. | ||
func EtcdSetup(t *testing.T) (*clientv3.Client, func()) { | ||
t.Helper() | ||
|
||
tempDir, err := ioutil.TempDir("", "etcd") | ||
if err != nil { | ||
t.Fatalf("unable to create temp dir: %v", err) | ||
} | ||
|
||
cfg := embed.NewConfig() | ||
cfg.Dir = tempDir | ||
cfg.Logger = "zap" | ||
cfg.LCUrls = []url.URL{{Host: "127.0.0.1:9125"}} | ||
cfg.LPUrls = []url.URL{{Host: "127.0.0.1:9126"}} | ||
|
||
etcd, err := embed.StartEtcd(cfg) | ||
if err != nil { | ||
os.RemoveAll(tempDir) | ||
t.Fatalf("unable to start etcd: %v", err) | ||
} | ||
|
||
select { | ||
case <-etcd.Server.ReadyNotify(): | ||
case <-time.After(5 * time.Second): | ||
os.RemoveAll(tempDir) | ||
etcd.Server.Stop() // trigger a shutdown | ||
t.Fatal("server took too long to start") | ||
} | ||
|
||
client, err := clientv3.New(clientv3.Config{ | ||
Endpoints: []string{cfg.LCUrls[0].Host}, | ||
DialTimeout: 5 * time.Second, | ||
}) | ||
if err != nil { | ||
t.Fatalf("unable to connect to etcd: %v", err) | ||
} | ||
|
||
return client, func() { | ||
etcd.Close() | ||
os.RemoveAll(tempDir) | ||
} | ||
} |