@@ -423,7 +423,8 @@ handleIncomingMessages node = go [] Map.empty
423423 NT.ConnectionClosed cid ->
424424 go (List.delete cid halfOpenConns) (Map.delete cid openConns)
425425 NT.ErrorEvent _ ->
426− fail "handleIncomingMessages: TODO 3"
426+ -- fail "handleIncomingMessages: TODO 3"
427+ go halfOpenConns openConns
427428 NT.EndPointClosed ->
428429 return ()
429430 NT.ReceivedMulticast _ _ ->
@@ -437,26 +438,26 @@ handleIncomingMessages node = go [] Map.empty
437438--------------------------------------------------------------------------------
438439
439440getConnectionTo :: ProcessId -> Process (Maybe NT.Connection)
440−getConnectionTo pid = do
441+getConnectionTo them = do
441442 ourState <- processState <$> ask
442− mConn <- liftIO $ withMVar ourState $ return . (^. connectionTo pid)
443+ mConn <- liftIO $ withMVar ourState $ return . (^. connectionTo them)
443444 case mConn of
444445 Just conn -> return . Just $ conn
445− Nothing -> createConnectionTo pid
446+ Nothing -> createConnectionTo them
446447
447448createConnectionTo :: ProcessId -> Process (Maybe NT.Connection)
448−createConnectionTo pid = do
449+createConnectionTo them = do
449450 proc <- ask
450451 mConn <- liftIO $ NT.connect (localEndPoint . processNode $ proc)
451− (processAddress pid)
452+ (processAddress them)
452453 NT.ReliableOrdered
453454 NT.defaultConnectHints
454455 case mConn of
455456 Right conn -> do
456457 mConn' <- liftIO $ modifyMVar (processState proc) $ \st ->
457− case st ^. connectionTo pid of
458+ case st ^. connectionTo them of
458459 Just conn' -> return (st, Just conn')
459− Nothing -> return (connectionTo pid ^= Just conn $ st, Nothing)
460+ Nothing -> return (connectionTo them ^= Just conn $ st, Nothing)
460461 case mConn' of
461462 Just conn' -> do
462463 -- Somebody else already created a connection while we weren't looking
@@ -467,27 +468,30 @@ createConnectionTo pid = do
467468 liftIO $ NT.close conn
468469 return . Just $ conn'
469470 Nothing -> do
470− sendBinary pid conn $ lpidToPayload (processLocalId pid)
471+ sendBinary them conn $ lpidToPayload (processLocalId them)
471472 return . Just $ conn
472473 Left _err -> do
473474 -- TODO: should probably pass this error to remoteProcessFailed
474− remoteProcessFailed pid
475+ remoteProcessFailed them
475476 return Nothing
476477
477478sendBinary :: ProcessId -> NT.Connection -> [BSS.ByteString] -> Process ()
478−sendBinary pid conn payload = do
479+sendBinary them conn payload = do
479480 result <- liftIO $ NT.send conn payload
480481 case result of
481482 Right () -> return ()
482− Left err -> do
483− ourState <- processState <$> ask
483+ Left _ ->
484+ {-
485+ -- TODO: put into unreachable state rather than Nothing
486+ -- ourState <- processState <$> ask
484487 liftIO $ modifyMVar_ ourState $
485− return . (connectionTo pid ^= Nothing)
486− liftIO $ throwIO err
488+ return . (connectionTo them ^= Nothing)
489+ -}
490+ remoteProcessFailed them
487491
488492sendMessage :: ProcessId -> NT.Connection -> Message -> Process ()
489−sendMessage pid conn (Message fp enc) =
490− sendBinary pid conn $ encodeFingerprint fp : BSL.toChunks enc
493+sendMessage them conn (Message fp enc) =
494+ sendBinary them conn $ encodeFingerprint fp : BSL.toChunks enc
491495
492496payloadToMessage :: [BSS.ByteString] -> Message
493497payloadToMessage payload = Message fp msg