Add whitelist config option

This commit is contained in:
Vladimir Krutkin 2023-03-17 15:57:21 +03:00
parent dfdd7d9796
commit c710dab928
2 changed files with 16 additions and 4 deletions

View File

@ -391,3 +391,5 @@ fixme-del "FbcbtA4eCx"
(fixme-set "assigned" "voidlizard" "5RbVNm9SRz") (fixme-set "assigned" "voidlizard" "5RbVNm9SRz")
(fixme-set "workflow" "wip" "5RbVNm9SRz") (fixme-set "workflow" "wip" "5RbVNm9SRz")
(fixme-set "workflow" "test" "5RbVNm9SRz") (fixme-set "workflow" "test" "5RbVNm9SRz")
(fixme-set "assigned" "fastopk" "EpnYqZi7bW")
(fixme-set "workflow" "test" "EpnYqZi7bW")

View File

@ -91,6 +91,7 @@ data PeerListenKey
data PeerRpcKey data PeerRpcKey
data PeerKeyFileKey data PeerKeyFileKey
data PeerBlackListKey data PeerBlackListKey
data PeerWhiteListKey
data PeerStorageKey data PeerStorageKey
data PeerAcceptAnnounceKey data PeerAcceptAnnounceKey
data PeerTraceKey data PeerTraceKey
@ -123,6 +124,9 @@ instance HasCfgKey PeerStorageKey (Maybe String) where
instance HasCfgKey PeerBlackListKey (Set String) where instance HasCfgKey PeerBlackListKey (Set String) where
key = "blacklist" key = "blacklist"
instance HasCfgKey PeerWhiteListKey (Set String) where
key = "whitelist"
instance HasCfgKey PeerAcceptAnnounceKey AcceptAnnounce where instance HasCfgKey PeerAcceptAnnounceKey AcceptAnnounce where
key = "accept-block-announce" key = "accept-block-announce"
@ -431,10 +435,14 @@ runPeer opts = Exception.handle myException $ do
setLogging @TRACE tracePrefix setLogging @TRACE tracePrefix
let bls = cfgValue @PeerBlackListKey conf :: Set String let bls = cfgValue @PeerBlackListKey conf :: Set String
let whs = cfgValue @PeerWhiteListKey conf :: Set String
let blkeys = Set.fromList let toKeys xs = Set.fromList
$ catMaybes [ fromStringMay x | x <- Set.toList bls $ catMaybes [ fromStringMay x | x <- Set.toList xs
] :: Set (PubKey 'Sign UDP) ] :: Set (PubKey 'Sign UDP)
let blkeys = toKeys bls
let wlkeys = toKeys whs
unless (Set.disjoint blkeys wlkeys) do
die "whitelist and blacklist intersect"
let accptAnn = cfgValue @PeerAcceptAnnounceKey conf :: AcceptAnnounce let accptAnn = cfgValue @PeerAcceptAnnounceKey conf :: AcceptAnnounce
@ -443,7 +451,9 @@ runPeer opts = Exception.handle myException $ do
-- FIXME: move-peerBanned-somewhere -- FIXME: move-peerBanned-somewhere
let peerBanned p d = do let peerBanned p d = do
let k = view peerSignKey d let k = view peerSignKey d
pure $ k `Set.member` blkeys let blacklisted = k `Set.member` blkeys
let whitelisted = Set.null wlkeys || (k `Set.member` wlkeys)
pure $ blacklisted || not whitelisted
let acceptAnnounce p d = do let acceptAnnounce p d = do
case accptAnn of case accptAnn of