From 15e555604a3237a654462c468d4518927733e37b Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Sun, 29 May 2022 13:54:10 +0200 Subject: [PATCH] add blacklist --- config.go | 10 ++++++++-- config.yaml.example | 14 ++++++++++---- main.go | 26 +++++++++++++++++++------- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/config.go b/config.go index bde5762..213d618 100644 --- a/config.go +++ b/config.go @@ -8,10 +8,12 @@ import ( ) var Configuration = struct { + Mode string `yaml:"mode"` Host string `yaml:"host"` MacaroonPath string `yaml:"macaroon_path"` TLSPath string `yaml:"tls_path"` - Accept []string `yaml:"accept"` + Whitelist []string `yaml:"whitelist"` + Blacklist []string `yaml:"blacklist"` RejectMessage string `yaml:"reject_message"` }{} @@ -28,7 +30,7 @@ func checkConfig() { panic(fmt.Errorf("no host specified in config.yaml")) } - if len(Configuration.Accept) == 0 { + if len(Configuration.Whitelist) == 0 { panic(fmt.Errorf("no accepted pubkeys specified in config.yaml")) } @@ -36,4 +38,8 @@ func checkConfig() { log.Warnf("reject message is too long. Trimming to 500 characters.") Configuration.RejectMessage = Configuration.RejectMessage[:500] } + if len(Configuration.Mode) == 0 { + Configuration.Mode = "blacklist" + } + log.Infof("Running in %s mode", Configuration.Mode) } diff --git a/config.yaml.example b/config.yaml.example index 003370e..25f9abe 100644 --- a/config.yaml.example +++ b/config.yaml.example @@ -1,7 +1,13 @@ +mode: "blacklist" + host: "127.0.0.1:10009" -macaroon_path: "/home/bitcoin/.lnd/data/chain/bitcoin/regtest/admin.macaroon" +macaroon_path: "/home/bitcoin/.lnd/data/chain/bitcoin/mainnet/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: + +reject_message: "Contact me at user@email.com" + +whitelist: - "03de70865239e99460041e127647b37101b9eb335b3c22de95c944671f0dabc2d0" - - "0307299a290529c5ccb3a5e3bd2eb504daf64cc65c6d65b582c01cbd7e5ede14b6" \ No newline at end of file + - "0307299a290529c5ccb3a5e3bd2eb504daf64cc65c6d65b582c01cbd7e5ede14b6" +blacklist: + - "02853f9c1d15d479b433039885373b681683b84bb73e86dff861bee6697c17c1de" \ No newline at end of file diff --git a/main.go b/main.go index 9953646..9fc528e 100644 --- a/main.go +++ b/main.go @@ -70,17 +70,29 @@ func main() { } log.Infof("New channel request from %s", hex.EncodeToString(req.NodePubkey)) - accept := false - for _, pubkey := range Configuration.Accept { - if hex.EncodeToString(req.NodePubkey) == pubkey { - accept = true - break + var accept bool + + if Configuration.Mode == "whitelist" { + accept = false + for _, pubkey := range Configuration.Whitelist { + if hex.EncodeToString(req.NodePubkey) == pubkey { + accept = true + break + } + } + } else if Configuration.Mode == "blacklist" { + accept = true + for _, pubkey := range Configuration.Blacklist { + if hex.EncodeToString(req.NodePubkey) == pubkey { + accept = false + break + } } } res := lnrpc.ChannelAcceptResponse{} if accept { - log.Infof("✅ Accepting channel request from %s", trimPubKey(req.NodePubkey)) + log.Infof("✅ [%s mode] Allow channel from %s", Configuration.Mode, trimPubKey(req.NodePubkey)) res = lnrpc.ChannelAcceptResponse{Accept: true, PendingChanId: req.PendingChanId, CsvDelay: req.CsvDelay, @@ -91,7 +103,7 @@ func main() { } } else { - log.Infof("❌ Rejecting channel request from %s", trimPubKey(req.NodePubkey)) + log.Infof("❌ [%s mode] Deny channel from %s", Configuration.Mode, trimPubKey(req.NodePubkey)) res = lnrpc.ChannelAcceptResponse{Accept: false, Error: Configuration.RejectMessage} }