From 6921cd4b2d6994e67f50a766af36d567a02bc279 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Sat, 28 May 2022 12:13:44 +0200 Subject: [PATCH] config --- README.md | 2 +- config.go | 16 ++++++++++++---- config.yaml => config.yaml.example | 1 + main.go | 15 +++++++++++---- 4 files changed, 25 insertions(+), 9 deletions(-) rename config.yaml => config.yaml.example (79%) diff --git a/README.md b/README.md index f59c851..ed5d6b2 100644 --- a/README.md +++ b/README.md @@ -11,4 +11,4 @@ go build . ``` ## Config -Edit `config.yaml` +Edit `config.yaml.example` and rename to `config.yaml`. diff --git a/config.go b/config.go index 3bff3e0..bde5762 100644 --- a/config.go +++ b/config.go @@ -4,13 +4,15 @@ import ( "fmt" "github.com/jinzhu/configor" + log "github.com/sirupsen/logrus" ) var Configuration = struct { - Host string `yaml:"host"` - MacaroonPath string `yaml:"macaroon_path"` - TLSPath string `yaml:"tls_path"` - Accept []string `yaml:"accept"` + Host string `yaml:"host"` + MacaroonPath string `yaml:"macaroon_path"` + TLSPath string `yaml:"tls_path"` + Accept []string `yaml:"accept"` + RejectMessage string `yaml:"reject_message"` }{} func init() { @@ -25,7 +27,13 @@ func checkConfig() { if Configuration.Host == "" { panic(fmt.Errorf("no host specified in config.yaml")) } + if len(Configuration.Accept) == 0 { panic(fmt.Errorf("no accepted pubkeys specified in config.yaml")) } + + if len(Configuration.RejectMessage) > 500 { + log.Warnf("reject message is too long. Trimming to 500 characters.") + Configuration.RejectMessage = Configuration.RejectMessage[:500] + } } diff --git a/config.yaml b/config.yaml.example similarity index 79% rename from config.yaml rename to config.yaml.example index c3f47b6..003370e 100644 --- a/config.yaml +++ b/config.yaml.example @@ -1,6 +1,7 @@ host: "127.0.0.1:10009" macaroon_path: "/home/bitcoin/.lnd/data/chain/bitcoin/regtest/admin.macaroon" tls_path: "/home/bitcoin/.lnd/tls.cert" +reject_message: "Contact me at user@email.com to be added to the white list." accept: - "03de70865239e99460041e127647b37101b9eb335b3c22de95c944671f0dabc2d0" - "0307299a290529c5ccb3a5e3bd2eb504daf64cc65c6d65b582c01cbd7e5ede14b6" \ No newline at end of file diff --git a/main.go b/main.go index 4c2a563..9953646 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "context" "encoding/hex" + "fmt" "io/ioutil" "github.com/lightningnetwork/lnd/lnrpc" @@ -45,6 +46,11 @@ func getClientConnection(ctx context.Context) (*grpc.ClientConn, error) { return conn, nil } + +func trimPubKey(pubkey []byte) string { + return fmt.Sprintf("%s...%s", hex.EncodeToString(pubkey)[:6], hex.EncodeToString(pubkey)[len(hex.EncodeToString(pubkey))-6:]) +} + func main() { conn, err := getClientConnection(context.Background()) if err != nil { @@ -55,7 +61,7 @@ func main() { if err != nil { panic(err) } - log.Infof("Listening for incoming channel requests...") + log.Infof("Listening for incoming channel requests") for { req := lnrpc.ChannelAcceptRequest{} err = acceptClient.RecvMsg(&req) @@ -74,7 +80,7 @@ func main() { res := lnrpc.ChannelAcceptResponse{} if accept { - log.Infof("Accepting channel request from %s", hex.EncodeToString(req.NodePubkey)) + log.Infof("✅ Accepting channel request from %s", trimPubKey(req.NodePubkey)) res = lnrpc.ChannelAcceptResponse{Accept: true, PendingChanId: req.PendingChanId, CsvDelay: req.CsvDelay, @@ -85,8 +91,9 @@ func main() { } } else { - log.Infof("Rejecting channel request from %s", hex.EncodeToString(req.NodePubkey)) - res = lnrpc.ChannelAcceptResponse{Accept: false} + log.Infof("❌ Rejecting channel request from %s", trimPubKey(req.NodePubkey)) + res = lnrpc.ChannelAcceptResponse{Accept: false, + Error: Configuration.RejectMessage} } err = acceptClient.Send(&res) if err != nil {