Skip to content

Commit

Permalink
Hot fix recv zero sized body (#884)
Browse files Browse the repository at this point in the history
* Fix zero size body parsing
  • Loading branch information
NCrashed authored Mar 15, 2021
1 parent 025864d commit 53ce688
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 5 additions & 3 deletions index-server/src/Ergvein/Index/Server/TCPService/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ runConnection (sock, addr) = incGaugeWhile activeConnsGauge $ do
rawSendMsg $ MReject r
threadDelay 100000
closeConnection addr
Right _ -> do
logErrorN $ "<" <> showt addr <> ">: Impossible! Tried to send something that is not MVersionACK or MReject to client at handshake."
Right msg -> do
logErrorN $ "<" <> showt addr <> ">: Impossible! Tried to send something that is not MVersionACK or MReject to client at handshake: " <> showt msg
closeConnection addr
where
rawSendMsg :: Message -> IO ()
Expand Down Expand Up @@ -196,7 +196,9 @@ runConnection (sock, addr) = incGaugeWhile activeConnsGauge $ do

request :: MessageHeader -> ExceptT Reject ServerM Message
request MessageHeader {..} = do
messageBytes <- liftIO $ NS.recv sock $ fromIntegral msgSize
messageBytes <- if not $ messageHasPayload msgType
then pure mempty
else liftIO $ NS.recv sock $ fromIntegral msgSize
except $ mapLeft (\_-> Reject msgType MessageParsing "Failed to parse message body") $ eitherResult $ parse (messageParser msgType) messageBytes

response :: Message -> ExceptT Reject ServerM ([Message], Bool)
Expand Down
4 changes: 1 addition & 3 deletions wallet/src/Ergvein/Wallet/Indexer/Socket.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ import qualified Data.ByteString.Lazy as BL
import qualified Data.Map.Strict as M
import qualified Data.Vector.Unboxed as VU

import Debug.Trace

requiredCurrencies :: [CurrencyCode]
requiredCurrencies = if isTestnet
then [TBTC] -- TODO: add ERGO here
Expand Down Expand Up @@ -202,7 +200,7 @@ mkVers :: MonadIO m => m Message
mkVers = liftIO $ do
nonce <- randomIO
t <- fmap (fromIntegral . floor) getPOSIXTime
pure $ traceShowId $ MVersion $ Version {
pure $ MVersion $ Version {
versionVersion = protocolVersion
, versionTime = t
, versionNonce = nonce
Expand Down

0 comments on commit 53ce688

Please sign in to comment.