module Network.LibP2P.Protocol.GossipSub.Types
(
gossipSubProtocolId
, maxRPCSize
, Topic
, MessageId
, PubSubMessage (..)
, SubOpts (..)
, ControlMessage (..)
, IHave (..)
, IWant (..)
, Graft (..)
, Prune (..)
, PeerExchangeInfo (..)
, RPC (..)
, SignaturePolicy (..)
, GossipSubParams (..)
, defaultGossipSubParams
, PeerProtocol (..)
, PeerState (..)
, TopicScoreParams (..)
, defaultTopicScoreParams
, PeerScoreParams (..)
, defaultPeerScoreParams
, TopicPeerState (..)
, defaultTopicPeerState
, ScoreThresholds (..)
, defaultScoreThresholds
, CacheEntry (..)
, MessageCache (..)
, GossipSubRouter (..)
, emptyRPC
, emptyControlMessage
, defaultMessageId
) where
import Control.Concurrent.STM (TVar)
import Data.ByteString (ByteString)
import qualified Data.ByteString as BS
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Sequence (Seq)
import Data.Set (Set)
import Data.Text (Text)
import Data.Time (NominalDiffTime, UTCTime)
import Data.Word (Word64)
import Network.LibP2P.Crypto.PeerId (PeerId)
gossipSubProtocolId :: Text
gossipSubProtocolId :: Text
gossipSubProtocolId = Text
"/meshsub/1.1.0"
maxRPCSize :: Int
maxRPCSize :: Int
maxRPCSize = Int
1048576
type Topic = Text
type MessageId = ByteString
data PubSubMessage = PubSubMessage
{ PubSubMessage -> Maybe MessageId
msgFrom :: !(Maybe ByteString)
, PubSubMessage -> MessageId
msgData :: !ByteString
, PubSubMessage -> Maybe MessageId
msgSeqNo :: !(Maybe ByteString)
, PubSubMessage -> Text
msgTopic :: !Topic
, PubSubMessage -> Maybe MessageId
msgSignature :: !(Maybe ByteString)
, PubSubMessage -> Maybe MessageId
msgKey :: !(Maybe ByteString)
} deriving (Int -> PubSubMessage -> ShowS
[PubSubMessage] -> ShowS
PubSubMessage -> String
(Int -> PubSubMessage -> ShowS)
-> (PubSubMessage -> String)
-> ([PubSubMessage] -> ShowS)
-> Show PubSubMessage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PubSubMessage -> ShowS
showsPrec :: Int -> PubSubMessage -> ShowS
$cshow :: PubSubMessage -> String
show :: PubSubMessage -> String
$cshowList :: [PubSubMessage] -> ShowS
showList :: [PubSubMessage] -> ShowS
Show, PubSubMessage -> PubSubMessage -> Bool
(PubSubMessage -> PubSubMessage -> Bool)
-> (PubSubMessage -> PubSubMessage -> Bool) -> Eq PubSubMessage
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PubSubMessage -> PubSubMessage -> Bool
== :: PubSubMessage -> PubSubMessage -> Bool
$c/= :: PubSubMessage -> PubSubMessage -> Bool
/= :: PubSubMessage -> PubSubMessage -> Bool
Eq)
data SubOpts = SubOpts
{ SubOpts -> Bool
subSubscribe :: !Bool
, SubOpts -> Text
subTopicId :: !Topic
} deriving (Int -> SubOpts -> ShowS
[SubOpts] -> ShowS
SubOpts -> String
(Int -> SubOpts -> ShowS)
-> (SubOpts -> String) -> ([SubOpts] -> ShowS) -> Show SubOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SubOpts -> ShowS
showsPrec :: Int -> SubOpts -> ShowS
$cshow :: SubOpts -> String
show :: SubOpts -> String
$cshowList :: [SubOpts] -> ShowS
showList :: [SubOpts] -> ShowS
Show, SubOpts -> SubOpts -> Bool
(SubOpts -> SubOpts -> Bool)
-> (SubOpts -> SubOpts -> Bool) -> Eq SubOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SubOpts -> SubOpts -> Bool
== :: SubOpts -> SubOpts -> Bool
$c/= :: SubOpts -> SubOpts -> Bool
/= :: SubOpts -> SubOpts -> Bool
Eq)
data IHave = IHave
{ IHave -> Text
ihaveTopic :: !Topic
, IHave -> [MessageId]
ihaveMessageIds :: ![MessageId]
} deriving (Int -> IHave -> ShowS
[IHave] -> ShowS
IHave -> String
(Int -> IHave -> ShowS)
-> (IHave -> String) -> ([IHave] -> ShowS) -> Show IHave
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> IHave -> ShowS
showsPrec :: Int -> IHave -> ShowS
$cshow :: IHave -> String
show :: IHave -> String
$cshowList :: [IHave] -> ShowS
showList :: [IHave] -> ShowS
Show, IHave -> IHave -> Bool
(IHave -> IHave -> Bool) -> (IHave -> IHave -> Bool) -> Eq IHave
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: IHave -> IHave -> Bool
== :: IHave -> IHave -> Bool
$c/= :: IHave -> IHave -> Bool
/= :: IHave -> IHave -> Bool
Eq)
data IWant = IWant
{ IWant -> [MessageId]
iwantMessageIds :: ![MessageId]
} deriving (Int -> IWant -> ShowS
[IWant] -> ShowS
IWant -> String
(Int -> IWant -> ShowS)
-> (IWant -> String) -> ([IWant] -> ShowS) -> Show IWant
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> IWant -> ShowS
showsPrec :: Int -> IWant -> ShowS
$cshow :: IWant -> String
show :: IWant -> String
$cshowList :: [IWant] -> ShowS
showList :: [IWant] -> ShowS
Show, IWant -> IWant -> Bool
(IWant -> IWant -> Bool) -> (IWant -> IWant -> Bool) -> Eq IWant
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: IWant -> IWant -> Bool
== :: IWant -> IWant -> Bool
$c/= :: IWant -> IWant -> Bool
/= :: IWant -> IWant -> Bool
Eq)
data Graft = Graft
{ Graft -> Text
graftTopic :: !Topic
} deriving (Int -> Graft -> ShowS
[Graft] -> ShowS
Graft -> String
(Int -> Graft -> ShowS)
-> (Graft -> String) -> ([Graft] -> ShowS) -> Show Graft
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Graft -> ShowS
showsPrec :: Int -> Graft -> ShowS
$cshow :: Graft -> String
show :: Graft -> String
$cshowList :: [Graft] -> ShowS
showList :: [Graft] -> ShowS
Show, Graft -> Graft -> Bool
(Graft -> Graft -> Bool) -> (Graft -> Graft -> Bool) -> Eq Graft
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Graft -> Graft -> Bool
== :: Graft -> Graft -> Bool
$c/= :: Graft -> Graft -> Bool
/= :: Graft -> Graft -> Bool
Eq)
data Prune = Prune
{ Prune -> Text
pruneTopic :: !Topic
, Prune -> [PeerExchangeInfo]
prunePeers :: ![PeerExchangeInfo]
, Prune -> Maybe Word64
pruneBackoff :: !(Maybe Word64)
} deriving (Int -> Prune -> ShowS
[Prune] -> ShowS
Prune -> String
(Int -> Prune -> ShowS)
-> (Prune -> String) -> ([Prune] -> ShowS) -> Show Prune
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Prune -> ShowS
showsPrec :: Int -> Prune -> ShowS
$cshow :: Prune -> String
show :: Prune -> String
$cshowList :: [Prune] -> ShowS
showList :: [Prune] -> ShowS
Show, Prune -> Prune -> Bool
(Prune -> Prune -> Bool) -> (Prune -> Prune -> Bool) -> Eq Prune
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Prune -> Prune -> Bool
== :: Prune -> Prune -> Bool
$c/= :: Prune -> Prune -> Bool
/= :: Prune -> Prune -> Bool
Eq)
data PeerExchangeInfo = PeerExchangeInfo
{ PeerExchangeInfo -> MessageId
pxPeerId :: !ByteString
, PeerExchangeInfo -> Maybe MessageId
pxSignedPeerRecord :: !(Maybe ByteString)
} deriving (Int -> PeerExchangeInfo -> ShowS
[PeerExchangeInfo] -> ShowS
PeerExchangeInfo -> String
(Int -> PeerExchangeInfo -> ShowS)
-> (PeerExchangeInfo -> String)
-> ([PeerExchangeInfo] -> ShowS)
-> Show PeerExchangeInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PeerExchangeInfo -> ShowS
showsPrec :: Int -> PeerExchangeInfo -> ShowS
$cshow :: PeerExchangeInfo -> String
show :: PeerExchangeInfo -> String
$cshowList :: [PeerExchangeInfo] -> ShowS
showList :: [PeerExchangeInfo] -> ShowS
Show, PeerExchangeInfo -> PeerExchangeInfo -> Bool
(PeerExchangeInfo -> PeerExchangeInfo -> Bool)
-> (PeerExchangeInfo -> PeerExchangeInfo -> Bool)
-> Eq PeerExchangeInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PeerExchangeInfo -> PeerExchangeInfo -> Bool
== :: PeerExchangeInfo -> PeerExchangeInfo -> Bool
$c/= :: PeerExchangeInfo -> PeerExchangeInfo -> Bool
/= :: PeerExchangeInfo -> PeerExchangeInfo -> Bool
Eq)
data ControlMessage = ControlMessage
{ ControlMessage -> [IHave]
ctrlIHave :: ![IHave]
, ControlMessage -> [IWant]
ctrlIWant :: ![IWant]
, ControlMessage -> [Graft]
ctrlGraft :: ![Graft]
, ControlMessage -> [Prune]
ctrlPrune :: ![Prune]
} deriving (Int -> ControlMessage -> ShowS
[ControlMessage] -> ShowS
ControlMessage -> String
(Int -> ControlMessage -> ShowS)
-> (ControlMessage -> String)
-> ([ControlMessage] -> ShowS)
-> Show ControlMessage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ControlMessage -> ShowS
showsPrec :: Int -> ControlMessage -> ShowS
$cshow :: ControlMessage -> String
show :: ControlMessage -> String
$cshowList :: [ControlMessage] -> ShowS
showList :: [ControlMessage] -> ShowS
Show, ControlMessage -> ControlMessage -> Bool
(ControlMessage -> ControlMessage -> Bool)
-> (ControlMessage -> ControlMessage -> Bool) -> Eq ControlMessage
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ControlMessage -> ControlMessage -> Bool
== :: ControlMessage -> ControlMessage -> Bool
$c/= :: ControlMessage -> ControlMessage -> Bool
/= :: ControlMessage -> ControlMessage -> Bool
Eq)
data RPC = RPC
{ RPC -> [SubOpts]
rpcSubscriptions :: ![SubOpts]
, RPC -> [PubSubMessage]
rpcPublish :: ![PubSubMessage]
, RPC -> Maybe ControlMessage
rpcControl :: !(Maybe ControlMessage)
} deriving (Int -> RPC -> ShowS
[RPC] -> ShowS
RPC -> String
(Int -> RPC -> ShowS)
-> (RPC -> String) -> ([RPC] -> ShowS) -> Show RPC
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RPC -> ShowS
showsPrec :: Int -> RPC -> ShowS
$cshow :: RPC -> String
show :: RPC -> String
$cshowList :: [RPC] -> ShowS
showList :: [RPC] -> ShowS
Show, RPC -> RPC -> Bool
(RPC -> RPC -> Bool) -> (RPC -> RPC -> Bool) -> Eq RPC
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RPC -> RPC -> Bool
== :: RPC -> RPC -> Bool
$c/= :: RPC -> RPC -> Bool
/= :: RPC -> RPC -> Bool
Eq)
data SignaturePolicy
= StrictSign
| StrictNoSign
deriving (Int -> SignaturePolicy -> ShowS
[SignaturePolicy] -> ShowS
SignaturePolicy -> String
(Int -> SignaturePolicy -> ShowS)
-> (SignaturePolicy -> String)
-> ([SignaturePolicy] -> ShowS)
-> Show SignaturePolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SignaturePolicy -> ShowS
showsPrec :: Int -> SignaturePolicy -> ShowS
$cshow :: SignaturePolicy -> String
show :: SignaturePolicy -> String
$cshowList :: [SignaturePolicy] -> ShowS
showList :: [SignaturePolicy] -> ShowS
Show, SignaturePolicy -> SignaturePolicy -> Bool
(SignaturePolicy -> SignaturePolicy -> Bool)
-> (SignaturePolicy -> SignaturePolicy -> Bool)
-> Eq SignaturePolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SignaturePolicy -> SignaturePolicy -> Bool
== :: SignaturePolicy -> SignaturePolicy -> Bool
$c/= :: SignaturePolicy -> SignaturePolicy -> Bool
/= :: SignaturePolicy -> SignaturePolicy -> Bool
Eq)
data GossipSubParams = GossipSubParams
{ GossipSubParams -> Int
paramD :: !Int
, GossipSubParams -> Int
paramDlo :: !Int
, GossipSubParams -> Int
paramDhi :: !Int
, GossipSubParams -> Int
paramDlazy :: !Int
, GossipSubParams -> Int
paramDscore :: !Int
, GossipSubParams -> Int
paramDout :: !Int
, GossipSubParams -> NominalDiffTime
paramHeartbeatInterval :: !NominalDiffTime
, GossipSubParams -> NominalDiffTime
paramFanoutTTL :: !NominalDiffTime
, GossipSubParams -> NominalDiffTime
paramSeenTTL :: !NominalDiffTime
, GossipSubParams -> NominalDiffTime
paramPruneBackoff :: !NominalDiffTime
, GossipSubParams -> NominalDiffTime
paramUnsubBackoff :: !NominalDiffTime
, GossipSubParams -> Double
paramGossipFactor :: !Double
, GossipSubParams -> Bool
paramFloodPublish :: !Bool
, GossipSubParams -> PubSubMessage -> MessageId
paramMessageIdFn :: !(PubSubMessage -> MessageId)
, GossipSubParams -> SignaturePolicy
paramSignaturePolicy :: !SignaturePolicy
, GossipSubParams -> Int
paramMcacheLen :: !Int
, GossipSubParams -> Int
paramMcacheGossip :: !Int
}
defaultMessageId :: PubSubMessage -> MessageId
defaultMessageId :: PubSubMessage -> MessageId
defaultMessageId PubSubMessage
msg =
let from :: MessageId
from = MessageId
-> (MessageId -> MessageId) -> Maybe MessageId -> MessageId
forall b a. b -> (a -> b) -> Maybe a -> b
maybe MessageId
BS.empty MessageId -> MessageId
forall a. a -> a
id (PubSubMessage -> Maybe MessageId
msgFrom PubSubMessage
msg)
seqno :: MessageId
seqno = MessageId
-> (MessageId -> MessageId) -> Maybe MessageId -> MessageId
forall b a. b -> (a -> b) -> Maybe a -> b
maybe MessageId
BS.empty MessageId -> MessageId
forall a. a -> a
id (PubSubMessage -> Maybe MessageId
msgSeqNo PubSubMessage
msg)
in MessageId
from MessageId -> MessageId -> MessageId
forall a. Semigroup a => a -> a -> a
<> MessageId
seqno
defaultGossipSubParams :: GossipSubParams
defaultGossipSubParams :: GossipSubParams
defaultGossipSubParams = GossipSubParams
{ paramD :: Int
paramD = Int
6
, paramDlo :: Int
paramDlo = Int
4
, paramDhi :: Int
paramDhi = Int
12
, paramDlazy :: Int
paramDlazy = Int
6
, paramDscore :: Int
paramDscore = Int
4
, paramDout :: Int
paramDout = Int
2
, paramHeartbeatInterval :: NominalDiffTime
paramHeartbeatInterval = NominalDiffTime
1
, paramFanoutTTL :: NominalDiffTime
paramFanoutTTL = NominalDiffTime
60
, paramSeenTTL :: NominalDiffTime
paramSeenTTL = NominalDiffTime
120
, paramPruneBackoff :: NominalDiffTime
paramPruneBackoff = NominalDiffTime
60
, paramUnsubBackoff :: NominalDiffTime
paramUnsubBackoff = NominalDiffTime
10
, paramGossipFactor :: Double
paramGossipFactor = Double
0.25
, paramFloodPublish :: Bool
paramFloodPublish = Bool
True
, paramMessageIdFn :: PubSubMessage -> MessageId
paramMessageIdFn = PubSubMessage -> MessageId
defaultMessageId
, paramSignaturePolicy :: SignaturePolicy
paramSignaturePolicy = SignaturePolicy
StrictSign
, paramMcacheLen :: Int
paramMcacheLen = Int
5
, paramMcacheGossip :: Int
paramMcacheGossip = Int
3
}
data PeerProtocol
= GossipSubPeer
| FloodSubPeer
deriving (Int -> PeerProtocol -> ShowS
[PeerProtocol] -> ShowS
PeerProtocol -> String
(Int -> PeerProtocol -> ShowS)
-> (PeerProtocol -> String)
-> ([PeerProtocol] -> ShowS)
-> Show PeerProtocol
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PeerProtocol -> ShowS
showsPrec :: Int -> PeerProtocol -> ShowS
$cshow :: PeerProtocol -> String
show :: PeerProtocol -> String
$cshowList :: [PeerProtocol] -> ShowS
showList :: [PeerProtocol] -> ShowS
Show, PeerProtocol -> PeerProtocol -> Bool
(PeerProtocol -> PeerProtocol -> Bool)
-> (PeerProtocol -> PeerProtocol -> Bool) -> Eq PeerProtocol
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PeerProtocol -> PeerProtocol -> Bool
== :: PeerProtocol -> PeerProtocol -> Bool
$c/= :: PeerProtocol -> PeerProtocol -> Bool
/= :: PeerProtocol -> PeerProtocol -> Bool
Eq)
data PeerState = PeerState
{ PeerState -> PeerProtocol
psProtocol :: !PeerProtocol
, PeerState -> Set Text
psTopics :: !(Set Topic)
, PeerState -> Bool
psIsOutbound :: !Bool
, PeerState -> UTCTime
psConnectedAt :: !UTCTime
, PeerState -> Map Text TopicPeerState
psTopicState :: !(Map Topic TopicPeerState)
, PeerState -> Double
psBehaviorPenalty :: !Double
, PeerState -> Maybe MessageId
psIPAddress :: !(Maybe ByteString)
, PeerState -> Double
psCachedScore :: !Double
} deriving (Int -> PeerState -> ShowS
[PeerState] -> ShowS
PeerState -> String
(Int -> PeerState -> ShowS)
-> (PeerState -> String)
-> ([PeerState] -> ShowS)
-> Show PeerState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PeerState -> ShowS
showsPrec :: Int -> PeerState -> ShowS
$cshow :: PeerState -> String
show :: PeerState -> String
$cshowList :: [PeerState] -> ShowS
showList :: [PeerState] -> ShowS
Show, PeerState -> PeerState -> Bool
(PeerState -> PeerState -> Bool)
-> (PeerState -> PeerState -> Bool) -> Eq PeerState
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PeerState -> PeerState -> Bool
== :: PeerState -> PeerState -> Bool
$c/= :: PeerState -> PeerState -> Bool
/= :: PeerState -> PeerState -> Bool
Eq)
data TopicScoreParams = TopicScoreParams
{ TopicScoreParams -> Double
tspTopicWeight :: !Double
, TopicScoreParams -> Double
tspTimeInMeshWeight :: !Double
, TopicScoreParams -> NominalDiffTime
tspTimeInMeshQuantum :: !NominalDiffTime
, TopicScoreParams -> Double
tspTimeInMeshCap :: !Double
, TopicScoreParams -> Double
tspFirstMessageDeliveriesWeight :: !Double
, TopicScoreParams -> Double
tspFirstMessageDeliveriesDecay :: !Double
, TopicScoreParams -> Double
tspFirstMessageDeliveriesCap :: !Double
, TopicScoreParams -> Double
tspMeshMessageDeliveriesWeight :: !Double
, TopicScoreParams -> Double
tspMeshMessageDeliveriesDecay :: !Double
, TopicScoreParams -> Double
tspMeshMessageDeliveriesThreshold :: !Double
, TopicScoreParams -> Double
tspMeshMessageDeliveriesCap :: !Double
, TopicScoreParams -> NominalDiffTime
tspMeshMessageDeliveriesActivation :: !NominalDiffTime
, TopicScoreParams -> NominalDiffTime
tspMeshMessageDeliveryWindow :: !NominalDiffTime
, TopicScoreParams -> Double
tspMeshFailurePenaltyWeight :: !Double
, TopicScoreParams -> Double
tspMeshFailurePenaltyDecay :: !Double
, TopicScoreParams -> Double
tspInvalidMessageDeliveriesWeight :: !Double
, TopicScoreParams -> Double
tspInvalidMessageDeliveriesDecay :: !Double
} deriving (Int -> TopicScoreParams -> ShowS
[TopicScoreParams] -> ShowS
TopicScoreParams -> String
(Int -> TopicScoreParams -> ShowS)
-> (TopicScoreParams -> String)
-> ([TopicScoreParams] -> ShowS)
-> Show TopicScoreParams
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TopicScoreParams -> ShowS
showsPrec :: Int -> TopicScoreParams -> ShowS
$cshow :: TopicScoreParams -> String
show :: TopicScoreParams -> String
$cshowList :: [TopicScoreParams] -> ShowS
showList :: [TopicScoreParams] -> ShowS
Show, TopicScoreParams -> TopicScoreParams -> Bool
(TopicScoreParams -> TopicScoreParams -> Bool)
-> (TopicScoreParams -> TopicScoreParams -> Bool)
-> Eq TopicScoreParams
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TopicScoreParams -> TopicScoreParams -> Bool
== :: TopicScoreParams -> TopicScoreParams -> Bool
$c/= :: TopicScoreParams -> TopicScoreParams -> Bool
/= :: TopicScoreParams -> TopicScoreParams -> Bool
Eq)
defaultTopicScoreParams :: TopicScoreParams
defaultTopicScoreParams :: TopicScoreParams
defaultTopicScoreParams = TopicScoreParams
{ tspTopicWeight :: Double
tspTopicWeight = Double
1.0
, tspTimeInMeshWeight :: Double
tspTimeInMeshWeight = Double
0.01
, tspTimeInMeshQuantum :: NominalDiffTime
tspTimeInMeshQuantum = NominalDiffTime
1
, tspTimeInMeshCap :: Double
tspTimeInMeshCap = Double
100
, tspFirstMessageDeliveriesWeight :: Double
tspFirstMessageDeliveriesWeight = Double
1.0
, tspFirstMessageDeliveriesDecay :: Double
tspFirstMessageDeliveriesDecay = Double
0.5
, tspFirstMessageDeliveriesCap :: Double
tspFirstMessageDeliveriesCap = Double
100
, tspMeshMessageDeliveriesWeight :: Double
tspMeshMessageDeliveriesWeight = -Double
1.0
, tspMeshMessageDeliveriesDecay :: Double
tspMeshMessageDeliveriesDecay = Double
0.5
, tspMeshMessageDeliveriesThreshold :: Double
tspMeshMessageDeliveriesThreshold = Double
1.0
, tspMeshMessageDeliveriesCap :: Double
tspMeshMessageDeliveriesCap = Double
100
, tspMeshMessageDeliveriesActivation :: NominalDiffTime
tspMeshMessageDeliveriesActivation = NominalDiffTime
5
, tspMeshMessageDeliveryWindow :: NominalDiffTime
tspMeshMessageDeliveryWindow = NominalDiffTime
0.01
, tspMeshFailurePenaltyWeight :: Double
tspMeshFailurePenaltyWeight = -Double
1.0
, tspMeshFailurePenaltyDecay :: Double
tspMeshFailurePenaltyDecay = Double
0.5
, tspInvalidMessageDeliveriesWeight :: Double
tspInvalidMessageDeliveriesWeight = -Double
100.0
, tspInvalidMessageDeliveriesDecay :: Double
tspInvalidMessageDeliveriesDecay = Double
0.5
}
data PeerScoreParams = PeerScoreParams
{ PeerScoreParams -> Map Text TopicScoreParams
pspTopicParams :: !(Map Topic TopicScoreParams)
, PeerScoreParams -> Double
pspAppSpecificWeight :: !Double
, PeerScoreParams -> PeerId -> Double
pspAppSpecificScore :: !(PeerId -> Double)
, PeerScoreParams -> Double
pspIPColocationFactorWeight :: !Double
, PeerScoreParams -> Int
pspIPColocationFactorThreshold :: !Int
, PeerScoreParams -> Double
pspBehaviorPenaltyWeight :: !Double
, PeerScoreParams -> Double
pspBehaviorPenaltyDecay :: !Double
, PeerScoreParams -> NominalDiffTime
pspDecayInterval :: !NominalDiffTime
, PeerScoreParams -> Double
pspDecayToZero :: !Double
, PeerScoreParams -> NominalDiffTime
pspRetainScore :: !NominalDiffTime
, PeerScoreParams -> Double
pspTopicScoreCap :: !Double
}
defaultPeerScoreParams :: PeerScoreParams
defaultPeerScoreParams :: PeerScoreParams
defaultPeerScoreParams = PeerScoreParams
{ pspTopicParams :: Map Text TopicScoreParams
pspTopicParams = Map Text TopicScoreParams
forall k a. Map k a
Map.empty
, pspAppSpecificWeight :: Double
pspAppSpecificWeight = Double
1.0
, pspAppSpecificScore :: PeerId -> Double
pspAppSpecificScore = Double -> PeerId -> Double
forall a b. a -> b -> a
const Double
0
, pspIPColocationFactorWeight :: Double
pspIPColocationFactorWeight = -Double
10.0
, pspIPColocationFactorThreshold :: Int
pspIPColocationFactorThreshold = Int
3
, pspBehaviorPenaltyWeight :: Double
pspBehaviorPenaltyWeight = -Double
1.0
, pspBehaviorPenaltyDecay :: Double
pspBehaviorPenaltyDecay = Double
0.99
, pspDecayInterval :: NominalDiffTime
pspDecayInterval = NominalDiffTime
1
, pspDecayToZero :: Double
pspDecayToZero = Double
0.01
, pspRetainScore :: NominalDiffTime
pspRetainScore = NominalDiffTime
3600
, pspTopicScoreCap :: Double
pspTopicScoreCap = Double
100.0
}
data TopicPeerState = TopicPeerState
{ TopicPeerState -> NominalDiffTime
tpsMeshTime :: !NominalDiffTime
, TopicPeerState -> Double
tpsFirstMessageDeliveries :: !Double
, TopicPeerState -> Double
tpsMeshMessageDeliveries :: !Double
, TopicPeerState -> Double
tpsMeshFailurePenalty :: !Double
, TopicPeerState -> Double
tpsInvalidMessages :: !Double
, TopicPeerState -> Maybe UTCTime
tpsGraftTime :: !(Maybe UTCTime)
, TopicPeerState -> Bool
tpsInMesh :: !Bool
} deriving (Int -> TopicPeerState -> ShowS
[TopicPeerState] -> ShowS
TopicPeerState -> String
(Int -> TopicPeerState -> ShowS)
-> (TopicPeerState -> String)
-> ([TopicPeerState] -> ShowS)
-> Show TopicPeerState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TopicPeerState -> ShowS
showsPrec :: Int -> TopicPeerState -> ShowS
$cshow :: TopicPeerState -> String
show :: TopicPeerState -> String
$cshowList :: [TopicPeerState] -> ShowS
showList :: [TopicPeerState] -> ShowS
Show, TopicPeerState -> TopicPeerState -> Bool
(TopicPeerState -> TopicPeerState -> Bool)
-> (TopicPeerState -> TopicPeerState -> Bool) -> Eq TopicPeerState
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TopicPeerState -> TopicPeerState -> Bool
== :: TopicPeerState -> TopicPeerState -> Bool
$c/= :: TopicPeerState -> TopicPeerState -> Bool
/= :: TopicPeerState -> TopicPeerState -> Bool
Eq)
defaultTopicPeerState :: TopicPeerState
defaultTopicPeerState :: TopicPeerState
defaultTopicPeerState = TopicPeerState
{ tpsMeshTime :: NominalDiffTime
tpsMeshTime = NominalDiffTime
0
, tpsFirstMessageDeliveries :: Double
tpsFirstMessageDeliveries = Double
0
, tpsMeshMessageDeliveries :: Double
tpsMeshMessageDeliveries = Double
0
, tpsMeshFailurePenalty :: Double
tpsMeshFailurePenalty = Double
0
, tpsInvalidMessages :: Double
tpsInvalidMessages = Double
0
, tpsGraftTime :: Maybe UTCTime
tpsGraftTime = Maybe UTCTime
forall a. Maybe a
Nothing
, tpsInMesh :: Bool
tpsInMesh = Bool
False
}
data ScoreThresholds = ScoreThresholds
{ ScoreThresholds -> Double
stGossipThreshold :: !Double
, ScoreThresholds -> Double
stPublishThreshold :: !Double
, ScoreThresholds -> Double
stGraylistThreshold :: !Double
, ScoreThresholds -> Double
stAcceptPXThreshold :: !Double
, ScoreThresholds -> Double
stOpportunisticGraftThreshold :: !Double
} deriving (Int -> ScoreThresholds -> ShowS
[ScoreThresholds] -> ShowS
ScoreThresholds -> String
(Int -> ScoreThresholds -> ShowS)
-> (ScoreThresholds -> String)
-> ([ScoreThresholds] -> ShowS)
-> Show ScoreThresholds
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ScoreThresholds -> ShowS
showsPrec :: Int -> ScoreThresholds -> ShowS
$cshow :: ScoreThresholds -> String
show :: ScoreThresholds -> String
$cshowList :: [ScoreThresholds] -> ShowS
showList :: [ScoreThresholds] -> ShowS
Show, ScoreThresholds -> ScoreThresholds -> Bool
(ScoreThresholds -> ScoreThresholds -> Bool)
-> (ScoreThresholds -> ScoreThresholds -> Bool)
-> Eq ScoreThresholds
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ScoreThresholds -> ScoreThresholds -> Bool
== :: ScoreThresholds -> ScoreThresholds -> Bool
$c/= :: ScoreThresholds -> ScoreThresholds -> Bool
/= :: ScoreThresholds -> ScoreThresholds -> Bool
Eq)
defaultScoreThresholds :: ScoreThresholds
defaultScoreThresholds :: ScoreThresholds
defaultScoreThresholds = ScoreThresholds
{ stGossipThreshold :: Double
stGossipThreshold = -Double
100
, stPublishThreshold :: Double
stPublishThreshold = -Double
1000
, stGraylistThreshold :: Double
stGraylistThreshold = -Double
10000
, stAcceptPXThreshold :: Double
stAcceptPXThreshold = Double
100
, stOpportunisticGraftThreshold :: Double
stOpportunisticGraftThreshold = Double
1
}
data CacheEntry = CacheEntry
{ CacheEntry -> MessageId
ceMessageId :: !MessageId
, CacheEntry -> PubSubMessage
ceMessage :: !PubSubMessage
, CacheEntry -> Text
ceTopic :: !Topic
} deriving (Int -> CacheEntry -> ShowS
[CacheEntry] -> ShowS
CacheEntry -> String
(Int -> CacheEntry -> ShowS)
-> (CacheEntry -> String)
-> ([CacheEntry] -> ShowS)
-> Show CacheEntry
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CacheEntry -> ShowS
showsPrec :: Int -> CacheEntry -> ShowS
$cshow :: CacheEntry -> String
show :: CacheEntry -> String
$cshowList :: [CacheEntry] -> ShowS
showList :: [CacheEntry] -> ShowS
Show, CacheEntry -> CacheEntry -> Bool
(CacheEntry -> CacheEntry -> Bool)
-> (CacheEntry -> CacheEntry -> Bool) -> Eq CacheEntry
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CacheEntry -> CacheEntry -> Bool
== :: CacheEntry -> CacheEntry -> Bool
$c/= :: CacheEntry -> CacheEntry -> Bool
/= :: CacheEntry -> CacheEntry -> Bool
Eq)
data MessageCache = MessageCache
{ MessageCache -> Seq [CacheEntry]
mcWindows :: !(Seq [CacheEntry])
, MessageCache -> Map MessageId CacheEntry
mcIndex :: !(Map MessageId CacheEntry)
, MessageCache -> Int
mcLen :: !Int
, MessageCache -> Int
mcGossip :: !Int
} deriving (Int -> MessageCache -> ShowS
[MessageCache] -> ShowS
MessageCache -> String
(Int -> MessageCache -> ShowS)
-> (MessageCache -> String)
-> ([MessageCache] -> ShowS)
-> Show MessageCache
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MessageCache -> ShowS
showsPrec :: Int -> MessageCache -> ShowS
$cshow :: MessageCache -> String
show :: MessageCache -> String
$cshowList :: [MessageCache] -> ShowS
showList :: [MessageCache] -> ShowS
Show, MessageCache -> MessageCache -> Bool
(MessageCache -> MessageCache -> Bool)
-> (MessageCache -> MessageCache -> Bool) -> Eq MessageCache
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MessageCache -> MessageCache -> Bool
== :: MessageCache -> MessageCache -> Bool
$c/= :: MessageCache -> MessageCache -> Bool
/= :: MessageCache -> MessageCache -> Bool
Eq)
data GossipSubRouter = GossipSubRouter
{ GossipSubRouter -> GossipSubParams
gsParams :: !GossipSubParams
, GossipSubRouter -> PeerId
gsLocalPeerId :: !PeerId
, GossipSubRouter -> TVar (Map Text (Set PeerId))
gsMesh :: !(TVar (Map Topic (Set PeerId)))
, GossipSubRouter -> TVar (Map Text (Set PeerId))
gsFanout :: !(TVar (Map Topic (Set PeerId)))
, GossipSubRouter -> TVar (Map Text UTCTime)
gsFanoutPub :: !(TVar (Map Topic UTCTime))
, GossipSubRouter -> TVar (Map PeerId PeerState)
gsPeers :: !(TVar (Map PeerId PeerState))
, GossipSubRouter -> TVar (Map MessageId UTCTime)
gsSeen :: !(TVar (Map MessageId UTCTime))
, GossipSubRouter -> TVar (Map (PeerId, Text) UTCTime)
gsBackoff :: !(TVar (Map (PeerId, Topic) UTCTime))
, GossipSubRouter -> PeerScoreParams
gsScoreParams :: !PeerScoreParams
, GossipSubRouter -> ScoreThresholds
gsThresholds :: !ScoreThresholds
, GossipSubRouter -> TVar (Map MessageId (Set PeerId))
gsIPPeerCount :: !(TVar (Map ByteString (Set PeerId)))
, GossipSubRouter -> TVar MessageCache
gsMessageCache :: !(TVar MessageCache)
, GossipSubRouter -> TVar Int
gsHeartbeatCount :: !(TVar Int)
, GossipSubRouter -> PeerId -> RPC -> IO ()
gsSendRPC :: !(PeerId -> RPC -> IO ())
, GossipSubRouter -> IO UTCTime
gsGetTime :: !(IO UTCTime)
, GossipSubRouter -> TVar (Text -> PubSubMessage -> IO ())
gsOnMessage :: !(TVar (Topic -> PubSubMessage -> IO ()))
}
emptyRPC :: RPC
emptyRPC :: RPC
emptyRPC = [SubOpts] -> [PubSubMessage] -> Maybe ControlMessage -> RPC
RPC [] [] Maybe ControlMessage
forall a. Maybe a
Nothing
emptyControlMessage :: ControlMessage
emptyControlMessage :: ControlMessage
emptyControlMessage = [IHave] -> [IWant] -> [Graft] -> [Prune] -> ControlMessage
ControlMessage [] [] [] []