...
 
Commits (2)
......@@ -160,7 +160,7 @@ sendTcpMessage ::
sendTcpMessage conn msg =
$(withLoggingTH)
(LogNetworkStatement
([qc|sendTcpMessage: Host: {Conn.ipAddress conn} |]))
[qc|sendTcpMessage: Host: {Conn.ipAddress conn} |])
LevelInfo $ do
let sock = Conn.socket conn
lock = Conn.waitWrite conn
......@@ -183,7 +183,7 @@ sendUdpMessage ::
sendUdpMessage conn msg =
$(withLoggingTH)
(LogNetworkStatement
([qc|sendUdpMessage: Host: {Conn.ipAddress conn}: Port: {Conn.port conn}: MsgLength: {BSLC.length msg}|]))
[qc|sendUdpMessage: Host: {Conn.ipAddress conn}: Port: {Conn.port conn}: MsgLength: {BSLC.length msg}|])
LevelInfo $ do
let sock = Conn.socket conn
lock = Conn.waitWrite conn
......
......@@ -51,12 +51,12 @@ doEncryptedHandshake connection sk = do
openConnection ::
forall m. (HasLogging m, HasSecretKey m)
=> NetworkConfig
-> TransportType
=> NetworkConfig
-> TransportType
-> m (Either AriviNetworkException ConnectionHandle)
openConnection NetworkConfig{..} tt =
$(withLoggingTH)
(LogNetworkStatement ([qc|Opening Connection to host {_ip} |]))
(LogNetworkStatement [qc|Opening Connection to host {_ip} |])
LevelDebug $ do
let cId = makeConnectionId _ip portNum tt
sock <- liftIO $ createSocket _ip (read (show portNum)) tt
......
......@@ -82,7 +82,7 @@ issueFindNode ::
=> Peer
-> m ()
issueFindNode rpeer = do
nc@NetworkConfig {..} <- (^. networkConfig) <$> ask
nc@NetworkConfig {..} <- asks (^. networkConfig)
let rnid = fst $ getPeer rpeer
rnep = snd $ getPeer rpeer
ruport = Arivi.P2P.Kademlia.Types.udpPort rnep
......
......@@ -58,7 +58,7 @@ kademliaMessageHandler (KademliaRequest payload) = KademliaResponse <$> do
rnep = fromEndPoint msgb
rnid = Arivi.P2P.Kademlia.Types.nodeId msgb
rpeer = Peer (rnid, rnep)
nc@NetworkConfig {..} <- (^. networkConfig) <$> ask
nc@NetworkConfig {..} <- asks (^. networkConfig)
case msgb of
PING {} -> do
$(logDebug) $
......
......@@ -70,7 +70,7 @@ issuePing ::
=> Peer
-> m Bool
issuePing rpeer = do
nc <- (^. networkConfig) <$> ask
nc <- asks (^. networkConfig)
let rnid = fst $ getPeer rpeer
rnep = snd $ getPeer rpeer
ruport = Arivi.P2P.Kademlia.Types.udpPort rnep
......
......@@ -126,7 +126,7 @@ getVerifiedPeers peerR k = do
-- -- getRandomVerifiedNodes :: (HasKbucket m, MonadIO m) => Int -> m [Peer]
-- -- getRandomVerifiedNodes k = do
-- -- kb <- getKb
-- -- let vt = nodeStatusTable kb
-- -- let vt = nodeStatusTable kb
-- -- rps <- getKRandomPeers k
-- -- mapM isVerified rps
filterPeer :: NodeId -> NodeId -> [Peer] -> [Peer]
......@@ -185,7 +185,7 @@ issueVerifyNode ::
-> Peer
-> m [Peer]
issueVerifyNode peerV peerT peerR = do
nc@NetworkConfig {..} <- (^. networkConfig) <$> ask
nc@NetworkConfig {..} <- asks (^. networkConfig)
-- TODO randomly select a verified node and not as a parameter
let vnid = fst $ getPeer peerV
vnep = snd $ getPeer peerV
......
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies#-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE UndecidableInstances #-}
......@@ -47,8 +46,8 @@ class (HasTopics env t, HasSubscribers env t, HasNotifiers env t, HasInbox env m
type HasPubSub env t msg
= ( HasPubSubEnv env t msg
, Eq t, Ord t, Hashable t, Serialise t
, Eq msg, Hashable msg, Serialise msg
)
, Eq msg, Hashable msg, Serialise msg
)
mkPubSub :: IO (PubSubEnv t msg)
......
......@@ -49,7 +49,7 @@ notifyHandler nid (PubSubRequest (PubSubPayload (t, msg))) = do
inboxed <- asks inbox
cached <- asks cache
handlers <- asks topicHandlers
(PubSubResponse . PubSubPayload . (t, )) <$> handleTopic nid inboxed cached handlers t msg
PubSubResponse . PubSubPayload . (t, ) <$> handleTopic nid inboxed cached handlers t msg
publishHandler ::
( MonadReader env m
......@@ -61,7 +61,7 @@ publishHandler nid (PubSubRequest (PubSubPayload (t, msg))) = do
inboxed <- asks inbox
cached <- asks cache
handlers <- asks topicHandlers
(PubSubResponse . PubSubPayload . (t, )) <$> handleTopic nid inboxed cached handlers t msg
PubSubResponse . PubSubPayload . (t, ) <$> handleTopic nid inboxed cached handlers t msg
subscribeHandler ::
( MonadReader env m
......@@ -78,7 +78,7 @@ subscribeHandler nid (PubSubRequest (PubSubPayload (t, subTimer))) = do
then return (PubSubResponse Ok)
else return (PubSubResponse Error)
handleTopic ::
handleTopic ::
(Eq t, Hashable t, Eq msg, Hashable msg, MonadIO m)
=> NodeId
-> TVar (Inbox msg)
......
......@@ -23,7 +23,7 @@ notify ::
-> m ()
notify req@(PubSubPayload (t, msg)) = do
subs <- asks subscribers
inboxed <- join $ liftIO . readTVarIO <$> asks inbox
inboxed <- (liftIO . readTVarIO) =<< asks inbox
peers <- liftIO $ notifiersForMessage inboxed subs msg t
responses <-
mapSetConcurrently
......
......@@ -41,7 +41,7 @@ registerResource resource resourceHandler resourceType = do
funcA l hm = ArchivedResourceToPeerMap $ HM.insert resource (resourceHandler, l) (getArchivedMap hm)
funcT l hm = TransientResourceToPeerMap $ HM.insert resource (resourceHandler, l) (getTransientMap hm)
-- | Called by the service to fetch a resource. P2P decides best peer to ask for the resource.
-- | Called by the service to fetch a resource. P2P decides best peer to ask for the resource.
fetchResource ::
( HasP2PEnv env m r t msg pmsg
)
......@@ -79,7 +79,7 @@ fetchResourceForMessage ::
-> RpcPayload r msg
-> m (Either AriviP2PException (RpcPayload r msg))
fetchResourceForMessage storedMsg payload@(RpcPayload _ _) = do
Inbox inboxed <- join $ liftIO . readTVarIO <$> asks inbox
Inbox inboxed <- (liftIO . readTVarIO) =<< asks inbox
case HM.lookup storedMsg inboxed of
Just nodeListTVar -> do
nodeList <- (liftIO . readTVarIO) nodeListTVar
......