summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2020-01-18 21:58:18 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2020-01-18 21:58:18 +0100
commit25324026a1033c43652a058f966dfb3d255102ae (patch)
tree6aa3c1dc22b8ebd17f8629e766e7564108bf5e0f
parent167f580c2cbb08c541f1f4480f8862be75bd9ae0 (diff)
Use encrypted channel as soon as accept is received
-rw-r--r--src/Network.hs7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/Network.hs b/src/Network.hs
index eceeaff..339be7a 100644
--- a/src/Network.hs
+++ b/src/Network.hs
@@ -189,7 +189,10 @@ startServer origHead logd bhost services = do
mbpeer <- M.lookup paddr <$> readMVar peers
(peer, content, secure) <- if
| Just peer <- mbpeer
- , ChannelEstablished ch <- peerChannel peer
+ , Just ch <- case peerChannel peer of
+ ChannelEstablished ch -> Just ch
+ ChannelOurAccept _ sch -> Just $ fromStored sch
+ _ -> Nothing
, Right plain <- runExcept $ channelDecrypt ch msg
-> return (peer, plain, True)
@@ -399,7 +402,7 @@ handlePacket logd identity secure opeer chanSvc (TransportHeader headers) = do
[ serializeObject $ transportToObject $ TransportHeader $ reverse $ phHead ph
, BL.concat $ map lazyLoadBytes $ phBody ph
]
- case peerChannel opeer of
+ case peerChannel $ phPeer ph of
ChannelEstablished ch -> do
x <- runExceptT (channelEncrypt ch plain)
case x of Right ctext -> void $ sendTo (peerSocket $ phPeer ph) ctext paddr