Skip to content

Commit

Permalink
Allow connecting to remote Ogmios hosts behind TLS
Browse files Browse the repository at this point in the history
  Fixes #128.
  • Loading branch information
KtorZ committed Jul 20, 2023
1 parent c588f21 commit f71ff68
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
### [2.4.2] - unreleased

#### Added

- Allow connection to remote Ogmios hosts behind TLS. This is now possible by prefixing the hostname with `wss://`.

#### Changed

N/A

#### Removed

N/A

### [2.4.1] - 2023-06-29

#### Added
Expand Down
1 change: 1 addition & 0 deletions kupo.cabal

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ library:
- warp
- websockets
- websockets-json
- wuss

tests:
unit:
Expand Down
16 changes: 14 additions & 2 deletions src/Kupo/App/ChainSync/Ogmios.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import Kupo.Prelude
import Control.Exception.Safe
( MonadThrow
)
import Data.List
( stripPrefix
)
import Kupo.App.Mailbox
( Mailbox
, putHighFrequencyMessage
Expand Down Expand Up @@ -44,6 +47,7 @@ import Kupo.Data.Ogmios

import qualified Network.WebSockets as WS
import qualified Network.WebSockets.Json as WS
import qualified Wuss as WSS

runChainSyncClient
:: forall m.
Expand Down Expand Up @@ -91,11 +95,19 @@ connect
-> Int
-> (WS.Connection -> IO a)
-> IO a
connect ConnectionStatusToggle{toggleConnected} host port action =
WS.runClientWith host port "/"
connect ConnectionStatusToggle{toggleConnected} url port action =
runClientWith port "/"
-- TODO: Try to negotiate compact mode v2 once available.
--
-- See [ogmios#237](https://github.com/CardanoSolutions/ogmios/issues/237)
--
-- [("Sec-WebSocket-Protocol", "ogmios.v1:compact")]
WS.defaultConnectionOptions [] (\ws -> toggleConnected >> action ws)
where
runClientWith =
case stripPrefix "wss://" url of
Just host ->
WSS.runSecureClientWith host . fromIntegral
_ ->
let host = fromMaybe url (stripPrefix "ws://" url)
in WS.runClientWith host
2 changes: 1 addition & 1 deletion src/Kupo/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ serverHostOption :: Parser String
serverHostOption = option str $ mempty
<> long "host"
<> metavar "IPv4"
<> help "Address to bind to."
<> help "Address to bind to. Prefix with 'wss://' to connect to hosts behind TLS."
<> value "127.0.0.1"
<> showDefault
<> completer (bashCompleter "hostname")
Expand Down

0 comments on commit f71ff68

Please sign in to comment.