aboutsummaryrefslogtreecommitdiff
path: root/src/Ssb/Peer/RPC.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Ssb/Peer/RPC.hs')
-rw-r--r--src/Ssb/Peer/RPC.hs38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/Ssb/Peer/RPC.hs b/src/Ssb/Peer/RPC.hs
index 1336b5e..1de70f1 100644
--- a/src/Ssb/Peer/RPC.hs
+++ b/src/Ssb/Peer/RPC.hs
@@ -91,7 +91,7 @@ instance FromJSON ProcedureType where
"async" -> return Async
"source" -> return Source
"duplex" -> return Duplex
- otherwise -> fail $ "unknown value '" <> toS v <> "'"
+ _ -> fail $ "unknown value '" <> toS v <> "'"
instance ToJSON ProcedureType where
toJSON Async = "async"
@@ -323,9 +323,9 @@ instance Default Router
instance Handler Router where
endpoints demuxer = Map.keys (endpointHandlers demuxer)
- serve demuxer endpoint = case Map.lookup endpoint endpointHandlers' of
- Nothing -> (notFoundHandlerFunc endpoint)
- Just handler -> handler
+ serve demuxer endpoint = fromMaybe
+ (notFoundHandlerFunc endpoint)
+ (Map.lookup endpoint endpointHandlers')
where endpointHandlers' = endpointHandlers demuxer
notifyConnect demuxer id = do
@@ -451,7 +451,7 @@ streamStatus :: Stream -> STM StreamStatus
streamStatus stream = do
table <- readTMVar $ streamTable stream
return
- $ fromMaybe Closed (status . fst <$> Map.lookup (streamID stream) table)
+ $ maybe Closed (status . fst) (Map.lookup (streamID stream) table)
-- | manageStreamConn manages stream connection changes when writing messages
-- to a stream.
@@ -493,7 +493,7 @@ handleMessage :: Handler h => h -> ConnState -> Message -> IO Bool
handleMessage handler conn msg = do
nextReqNum <- atomically $ readTMVar (nextIncomingReqNum conn)
if
- | (header msg) == goodByeHeader -> return False
+ | header msg == goodByeHeader -> return False
| (isRequest nextReqNum msg) -> serveRequest handler conn msg
| (isEndOfStream msg) -> internalCloseStream conn msg
| (isAsyncResponse msg) -> do
@@ -503,7 +503,7 @@ handleMessage handler conn msg = do
where
internalCloseStream conn msg = do
let flags = def { isStream = True, isEndOrError = True }
- let requestNumber' = (requestNumber . header $ msg)
+ let requestNumber' = requestNumber . header $ msg
let mVarTable =
if requestNumber' > 0 then streamsIn conn else streamsOut conn
table <- atomically $ takeTMVar mVarTable
@@ -554,7 +554,7 @@ handleMessage handler conn msg = do
then return $ Left errTooManyRequests
else do
let (reqNum', table') = if streamID stream == reqNum
- then (reqNum + 1, (Map.insert reqNum (stream, chan) table))
+ then (reqNum + 1, Map.insert reqNum (stream, chan) table)
else (reqNum, table)
putTMVar (nextIncomingReqNum conn) reqNum'
putTMVar (streamsIn conn) table'
@@ -566,7 +566,7 @@ handleMessage handler conn msg = do
Right _ -> do
-- Serving a request call, how do we close it nicely?
let endpoint = Endpoint (name req) (typ req)
- spawnConnection stream $ (serve handler) endpoint (args req) stream
+ spawnConnection stream $ serve handler endpoint (args req) stream
return True
where errTooManyRequests = "connection limit reached, dropping request" :: Text
@@ -619,7 +619,7 @@ readBoxStream conn bytes = do
readMessage :: ConnState -> IO (Either Text Message)
readMessage conn = do
headerBuf <- readBoxStream (boxConn conn) headerLength
- header <- (return $ headerBuf >>= decode)
+ let header = headerBuf >>= decode
case header of
Left err -> return $ Left $ "RPC.readMessage header: " <> err
Right header -> do
@@ -627,10 +627,10 @@ readMessage conn = do
let ret = liftA2 (<>) headerBuf bodyBuf >>= decode
logDebug conn
$ "readMessage ("
- <> (Ssb.formatPublicKey $ connPeer conn)
+ <> Ssb.formatPublicKey (connPeer conn)
<> ")"
- <> (show ret)
- return $ ret
+ <> show ret
+ return ret
where
decode :: Serialize a => ByteString -> Either Text a
decode = mapLeft toS . Serialize.decode
@@ -639,9 +639,9 @@ writeMessage :: ConnState -> Message -> IO (Either Text ())
writeMessage conn msg = do
logDebug conn
$ "writeMessage ("
- <> (Ssb.formatPublicKey $ connPeer conn)
+ <> Ssb.formatPublicKey (connPeer conn)
<> ")"
- <> (show msg)
+ <> show msg
BoxStream.sendStream (boxConn conn) $ Serialize.encode msg
-- | request makes a Remote Procedure Call on the peer.
@@ -673,7 +673,7 @@ request conn req session = do
}
let stream = Stream { streamID = reqNum
- , streamType = (typ req)
+ , streamType = typ req
, conn = conn
, direction = Outgoing
, status = Open
@@ -788,7 +788,7 @@ newCloseErrorNotification streamID msg = do
closeStreamWithError :: Stream -> Text -> IO (Either Text ())
closeStreamWithError stream err = case streamType stream of
Async -> return . return $ ()
- otherwise ->
+ _ ->
either (return . Left) (manageStreamConn stream)
$ newCloseErrorNotification (streamID stream) err
@@ -818,7 +818,7 @@ readStreamJSON stream = do
resp <- readStream stream
case resp of
(Just (JSONPayload buf)) -> return (Just <$> decodeJSON buf)
- (Just otherwise ) -> return (errPayload resp)
+ (Just _) -> return (errPayload resp)
Nothing -> return . return $ Nothing
where
errPayload payload =
@@ -834,7 +834,7 @@ writeStream stream flags payload = do
let msgID = case direction stream of
Incoming -> -1 * streamID stream
Outgoing -> streamID stream
- let flags' = flags { isStream = not $ (streamType stream) == Async }
+ let flags' = flags { isStream = streamType stream /= Async }
let header' = case payload of
(BinaryPayload p) ->
newHeader (flags' { bodyType = Binary }) msgID p