1
0
Fork 0
mirror of https://github.com/anyproto/anytype-heart.git synced 2025-06-11 10:18:28 +09:00

GO-4285 stream keep-alive

This commit is contained in:
Sergey Cherepanov 2024-11-15 18:07:51 +01:00
parent 96d67b0353
commit d12a1a4c73
No known key found for this signature in database
GPG key ID: 87F8EDE8FBDF637C
3 changed files with 21 additions and 1 deletions

2
go.mod
View file

@ -8,7 +8,7 @@ require (
github.com/VividCortex/ewma v1.2.0
github.com/adrium/goheif v0.0.0-20230113233934-ca402e77a786
github.com/anyproto/any-store v0.1.2
github.com/anyproto/any-sync v0.5.17
github.com/anyproto/any-sync v0.5.18-0.20241115164535-944c9cf10add
github.com/anyproto/go-chash v0.1.0
github.com/anyproto/go-naturaldate/v2 v2.0.2-0.20230524105841-9829cfd13438
github.com/anyproto/lexid v0.0.2

2
go.sum
View file

@ -83,6 +83,8 @@ github.com/anyproto/any-store v0.1.2 h1:/WKsPOQxK1jOHS7efTIosnyJTvy0O3gYg/DSnt41
github.com/anyproto/any-store v0.1.2/go.mod h1:SDlN2AzysAfs8CDd28rrs6boUUtf5H/ydCvwmj+EbsE=
github.com/anyproto/any-sync v0.5.17 h1:KD0QUjRHhWYxDfHSV1hlgvPUGzyraybJUnl7xr1GsrA=
github.com/anyproto/any-sync v0.5.17/go.mod h1:BOy7swQk2LTrjTXCpUOpy19kL1ggwKHt/JSYzFLLg0c=
github.com/anyproto/any-sync v0.5.18-0.20241115164535-944c9cf10add h1:k/6kYpUOkJ93kpnaJG7q7sTwxBPu75ZdMiXHE8iqAeU=
github.com/anyproto/any-sync v0.5.18-0.20241115164535-944c9cf10add/go.mod h1:K53/whh/9tmGbXrkPS59XyqWU3SaxhsX9g6VIYnBIlU=
github.com/anyproto/badger/v4 v4.2.1-0.20240110160636-80743fa3d580 h1:Ba80IlCCxkZ9H1GF+7vFu/TSpPvbpDCxXJ5ogc4euYc=
github.com/anyproto/badger/v4 v4.2.1-0.20240110160636-80743fa3d580/go.mod h1:T/uWAYxrXdaXw64ihI++9RMbKTCpKd/yE9+saARew7k=
github.com/anyproto/go-chash v0.1.0 h1:I9meTPjXFRfXZHRJzjOHC/XF7Q5vzysKkiT/grsogXY=

View file

@ -9,6 +9,7 @@ import (
"github.com/anyproto/any-sync/app"
"github.com/anyproto/any-sync/app/logger"
"github.com/anyproto/any-sync/commonspace/spacesyncproto"
"github.com/anyproto/any-sync/net/streampool"
"storj.io/drpc"
@ -63,6 +64,7 @@ type clientPeerManager struct {
sync.Mutex
peerToPeerStatus PeerToPeerStatus
keepAliveMessage drpc.Message
}
func (n *clientPeerManager) Init(a *app.App) (err error) {
@ -75,6 +77,18 @@ func (n *clientPeerManager) Init(a *app.App) (err error) {
n.streamPool = app.MustComponent[streampool.StreamPool](a)
n.spaceSyncService = app.MustComponent[Updater](a)
n.peerToPeerStatus = app.MustComponent[PeerToPeerStatus](a)
var keepAliveMsg = &spacesyncproto.SpaceSubscription{
SpaceIds: []string{n.spaceId},
Action: spacesyncproto.SpaceSubscriptionAction_Subscribe,
}
payload, err := keepAliveMsg.Marshal()
if err != nil {
return
}
n.keepAliveMessage = &spacesyncproto.ObjectSyncMessage{
Payload: payload,
}
return
}
@ -256,6 +270,10 @@ func (n *clientPeerManager) watchPeer(p peer.Peer) {
}
}
func (n *clientPeerManager) KeepAlive(ctx context.Context) {
_ = n.BroadcastMessage(ctx, n.keepAliveMessage)
}
func (n *clientPeerManager) Close(ctx context.Context) (err error) {
n.ctxCancel()
n.peerToPeerStatus.UnregisterSpace(n.spaceId)