From 563377c855556f9e199208145e1561f47a9b5ba6 Mon Sep 17 00:00:00 2001 From: Sergey Ivanov Date: Tue, 18 Jul 2023 19:37:02 +0400 Subject: [PATCH] emit PeerExpiredEventKey (PeerExpiredEvent @e p) --- hbs2-core/hbs2-core.cabal | 1 + .../lib/HBS2/Net/Proto/Event/PeerExpired.hs | 33 +++++++++++++++++++ hbs2-peer/app/PeerInfo.hs | 2 ++ 3 files changed, 36 insertions(+) create mode 100644 hbs2-core/lib/HBS2/Net/Proto/Event/PeerExpired.hs diff --git a/hbs2-core/hbs2-core.cabal b/hbs2-core/hbs2-core.cabal index 5d71be67..62036cb6 100644 --- a/hbs2-core/hbs2-core.cabal +++ b/hbs2-core/hbs2-core.cabal @@ -95,6 +95,7 @@ library , HBS2.Net.Proto.BlockInfo , HBS2.Net.Proto.Definition , HBS2.Net.Proto.EncryptionHandshake + , HBS2.Net.Proto.Event.PeerExpired , HBS2.Net.Proto.Peer , HBS2.Net.Proto.PeerAnnounce , HBS2.Net.Proto.PeerExchange diff --git a/hbs2-core/lib/HBS2/Net/Proto/Event/PeerExpired.hs b/hbs2-core/lib/HBS2/Net/Proto/Event/PeerExpired.hs new file mode 100644 index 00000000..55d7d641 --- /dev/null +++ b/hbs2-core/lib/HBS2/Net/Proto/Event/PeerExpired.hs @@ -0,0 +1,33 @@ +module HBS2.Net.Proto.Event.PeerExpired where + +import HBS2.Clock +import HBS2.Events +import HBS2.Net.Proto +import HBS2.Prelude.Plated + +data PeerExpires = PeerExpires + +data instance EventKey e PeerExpires = + PeerExpiredEventKey + deriving stock (Typeable, Eq, Generic) + +data instance Event e PeerExpires = + PeerExpiredEvent (Peer e) + deriving stock (Typeable) + +instance EventType (Event e PeerExpires) where + isPersistent = True + +instance Expires (EventKey e PeerExpires) where + expiresIn _ = Nothing + +instance Hashable (EventKey e PeerExpires) + +--instance ( Serialise (PubKey 'Sign (Encryption e)) +-- , Serialise (PubKey 'Encrypt (Encryption e)) +-- , Serialise (Signature (Encryption e)) +-- , Serialise PeerNonce +-- ) + +-- => Serialise PeerExpires + diff --git a/hbs2-peer/app/PeerInfo.hs b/hbs2-peer/app/PeerInfo.hs index cf2ed433..813bb5d0 100644 --- a/hbs2-peer/app/PeerInfo.hs +++ b/hbs2-peer/app/PeerInfo.hs @@ -7,6 +7,7 @@ import HBS2.Clock import HBS2.Events import HBS2.Net.Auth.Credentials import HBS2.Net.PeerLocator +import HBS2.Net.Proto.Event.PeerExpired import HBS2.Net.Proto.Peer import HBS2.Net.Proto.PeerExchange import HBS2.Net.Proto.Sessions @@ -221,6 +222,7 @@ peerPingLoop cfg penv = do delPeers pl [p] expire (PeerInfoKey p) expire (KnownPeerKey p) + emit PeerExpiredEventKey (PeerExpiredEvent @e p) liftIO $ mapM_ link [watch, infoLoop]