mirror of https://github.com/voidlizard/hbs2
Add `known-peer` config option
This commit is contained in:
parent
d2c08dd1b5
commit
4e487b3a03
|
@ -84,6 +84,7 @@ data PeerBlackListKey
|
||||||
data PeerStorageKey
|
data PeerStorageKey
|
||||||
data PeerAcceptAnnounceKey
|
data PeerAcceptAnnounceKey
|
||||||
data PeerTraceKey
|
data PeerTraceKey
|
||||||
|
data PeerKnownPeer
|
||||||
|
|
||||||
data AcceptAnnounce = AcceptAnnounceAll
|
data AcceptAnnounce = AcceptAnnounceAll
|
||||||
| AcceptAnnounceFrom (Set (PubKey 'Sign UDP))
|
| AcceptAnnounceFrom (Set (PubKey 'Sign UDP))
|
||||||
|
@ -116,6 +117,9 @@ instance HasCfgKey PeerBlackListKey (Set String) where
|
||||||
instance HasCfgKey PeerAcceptAnnounceKey AcceptAnnounce where
|
instance HasCfgKey PeerAcceptAnnounceKey AcceptAnnounce where
|
||||||
key = "accept-block-announce"
|
key = "accept-block-announce"
|
||||||
|
|
||||||
|
instance HasCfgKey PeerKnownPeer [String] where
|
||||||
|
key = "known-peer"
|
||||||
|
|
||||||
instance HasCfgValue PeerAcceptAnnounceKey AcceptAnnounce where
|
instance HasCfgValue PeerAcceptAnnounceKey AcceptAnnounce where
|
||||||
cfgValue (PeerConfig syn) = fromMaybe (AcceptAnnounceFrom lst) fromAll
|
cfgValue (PeerConfig syn) = fromMaybe (AcceptAnnounceFrom lst) fromAll
|
||||||
where
|
where
|
||||||
|
@ -388,6 +392,12 @@ runPeer opts = Exception.handle myException $ do
|
||||||
|
|
||||||
let accptAnn = cfgValue @PeerAcceptAnnounceKey conf :: AcceptAnnounce
|
let accptAnn = cfgValue @PeerAcceptAnnounceKey conf :: AcceptAnnounce
|
||||||
|
|
||||||
|
-- FIXME: add validation and error handling
|
||||||
|
let parseKnownPeers xs = fmap (PeerUDP . addrAddress) . catMaybes
|
||||||
|
<$> (fmap headMay . parseAddr . fromString) `mapM` xs
|
||||||
|
|
||||||
|
knownPeers' <- parseKnownPeers $ cfgValue @PeerKnownPeer conf
|
||||||
|
|
||||||
print $ pretty accptAnn
|
print $ pretty accptAnn
|
||||||
|
|
||||||
-- FIXME: move-peerBanned-somewhere
|
-- FIXME: move-peerBanned-somewhere
|
||||||
|
@ -636,6 +646,10 @@ runPeer opts = Exception.handle myException $ do
|
||||||
, makeResponse peerExchangeProto
|
, makeResponse peerExchangeProto
|
||||||
]
|
]
|
||||||
|
|
||||||
|
wo $ liftIO $ async $ withPeerM env $ forever do
|
||||||
|
forM_ knownPeers' (sendPing @e)
|
||||||
|
pause @'Minutes 20
|
||||||
|
|
||||||
void $ liftIO $ waitAnyCatchCancel workers
|
void $ liftIO $ waitAnyCatchCancel workers
|
||||||
|
|
||||||
let pokeAction _ = do
|
let pokeAction _ = do
|
||||||
|
|
Loading…
Reference in New Issue