mirror of
https://github.com/callebtc/electronwall.git
synced 2025-12-18 15:44:20 +01:00
add blacklist
This commit is contained in:
10
config.go
10
config.go
@@ -8,10 +8,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var Configuration = struct {
|
var Configuration = struct {
|
||||||
|
Mode string `yaml:"mode"`
|
||||||
Host string `yaml:"host"`
|
Host string `yaml:"host"`
|
||||||
MacaroonPath string `yaml:"macaroon_path"`
|
MacaroonPath string `yaml:"macaroon_path"`
|
||||||
TLSPath string `yaml:"tls_path"`
|
TLSPath string `yaml:"tls_path"`
|
||||||
Accept []string `yaml:"accept"`
|
Whitelist []string `yaml:"whitelist"`
|
||||||
|
Blacklist []string `yaml:"blacklist"`
|
||||||
RejectMessage string `yaml:"reject_message"`
|
RejectMessage string `yaml:"reject_message"`
|
||||||
}{}
|
}{}
|
||||||
|
|
||||||
@@ -28,7 +30,7 @@ func checkConfig() {
|
|||||||
panic(fmt.Errorf("no host specified in config.yaml"))
|
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"))
|
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.")
|
log.Warnf("reject message is too long. Trimming to 500 characters.")
|
||||||
Configuration.RejectMessage = Configuration.RejectMessage[:500]
|
Configuration.RejectMessage = Configuration.RejectMessage[:500]
|
||||||
}
|
}
|
||||||
|
if len(Configuration.Mode) == 0 {
|
||||||
|
Configuration.Mode = "blacklist"
|
||||||
|
}
|
||||||
|
log.Infof("Running in %s mode", Configuration.Mode)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
|
mode: "blacklist"
|
||||||
|
|
||||||
host: "127.0.0.1:10009"
|
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"
|
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"
|
- "03de70865239e99460041e127647b37101b9eb335b3c22de95c944671f0dabc2d0"
|
||||||
- "0307299a290529c5ccb3a5e3bd2eb504daf64cc65c6d65b582c01cbd7e5ede14b6"
|
- "0307299a290529c5ccb3a5e3bd2eb504daf64cc65c6d65b582c01cbd7e5ede14b6"
|
||||||
|
blacklist:
|
||||||
|
- "02853f9c1d15d479b433039885373b681683b84bb73e86dff861bee6697c17c1de"
|
||||||
26
main.go
26
main.go
@@ -70,17 +70,29 @@ func main() {
|
|||||||
}
|
}
|
||||||
log.Infof("New channel request from %s", hex.EncodeToString(req.NodePubkey))
|
log.Infof("New channel request from %s", hex.EncodeToString(req.NodePubkey))
|
||||||
|
|
||||||
accept := false
|
var accept bool
|
||||||
for _, pubkey := range Configuration.Accept {
|
|
||||||
if hex.EncodeToString(req.NodePubkey) == pubkey {
|
if Configuration.Mode == "whitelist" {
|
||||||
accept = true
|
accept = false
|
||||||
break
|
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{}
|
res := lnrpc.ChannelAcceptResponse{}
|
||||||
if accept {
|
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,
|
res = lnrpc.ChannelAcceptResponse{Accept: true,
|
||||||
PendingChanId: req.PendingChanId,
|
PendingChanId: req.PendingChanId,
|
||||||
CsvDelay: req.CsvDelay,
|
CsvDelay: req.CsvDelay,
|
||||||
@@ -91,7 +103,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} 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,
|
res = lnrpc.ChannelAcceptResponse{Accept: false,
|
||||||
Error: Configuration.RejectMessage}
|
Error: Configuration.RejectMessage}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user