Skip to content

Commit

Permalink
Support websocket compression.
Browse files Browse the repository at this point in the history
  • Loading branch information
web3-developer committed Sep 18, 2024
1 parent 908dc38 commit 6e47b9f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
10 changes: 8 additions & 2 deletions fluffy/conf.nim
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,21 @@ type
.}: IpAddress

wsEnabled* {.
desc: "Enable the Websocket JSON-RPC server", defaultValue: false, name: "ws"
desc: "Enable the WebSocket JSON-RPC server", defaultValue: false, name: "ws"
.}: bool

wsPort* {.
desc: "Port for the Websocket JSON-RPC server",
desc: "Port for the WebSocket JSON-RPC server",
defaultValue: 8546,
name: "ws-port"
.}: Port

wsCompression* {.
desc: "Enable compression for the WebSocket JSON-RPC server",
defaultValue: false,
name: "ws-compression"
.}: bool

tableIpLimit* {.
hidden,
desc:
Expand Down
20 changes: 11 additions & 9 deletions fluffy/fluffy.nim
Original file line number Diff line number Diff line change
Expand Up @@ -244,28 +244,30 @@ proc run(config: PortalConf) {.raises: [CatchableError].} =
if config.wsEnabled:
let
ta = initTAddress(config.rpcAddress, config.wsPort)
wsServer = newRpcWebSocketServer(ta)
rpcWsServer = newRpcWebSocketServer(ta, compression = config.wsCompression)

wsServer.installDiscoveryApiHandlers(d)
wsServer.installWeb3ApiHandlers()
rpcWsServer.installDiscoveryApiHandlers(d)
rpcWsServer.installWeb3ApiHandlers()
if node.stateNetwork.isSome():
wsServer.installPortalApiHandlers(node.stateNetwork.value.portalProtocol, "state")
rpcWsServer.installPortalApiHandlers(
node.stateNetwork.value.portalProtocol, "state"
)
if node.historyNetwork.isSome():
wsServer.installEthApiHandlers(
rpcWsServer.installEthApiHandlers(
node.historyNetwork.value, node.beaconLightClient, node.stateNetwork
)
wsServer.installPortalApiHandlers(
rpcWsServer.installPortalApiHandlers(
node.historyNetwork.value.portalProtocol, "history"
)
wsServer.installPortalDebugApiHandlers(
rpcWsServer.installPortalDebugApiHandlers(
node.historyNetwork.value.portalProtocol, "history"
)
if node.beaconNetwork.isSome():
wsServer.installPortalApiHandlers(
rpcWsServer.installPortalApiHandlers(
node.beaconNetwork.value.portalProtocol, "beacon"
)

wsServer.start()
rpcWsServer.start()

runForever()

Expand Down

0 comments on commit 6e47b9f

Please sign in to comment.