Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Access] Implement keepalive routine with ping-ponging to ws connection in ws controller #6757

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
81ddee5
Added Websocket connection configurating
UlyanaAndrukhiv Nov 20, 2024
808b54b
Updated configureConnection and godoc
UlyanaAndrukhiv Nov 21, 2024
6c5ab5d
Adedd SetWriteDeadline before write operation
UlyanaAndrukhiv Nov 21, 2024
eec15e5
Set initital read deadline, updated godoc
UlyanaAndrukhiv Nov 21, 2024
fd567aa
Merge branch 'master' into UlyanaAndrukhiv/6638-ws-connection-configu…
UlyanaAndrukhiv Nov 21, 2024
098c10d
Merge branch 'master' into UlyanaAndrukhiv/6638-ws-connection-configu…
UlyanaAndrukhiv Nov 22, 2024
917bbde
Implemented ping-pong ws routine, refactored shutdownConnection
UlyanaAndrukhiv Nov 22, 2024
438b130
Merge branch 'UlyanaAndrukhiv/6638-ws-connection-configuring' of gith…
UlyanaAndrukhiv Nov 22, 2024
86cdb35
Merge branch 'master' of github.com:The-K-R-O-K/flow-go into UlyanaAn…
UlyanaAndrukhiv Nov 25, 2024
ec4e247
Added more comments and updated godoc
UlyanaAndrukhiv Nov 25, 2024
eae6bbf
Moved constants to new websockets package according to comment
UlyanaAndrukhiv Nov 25, 2024
4e2d35c
Merge branch 'UlyanaAndrukhiv/6638-ws-connection-configuring' of gith…
UlyanaAndrukhiv Nov 25, 2024
9971188
Merge branch 'master' into UlyanaAndrukhiv/6638-ws-connection-configu…
UlyanaAndrukhiv Nov 25, 2024
6cd2841
Merged with UlyanaAndrukhiv/6638-ws-connection-configuring
UlyanaAndrukhiv Nov 25, 2024
c90d75f
Updated according to comments, added unit tests for ping-pong functio…
UlyanaAndrukhiv Nov 26, 2024
afc8648
Merge branch 'master' into UlyanaAndrukhiv/6639-ws-ping-pong
UlyanaAndrukhiv Nov 26, 2024
040a949
Updated WriteMessage to WriteControl for Ping messages, updated mocks…
UlyanaAndrukhiv Nov 27, 2024
357dc2f
Merge branch 'master' into UlyanaAndrukhiv/6639-ws-ping-pong
UlyanaAndrukhiv Nov 27, 2024
276ea7e
Added tests for keepalive, configure connection, graceful shutdown, a…
UlyanaAndrukhiv Nov 28, 2024
077c543
Merge branch 'UlyanaAndrukhiv/6639-ws-ping-pong' of github.com:The-K-…
UlyanaAndrukhiv Nov 28, 2024
21259ce
Added happy case test for keepalive
UlyanaAndrukhiv Nov 28, 2024
1f5728d
Updated unit test for keep alive
UlyanaAndrukhiv Nov 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ generate-mocks: install-mock-generators
mockery --name '.*' --dir="./engine/access/state_stream" --case=underscore --output="./engine/access/state_stream/mock" --outpkg="mock"
mockery --name 'BlockTracker' --dir="./engine/access/subscription" --case=underscore --output="./engine/access/subscription/mock" --outpkg="mock"
mockery --name 'DataProvider' --dir="./engine/access/rest/websockets/data_provider" --case=underscore --output="./engine/access/rest/websockets/data_provider/mock" --outpkg="mock"
mockery --name 'DataProviderFactory' --dir="./engine/access/rest/websockets/data_provider" --case=underscore --output="./engine/access/rest/websockets/data_provider/mock" --outpkg="mock"
mockery --name 'WebsocketConnection' --dir="./engine/access/rest/websockets" --case=underscore --output="./engine/access/rest/websockets/mock" --outpkg="mock"
mockery --name 'ExecutionDataTracker' --dir="./engine/access/subscription" --case=underscore --output="./engine/access/subscription/mock" --outpkg="mock"
mockery --name 'ConnectionFactory' --dir="./engine/access/rpc/connection" --case=underscore --output="./engine/access/rpc/connection/mock" --outpkg="mock"
mockery --name 'Communicator' --dir="./engine/access/rpc/backend" --case=underscore --output="./engine/access/rpc/backend/mock" --outpkg="mock"
Expand Down
4 changes: 3 additions & 1 deletion engine/access/rest/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
flowhttp "github.com/onflow/flow-go/engine/access/rest/http"
"github.com/onflow/flow-go/engine/access/rest/http/models"
"github.com/onflow/flow-go/engine/access/rest/websockets"
"github.com/onflow/flow-go/engine/access/rest/websockets/data_provider"
legacyws "github.com/onflow/flow-go/engine/access/rest/websockets/legacy"
"github.com/onflow/flow-go/engine/access/state_stream"
"github.com/onflow/flow-go/engine/access/state_stream/backend"
Expand Down Expand Up @@ -93,7 +94,8 @@ func (b *RouterBuilder) AddWebsocketsRoute(
streamConfig backend.Config,
maxRequestSize int64,
) *RouterBuilder {
handler := websockets.NewWebSocketHandler(b.logger, config, chain, streamApi, streamConfig, maxRequestSize)
dataProviderFactory := data_provider.NewDataProviderFactory(b.logger, streamApi, streamConfig)
handler := websockets.NewWebSocketHandler(b.logger, config, chain, dataProviderFactory, maxRequestSize)
b.v1SubRouter.
Methods(http.MethodGet).
Path("/ws").
Expand Down
57 changes: 57 additions & 0 deletions engine/access/rest/websockets/connections.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package websockets
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why has this file name been changed to connections?


import (
"time"

"github.com/gorilla/websocket"
)

type WebsocketConnection interface {
ReadJSON(v interface{}) error
WriteJSON(v interface{}) error
WriteControl(messageType int, deadline time.Time) error
Close() error
SetReadDeadline(deadline time.Time) error
SetWriteDeadline(deadline time.Time) error
SetPongHandler(h func(string) error)
}

type WebsocketConnectionImpl struct {
conn *websocket.Conn
}

func NewWebsocketConnection(conn *websocket.Conn) *WebsocketConnectionImpl {
return &WebsocketConnectionImpl{
conn: conn,
}
}

var _ WebsocketConnection = (*WebsocketConnectionImpl)(nil)

func (c *WebsocketConnectionImpl) ReadJSON(v interface{}) error {
return c.conn.ReadJSON(v)
}

func (c *WebsocketConnectionImpl) WriteJSON(v interface{}) error {
return c.conn.WriteJSON(v)
}

func (c *WebsocketConnectionImpl) WriteControl(messageType int, deadline time.Time) error {
return c.conn.WriteControl(messageType, nil, deadline)
}

func (c *WebsocketConnectionImpl) Close() error {
return c.conn.Close()
}

func (c *WebsocketConnectionImpl) SetReadDeadline(deadline time.Time) error {
return c.conn.SetReadDeadline(deadline)
}

func (c *WebsocketConnectionImpl) SetWriteDeadline(deadline time.Time) error {
return c.conn.SetWriteDeadline(deadline)
}

func (c *WebsocketConnectionImpl) SetPongHandler(h func(string) error) {
c.conn.SetPongHandler(h)
}
Loading
Loading