1
0
Fork 0
mirror of https://github.com/anyproto/anytype-heart.git synced 2025-06-08 05:47:07 +09:00

GO-3171: refactoring

Signed-off-by: AnastasiaShemyakinskaya <shem98a@mail.ru>
This commit is contained in:
AnastasiaShemyakinskaya 2024-05-28 13:46:26 +02:00
parent 67fa0d02ae
commit a30db2f1ca
No known key found for this signature in database
GPG key ID: CCD60ED83B103281
13 changed files with 922 additions and 514 deletions

View file

@ -74,7 +74,6 @@ import (
"github.com/anyproto/anytype-heart/core/recordsbatcher"
"github.com/anyproto/anytype-heart/core/subscription"
"github.com/anyproto/anytype-heart/core/syncstatus"
"github.com/anyproto/anytype-heart/core/syncstatus/p2p"
"github.com/anyproto/anytype-heart/core/syncstatus/nodestatus"
"github.com/anyproto/anytype-heart/core/syncstatus/spacesyncstatus"
"github.com/anyproto/anytype-heart/core/wallet"
@ -228,7 +227,6 @@ func Bootstrap(a *app.App, components ...app.Component) {
Register(virtualspaceservice.New()).
Register(spacecore.New()).
Register(idresolver.New()).
Register(p2p.NewObservers()).
Register(localdiscovery.New()).
Register(peermanager.New()).
Register(typeprovider.New()).

View file

@ -1,4 +1,4 @@
package p2p
package peerstatus
import (
"context"
@ -6,15 +6,18 @@ import (
"time"
"github.com/anyproto/any-sync/app"
"github.com/anyproto/any-sync/app/ocache"
"github.com/anyproto/any-sync/net/pool"
"github.com/anyproto/anytype-heart/core/event"
"github.com/anyproto/anytype-heart/pb"
"github.com/anyproto/anytype-heart/pkg/lib/logging"
"github.com/anyproto/anytype-heart/space/spacecore/peerstore"
)
const CName = "core.syncstatus.p2p"
var log = logging.Logger(CName)
type Status int32
const (
@ -36,7 +39,7 @@ type PeerUpdateHook interface {
type StatusUpdateSender interface {
app.ComponentRunnable
CheckPeerStatus()
P2PNotPossible()
SendNotPossibleStatus()
}
type p2pStatus struct {
@ -44,6 +47,7 @@ type p2pStatus struct {
eventSender event.Sender
contextCancel context.CancelFunc
ctx context.Context
peerStore peerstore.PeerStore
sync.Mutex
status Status
@ -60,10 +64,11 @@ func NewP2PStatus(spaceId string) StatusUpdateSender {
func (p *p2pStatus) Init(a *app.App) (err error) {
p.eventSender = app.MustComponent[event.Sender](a)
p.peersConnectionPool = app.MustComponent[pool.Service](a)
p.peerStore = app.MustComponent[peerstore.PeerStore](a)
hookRegister := app.MustComponent[HookRegister](a)
hookRegister.RegisterP2PNotPossible(p.P2PNotPossible)
hookRegister.RegisterP2PNotPossible(p.SendNotPossibleStatus)
hookRegister.RegisterPeerDiscovered(p.CheckPeerStatus)
peerManager := app.MustComponent[PeerUpdateHook](a)
@ -92,7 +97,7 @@ func (p *p2pStatus) CheckPeerStatus() {
p.forceCheckSpace <- struct{}{}
}
func (p *p2pStatus) P2PNotPossible() {
func (p *p2pStatus) SendNotPossibleStatus() {
p.updateStatus <- NotPossible
}
@ -117,11 +122,11 @@ func (p *p2pStatus) checkP2PDevices() {
func (p *p2pStatus) updateSpaceP2PStatus() {
p.Lock()
defer p.Unlock()
var connectionCount int64
p.peersConnectionPool.ForEach(func(v ocache.Object) bool {
connectionCount++
return true
})
connectionCount, err := p.countOpenConnections()
if err != nil {
log.Errorf("failed to get pick peer %s", err)
return
}
if p.status != Unknown {
// avoiding sending of redundant event
p.handleNonUnknownStatus(connectionCount)
@ -130,6 +135,21 @@ func (p *p2pStatus) updateSpaceP2PStatus() {
}
}
func (p *p2pStatus) countOpenConnections() (int64, error) {
var connectionCount int64
ctx, cancelFunc := context.WithTimeout(context.Background(), time.Second*20)
defer cancelFunc()
peerIds := p.peerStore.LocalPeerIds(p.spaceId)
for _, peerId := range peerIds {
_, err := p.peersConnectionPool.Pick(ctx, peerId)
if err != nil {
return 0, err
}
connectionCount++
}
return connectionCount, nil
}
func (p *p2pStatus) handleUnknownStatus(connectionCount int64) {
if connectionCount > 0 {
p.sendEvent(p.spaceId, pb.EventP2PStatus_Connected)

View file

@ -1,4 +1,4 @@
package p2p
package peerstatus
import (
"context"
@ -58,7 +58,7 @@ func TestP2pStatus_SendNewStatus(t *testing.T) {
},
},
})
f.P2PNotPossible()
f.SendNotPossibleStatus()
// then
status := f.StatusUpdateSender.(*p2pStatus)
@ -88,7 +88,7 @@ func TestP2pStatus_SendNewStatus(t *testing.T) {
},
},
})
f.P2PNotPossible()
f.SendNotPossibleStatus()
// then
status := f.StatusUpdateSender.(*p2pStatus)
@ -117,7 +117,7 @@ func TestP2pStatus_SendNewStatus(t *testing.T) {
},
},
})
f.P2PNotPossible()
f.SendNotPossibleStatus()
// then
status := f.StatusUpdateSender.(*p2pStatus)
@ -145,7 +145,7 @@ func TestP2pStatus_SendNewStatus(t *testing.T) {
},
},
})
f.P2PNotPossible()
f.SendNotPossibleStatus()
// then
status := f.StatusUpdateSender.(*p2pStatus)
@ -232,7 +232,7 @@ func TestP2pStatus_SendPeerUpdate(t *testing.T) {
},
},
})
f.P2PNotPossible()
f.SendNotPossibleStatus()
err = waitForStatus(f.StatusUpdateSender.(*p2pStatus), NotPossible)
assert.Nil(t, err)
@ -309,7 +309,6 @@ func newFixture(t *testing.T, spaceId string, initialStatus pb.EventP2PStatusSta
store := peerstore.New()
a.Register(testutil.PrepareMock(ctx, a, sender)).
Register(service).
Register(NewObservers()).
Register(store)
err := store.Init(a)
assert.Nil(t, err)

View file

@ -1575,6 +1575,8 @@
- [Event.Object.Subscription.Groups](#anytype-Event-Object-Subscription-Groups)
- [Event.Object.Subscription.Position](#anytype-Event-Object-Subscription-Position)
- [Event.Object.Subscription.Remove](#anytype-Event-Object-Subscription-Remove)
- [Event.P2PStatus](#anytype-Event-P2PStatus)
- [Event.P2PStatus.Update](#anytype-Event-P2PStatus-Update)
- [Event.Payload](#anytype-Event-Payload)
- [Event.Payload.Broadcast](#anytype-Event-Payload-Broadcast)
- [Event.Ping](#anytype-Event-Ping)
@ -1604,6 +1606,7 @@
- [ResponseEvent](#anytype-ResponseEvent)
- [Event.Block.Dataview.SliceOperation](#anytype-Event-Block-Dataview-SliceOperation)
- [Event.P2PStatus.Status](#anytype-Event-P2PStatus-Status)
- [Event.Space.Network](#anytype-Event-Space-Network)
- [Event.Space.Status](#anytype-Event-Space-Status)
- [Event.Space.SyncError](#anytype-Event-Space-SyncError)
@ -24598,6 +24601,7 @@ Precondition: user A opened a block
| payloadBroadcast | [Event.Payload.Broadcast](#anytype-Event-Payload-Broadcast) | | |
| membershipUpdate | [Event.Membership.Update](#anytype-Event-Membership-Update) | | |
| spaceSyncStatusUpdate | [Event.Space.SyncStatus.Update](#anytype-Event-Space-SyncStatus-Update) | | |
| p2pStatusUpdate | [Event.P2PStatus.Update](#anytype-Event-P2PStatus-Update) | | |
@ -24909,6 +24913,32 @@ Removes document from subscription
<a name="anytype-Event-P2PStatus"></a>
### Event.P2PStatus
<a name="anytype-Event-P2PStatus-Update"></a>
### Event.P2PStatus.Update
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| spaceId | [string](#string) | | |
| status | [Event.P2PStatus.Status](#anytype-Event-P2PStatus-Status) | | |
<a name="anytype-Event-Payload"></a>
### Event.Payload
@ -25334,6 +25364,19 @@ Precondition: user A and user B opened the same block
<a name="anytype-Event-P2PStatus-Status"></a>
### Event.P2PStatus.Status
| Name | Number | Description |
| ---- | ------ | ----------- |
| Connected | 0 | |
| NotPossible | 1 | |
| NotConnected | 2 | |
<a name="anytype-Event-Space-Network"></a>
### Event.Space.Network

10
go.mod
View file

@ -142,10 +142,7 @@ require (
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chigopher/pathlib v0.19.1 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.12.1 // indirect
github.com/crackcomm/go-gitignore v0.0.0-20170627025303-887ab5e44cc3 // indirect
github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
@ -155,7 +152,6 @@ require (
github.com/dsoprea/go-utility/v2 v2.0.0-20221003172846-a3e1774ef349 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/envoyproxy/protoc-gen-validate v1.0.4 // indirect
github.com/ethereum/c-kzg-4844 v0.4.0 // indirect
github.com/fogleman/gg v1.3.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-errors/errors v1.4.2 // indirect
@ -205,13 +201,11 @@ require (
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/miekg/dns v1.1.58 // indirect
github.com/miguelmota/go-ethereum-hdwallet v0.1.2 // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mschoch/smat v0.2.0 // indirect
@ -245,7 +239,6 @@ require (
github.com/spf13/viper v1.15.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
@ -274,7 +267,6 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect
lukechampine.com/blake3 v1.2.1 // indirect
nhooyr.io/websocket v1.8.7 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)
replace github.com/dgraph-io/badger/v4 => github.com/anyproto/badger/v4 v4.2.1-0.20240110160636-80743fa3d580
@ -294,3 +286,5 @@ replace github.com/araddon/dateparse => github.com/mehanizm/dateparse v0.0.0-202
replace github.com/multiformats/go-multiaddr => github.com/anyproto/go-multiaddr v0.8.1-0.20221213144344-0b6b93adaec4
replace github.com/gogo/protobuf => github.com/anyproto/protobuf v1.3.3-0.20240201225420-6e325cf0ac38
replace github.com/anyproto/any-sync => ./../any-sync

58
go.sum
View file

@ -42,8 +42,6 @@ github.com/AndreasBriese/bbloom v0.0.0-20180913140656-343706a395b7/go.mod h1:bOv
github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ=
github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
github.com/HdrHistogram/hdrhistogram-go v1.1.2 h1:5IcZpTvzydCQeHzK4Ef/D5rrSqwxob0t8PQPMybUNFM=
github.com/HdrHistogram/hdrhistogram-go v1.1.2/go.mod h1:yDgFjdqOqDEKOvasDdhWNXYg9BVp4O+o5f6V/ehm6Oo=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
@ -63,11 +61,7 @@ github.com/RoaringBitmap/roaring v1.2.3 h1:yqreLINqIrX22ErkKI0vY47/ivtJr6n+kMhVO
github.com/RoaringBitmap/roaring v1.2.3/go.mod h1:plvDsJQpxOC5bw8LRteu/MLWHsHez/3y6cubLI4/1yE=
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA=
github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8=
github.com/Stebalien/go-bitfield v0.0.1/go.mod h1:GNjFpasyUVkHMsfEOk8EFLJ9syQ6SI+XWrX9Wf2XH0s=
github.com/VictoriaMetrics/fastcache v1.12.1 h1:i0mICQuojGDL3KblA7wUNlY5lOK6a4bwt3uRKnkZU40=
github.com/VictoriaMetrics/fastcache v1.12.1/go.mod h1:tX04vaqcNoQeGLD+ra5pU5sWkuxnzWhEzLwhP9w653o=
github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow=
github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4=
github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=
@ -89,8 +83,6 @@ github.com/andybalholm/cascadia v1.2.0/go.mod h1:YCyR8vOZT9aZ1CHEd8ap0gMVm2aFgxB
github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA=
github.com/andybalholm/cascadia v1.3.2 h1:3Xi6Dw5lHF15JtdcmAHD3i1+T8plmv7BQ/nsViSLyss=
github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6lUvCFb+h7KvU=
github.com/anyproto/any-sync v0.4.20-0.20240522101738-b44a79d5b782 h1:s+Ig5ks7Bk8lmNp/nLu53pRoqiu7Pb64eQx4HCnKnE4=
github.com/anyproto/any-sync v0.4.20-0.20240522101738-b44a79d5b782/go.mod h1:Shjw2qXQKjsUfu5wVJjLpInSbMfecK8GGe+TOd16jrw=
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=
@ -221,23 +213,7 @@ github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGX
github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
github.com/cockroachdb/errors v1.8.1 h1:A5+txlVZfOqFBDa4mGz2bUWSp0aHElvHX2bKkdbQu+Y=
github.com/cockroachdb/errors v1.8.1/go.mod h1:qGwQn6JmZ+oMjuLwjWzUNqblqk0xl4CVV3SQbGwK7Ac=
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f h1:o/kfcElHqOiXqcou5a3rIlMc7oJbMQkeLk0VQJ7zgqY=
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI=
github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593 h1:aPEJyR4rPBvDmeyi+l/FS/VtA00IWvjeFvjen1m1l1A=
github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593/go.mod h1:6hk1eMY/u5t+Cf18q5lFMUA1Rc+Sm5I6Ra1QuPyxXCo=
github.com/cockroachdb/redact v1.0.8 h1:8QG/764wK+vmEYoOlfobpe12EQcS81ukx/a4hdVMxNw=
github.com/cockroachdb/redact v1.0.8/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
github.com/cockroachdb/sentry-go v0.6.1-cockroachdb.2 h1:IKgmqgMQlVJIZj19CdocBeSfSaiCbEBZGKODaixqtHM=
github.com/cockroachdb/sentry-go v0.6.1-cockroachdb.2/go.mod h1:8BT+cPK6xvFOcRlk0R8eg+OTkcqI6baNH4xAkpiYVvQ=
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo=
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06/go.mod h1:7nc4anLGjupUW/PeY5qiNYsdNXj7zopG+eqsS7To5IQ=
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
github.com/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/YjhQ=
github.com/consensys/bavard v0.1.13/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI=
github.com/consensys/gnark-crypto v0.12.1 h1:lHH39WuuFgVHONRl3J0LRBtuYdQTumFSDtJF7HpyG8M=
github.com/consensys/gnark-crypto v0.12.1/go.mod h1:v2Gy7L/4ZRosZ7Ivs+9SfUDr0f5UlG+EM5t7MPHiLuY=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
@ -256,10 +232,6 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsr
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/crackcomm/go-gitignore v0.0.0-20170627025303-887ab5e44cc3 h1:HVTnpeuvF6Owjd5mniCL8DEXo7uYXdQEmOP4FJbV5tg=
github.com/crackcomm/go-gitignore v0.0.0-20170627025303-887ab5e44cc3/go.mod h1:p1d6YEZWvFzEh4KLyvBcVSnrfNDDvK2zfK/4x2v/4pE=
github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 h1:d28BXYi+wUpz1KBmiF9bWrjEMacUEREV6MBi2ODnrfQ=
github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233/go.mod h1:geZJZH3SzKCqnz5VT0q/DyIG/tvu/dZk+VIfXicupJs=
github.com/crate-crypto/go-kzg-4844 v0.7.0 h1:C0vgZRk4q4EZ/JgPfzuSoxdCq3C3mOZMBShovmncxvA=
github.com/crate-crypto/go-kzg-4844 v0.7.0/go.mod h1:1kMhvPgI0Ky3yIa+9lFySEBUBXkYxeOi8ZF1sYioxhc=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cskr/pubsub v1.0.2 h1:vlOzMhl6PFn60gRlTQQsIfVwaPB/B/8MziK8FhEPt/0=
@ -334,8 +306,6 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.m
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/envoyproxy/protoc-gen-validate v1.0.4 h1:gVPz/FMfvh57HdSJQyvBtF00j8JU4zdyUgIUNhlgg0A=
github.com/envoyproxy/protoc-gen-validate v1.0.4/go.mod h1:qys6tmnRsYrQqIhm2bvKZH4Blx/1gTIZ2UKVY1M+Yew=
github.com/ethereum/c-kzg-4844 v0.4.0 h1:3MS1s4JtA868KpJxroZoepdV0ZKBp3u/O5HcZ7R3nlY=
github.com/ethereum/c-kzg-4844 v0.4.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0=
github.com/ethereum/go-ethereum v1.13.15 h1:U7sSGYGo4SPjP6iNIifNoyIAiNjrmQkz6EwQG+/EZWo=
github.com/ethereum/go-ethereum v1.13.15/go.mod h1:TN8ZiHrdJwSe8Cb6x+p0hs5CxhJZPbqB7hHkaUXcmIU=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
@ -355,8 +325,6 @@ github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7z
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 h1:BAIP2GihuqhwdILrV+7GJel5lyPV3u1+PgzrWLc0TkE=
github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46/go.mod h1:QNpY22eby74jVhqH4WhDLDwxc/vqsern6pW+u2kbkpc=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
@ -422,8 +390,6 @@ github.com/gobwas/ws v1.2.1/go.mod h1:hRKAFb8wOxFROYNsT1bqfWnhX+b5MFeJM9r2ZSwg/K
github.com/goccy/go-graphviz v0.1.2 h1:sWSJ6w13BCm/ZOUTHDVrdvbsxqN8yyzaFcHrH/hQ9Yg=
github.com/goccy/go-graphviz v0.1.2/go.mod h1:pMYpbAqJT10V8dzV1JN/g/wUlG/0imKPzn3ZsrchGCI=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw=
github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
github.com/gogo/googleapis v0.0.0-20180223154316-0cd9801be74a/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
github.com/gogo/googleapis v1.3.1 h1:CzMaKrvF6Qa7XtRii064vKBQiyvmY8H8vG1xa1/W1JA=
@ -520,7 +486,6 @@ github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLe
github.com/google/pprof v0.0.0-20240402174815-29b9bb013b0f h1:f00RU+zOX+B3rLAmMMkzHUF2h1z4DeYR9tTCvEq2REY=
github.com/google/pprof v0.0.0-20240402174815-29b9bb013b0f/go.mod h1:kf6iHlnVGwgKolg33glAes7Yg/8iWP8ukqeldJSO7jw=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
@ -808,10 +773,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c=
github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8=
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
github.com/libp2p/go-addr-util v0.0.1/go.mod h1:4ac6O7n9rIAKB1dnd+s8IbbMXkt+oBpzX4/+RACcnlQ=
@ -1018,8 +979,6 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
@ -1038,8 +997,6 @@ github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJys
github.com/miekg/dns v1.1.43/go.mod h1:+evo5L0630/F6ca/Z9+GAqzhjGyn8/c+TBaOyfEl0V4=
github.com/miekg/dns v1.1.58 h1:ca2Hdkz+cDg/7eNF6V56jjzuZ4aCAE+DbVkILdQWG/4=
github.com/miekg/dns v1.1.58/go.mod h1:Ypv+3b/KadlvW9vJfXOTf300O4UqaHFzFCuHz+rPkBY=
github.com/miguelmota/go-ethereum-hdwallet v0.1.2 h1:mz9LO6V7QCRkLYb0AH17t5R8KeqCe3E+hx9YXpmZeXA=
github.com/miguelmota/go-ethereum-hdwallet v0.1.2/go.mod h1:fdNwFSoBFVBPnU0xpOd6l2ueqsPSH/Gch5kIvSvTGk8=
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ=
github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U=
github.com/minio/sha256-simd v0.0.0-20190328051042-05b4dd3047e5/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U=
@ -1066,9 +1023,6 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iPfkHRY=
github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqkyU72HC5wJ4RlU=
github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@ -1151,8 +1105,6 @@ github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtb
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
@ -1263,8 +1215,6 @@ github.com/quic-go/webtransport-go v0.6.0 h1:CvNsKqc4W2HljHJnoT+rMmbRJybShZ0YPFD
github.com/quic-go/webtransport-go v0.6.0/go.mod h1:9KjU4AEBqEQidGHNDkZrb8CAa1abRaosM2yGOyiikEc=
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
@ -1293,8 +1243,6 @@ github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAm
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU=
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shirou/gopsutil/v3 v3.24.4 h1:dEHgzZXt4LMNm+oYELpzl9YCqV65Yr/6SfrvgRBtXeU=
github.com/shirou/gopsutil/v3 v3.24.4/go.mod h1:lTd2mdiOspcqLgAnr9/nGi71NkeMpWKdmhuxm9GusH8=
github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM=
@ -1373,11 +1321,7 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8=
github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=
github.com/supranational/blst v0.3.11 h1:LyU6FolezeWAhvQk0k6O/d49jqgO52MSDDfYgbeoEm4=
github.com/supranational/blst v0.3.11/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw=
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc=
github.com/tj/assert v0.0.0-20190920132354-ee03d75cd160 h1:NSWpaDaurcAJY7PkL8Xt0PhZE7qpvbZl5ljd8r6U0bI=
github.com/tj/assert v0.0.0-20190920132354-ee03d75cd160/go.mod h1:mZ9/Rh9oLWpLLDRpvE+3b7gP/C2YyLFYxNmcLnPTMe0=
github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU=
@ -2027,8 +1971,6 @@ rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
rsc.io/tmplfunc v0.0.3 h1:53XFQh69AfOa8Tw0Jm7t+GV7KZhOi6jzsCzTtKbMvzU=
rsc.io/tmplfunc v0.0.3/go.mod h1:AG3sTPzElb1Io3Yg4voV9AGZJuleGAwaVRxL9M49PhA=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=
storj.io/drpc v0.0.34 h1:q9zlQKfJ5A7x8NQNFk8x7eKUF78FMhmAbZLnFK+og7I=

View file

@ -42,7 +42,7 @@ func GetInterfacesAddrs() (iAddrs InterfacesAddrs, err error) {
}
func IsLoopBack(interfaces []net.Interface) bool {
return slices.ContainsFunc(interfaces, func(n net.Interface) bool {
return len(interfaces) == 1 && slices.ContainsFunc(interfaces, func(n net.Interface) bool {
return n.Flags&net.FlagLoopback != 0
})
}

File diff suppressed because it is too large Load diff

View file

@ -5,7 +5,6 @@ import (
"github.com/anyproto/any-sync/app"
"github.com/anyproto/anytype-heart/core/syncstatus/p2p"
"github.com/anyproto/anytype-heart/space/clientspace"
"github.com/anyproto/anytype-heart/space/internal/components/aclnotifications"
"github.com/anyproto/anytype-heart/space/internal/components/aclobjectmanager"
@ -38,8 +37,7 @@ type Params struct {
func New(app *app.App, params Params) Loader {
child := app.ChildApp()
child.Register(p2p.NewP2PStatus(params.SpaceId)).
Register(aclindexcleaner.New()).
child.Register(aclindexcleaner.New()).
Register(builder.New()).
Register(spaceloader.New(params.IsPersonal, false)).
Register(aclnotifications.NewAclNotificationSender()).

View file

@ -49,12 +49,11 @@ type localDiscovery struct {
peerId string
port int
peerToPeerStatusUpdater StatusUpdater
notifier Notifier
drpcServer clientserver.ClientServer
manualStart bool
m sync.Mutex
hooks map[Hook]HookCallback
notifier Notifier
drpcServer clientserver.ClientServer
manualStart bool
m sync.Mutex
hooks map[Hook][]HookCallback
}
func (l *localDiscovery) PeerDiscovered(peer DiscoveredPeer, own OwnAddresses) {
@ -87,7 +86,7 @@ func (l *localDiscovery) PeerDiscovered(peer DiscoveredPeer, own OwnAddresses) {
}
func New() LocalDiscovery {
return &localDiscovery{hooks: make(map[Hook]HookCallback, 0)}
return &localDiscovery{hooks: make(map[Hook][]HookCallback, 0)}
}
func (l *localDiscovery) SetNotifier(notifier Notifier) {
@ -128,12 +127,12 @@ func (l *localDiscovery) Name() (name string) {
return CName
}
func (l *localDiscovery) RegisterPeerDiscoveredHook(hook func()) {
l.hooks[PeerDiscovered] = hook
func (l *localDiscovery) RegisterPeerDiscovered(hook func()) {
l.hooks[PeerDiscovered] = append(l.hooks[PeerDiscovered], hook)
}
func (l *localDiscovery) RegisterPeerToPeerImpossibleHook(hook func()) {
l.hooks[PeerToPeerImpossible] = hook
func (l *localDiscovery) RegisterP2PNotPossible(hook func()) {
l.hooks[PeerToPeerImpossible] = append(l.hooks[PeerToPeerImpossible], hook)
}
func (l *localDiscovery) Close(ctx context.Context) (err error) {

View file

@ -15,19 +15,16 @@ import (
"github.com/anyproto/anytype-heart/core/anytype/config"
"github.com/anyproto/anytype-heart/core/event/mock_event"
"github.com/anyproto/anytype-heart/core/syncstatus/p2p"
"github.com/anyproto/anytype-heart/core/syncstatus/p2p/mock_p2p"
"github.com/anyproto/anytype-heart/space/spacecore/clientserver/mock_clientserver"
"github.com/anyproto/anytype-heart/tests/testutil"
)
type fixture struct {
LocalDiscovery
nodeConf *mock_nodeconf.MockService
eventSender *mock_event.MockSender
peerToPeerStatusUpdater *p2p.Observers
clientServer *mock_clientserver.MockClientServer
account *mock_accountservice.MockService
nodeConf *mock_nodeconf.MockService
eventSender *mock_event.MockSender
clientServer *mock_clientserver.MockClientServer
account *mock_accountservice.MockService
}
func newFixture(t *testing.T) *fixture {
@ -35,7 +32,6 @@ func newFixture(t *testing.T) *fixture {
c := &config.Config{}
nodeConf := mock_nodeconf.NewMockService(ctrl)
eventSender := mock_event.NewMockSender(t)
peerToPeerStatusUpdater := p2p.NewObservers()
clientServer := mock_clientserver.NewMockClientServer(t)
accountKeys, err := accountdata.NewRandom()
@ -47,7 +43,6 @@ func newFixture(t *testing.T) *fixture {
a.Register(c).
Register(testutil.PrepareMock(ctx, a, nodeConf)).
Register(testutil.PrepareMock(ctx, a, eventSender)).
Register(peerToPeerStatusUpdater).
Register(account).
Register(testutil.PrepareMock(ctx, a, clientServer))
@ -56,12 +51,11 @@ func newFixture(t *testing.T) *fixture {
assert.Nil(t, err)
f := &fixture{
LocalDiscovery: discovery,
nodeConf: nodeConf,
eventSender: eventSender,
peerToPeerStatusUpdater: peerToPeerStatusUpdater,
clientServer: clientServer,
account: account,
LocalDiscovery: discovery,
nodeConf: nodeConf,
eventSender: eventSender,
clientServer: clientServer,
account: account,
}
return f
}
@ -109,13 +103,9 @@ func TestLocalDiscovery_readAnswers(t *testing.T) {
err := f.Run(context.Background())
assert.Nil(t, err)
status := mock_p2p.NewMockStatusUpdateSender(t)
f.peerToPeerStatusUpdater.AddObserver("spaceId", status)
// when
ld := f.LocalDiscovery.(*localDiscovery)
peerUpdate := make(chan *zeroconf.ServiceEntry)
status.EXPECT().SendPeerUpdate().Return()
go func() {
ld.closeWait.Add(1)
@ -129,7 +119,6 @@ func TestLocalDiscovery_readAnswers(t *testing.T) {
ld.readAnswers(peerUpdate)
// then
status.AssertCalled(t, "CheckPeerStatus")
})
t.Run("readAnswers - send peer update to notifier", func(t *testing.T) {
// given

View file

@ -15,8 +15,6 @@ import (
"go.uber.org/mock/gomock"
"storj.io/drpc"
"github.com/anyproto/anytype-heart/core/syncstatus/p2p"
"github.com/anyproto/anytype-heart/core/syncstatus/p2p/mock_p2p"
"github.com/anyproto/anytype-heart/space/spacecore/peerstore"
)
@ -97,7 +95,6 @@ func Test_fetchResponsiblePeers(t *testing.T) {
f.cm.fetchResponsiblePeers()
// then
f.p2pStatusSender.AssertNotCalled(t, "CheckPeerStatus")
})
t.Run("local peers connected", func(t *testing.T) {
// given
@ -110,7 +107,6 @@ func Test_fetchResponsiblePeers(t *testing.T) {
f.cm.fetchResponsiblePeers()
// then
f.p2pStatusSender.AssertNotCalled(t, "CheckPeerStatus")
})
t.Run("local peer not connected", func(t *testing.T) {
// given
@ -120,11 +116,9 @@ func Test_fetchResponsiblePeers(t *testing.T) {
// when
f.pool.EXPECT().GetOneOf(gomock.Any(), gomock.Any()).Return(newTestPeer("id"), nil)
f.pool.EXPECT().Get(f.cm.ctx, "peerId").Return(nil, fmt.Errorf("error"))
f.p2pStatusSender.EXPECT().SendPeerUpdate().Return()
f.cm.fetchResponsiblePeers()
// then
f.p2pStatusSender.AssertCalled(t, "CheckPeerStatus")
})
}
@ -142,7 +136,6 @@ func Test_getStreamResponsiblePeers(t *testing.T) {
// then
assert.Nil(t, err)
assert.Len(t, peers, 1)
f.p2pStatusSender.AssertNotCalled(t, "CheckPeerStatus")
})
t.Run("local peers connected", func(t *testing.T) {
// given
@ -158,7 +151,6 @@ func Test_getStreamResponsiblePeers(t *testing.T) {
// then
assert.Nil(t, err)
assert.Len(t, peers, 2)
f.p2pStatusSender.AssertNotCalled(t, "CheckPeerStatus")
})
t.Run("local peer not connected", func(t *testing.T) {
// given
@ -169,13 +161,11 @@ func Test_getStreamResponsiblePeers(t *testing.T) {
f.pool.EXPECT().GetOneOf(gomock.Any(), gomock.Any()).Return(newTestPeer("id"), nil)
f.pool.EXPECT().Get(f.cm.ctx, "peerId").Return(nil, fmt.Errorf("error"))
f.pool.EXPECT().Get(f.cm.ctx, "id").Return(newTestPeer("id"), nil)
f.p2pStatusSender.EXPECT().SendPeerUpdate().Return()
peers, err := f.cm.getStreamResponsiblePeers(context.Background())
// then
assert.Nil(t, err)
assert.Len(t, peers, 1)
f.p2pStatusSender.AssertCalled(t, "CheckPeerStatus")
})
}
@ -256,10 +246,9 @@ func (t *testPeer) CloseChan() <-chan struct{} {
}
type fixture struct {
cm *clientPeerManager
pool *mock_pool.MockPool
p2pStatusSender *mock_p2p.MockStatusUpdateSender
store peerstore.PeerStore
cm *clientPeerManager
pool *mock_pool.MockPool
store peerstore.PeerStore
}
func newFixtureManager(t *testing.T, spaceId string) *fixture {
@ -267,21 +256,16 @@ func newFixtureManager(t *testing.T, spaceId string) *fixture {
pool := mock_pool.NewMockPool(ctrl)
provider := &provider{pool: pool}
store := peerstore.New()
observers := p2p.NewObservers()
p2pStatusSender := mock_p2p.NewMockStatusUpdateSender(t)
observers.AddObserver(spaceId, p2pStatusSender)
cm := &clientPeerManager{
p: provider,
spaceId: spaceId,
peerStore: store,
peerToPeerStatusObserver: observers,
watchingPeers: map[string]struct{}{},
ctx: context.Background(),
p: provider,
spaceId: spaceId,
peerStore: store,
watchingPeers: map[string]struct{}{},
ctx: context.Background(),
}
return &fixture{
cm: cm,
pool: pool,
p2pStatusSender: p2pStatusSender,
store: store,
cm: cm,
pool: pool,
store: store,
}
}

View file

@ -28,6 +28,7 @@ import (
"github.com/anyproto/anytype-heart/core/anytype/config"
"github.com/anyproto/anytype-heart/core/block/object/treesyncer"
"github.com/anyproto/anytype-heart/core/peerstatus"
"github.com/anyproto/anytype-heart/core/syncstatus/objectsyncstatus"
"github.com/anyproto/anytype-heart/core/wallet"
"github.com/anyproto/anytype-heart/space/spacecore/clientspaceproto"
@ -238,7 +239,7 @@ func (s *service) Delete(ctx context.Context, spaceID string) (err error) {
func (s *service) loadSpace(ctx context.Context, id string) (value ocache.Object, err error) {
statusService := objectsyncstatus.NewSyncStatusService()
cc, err := s.commonSpace.NewSpace(ctx, id, commonspace.Deps{TreeSyncer: treesyncer.NewTreeSyncer(id), SyncStatus: statusService})
cc, err := s.commonSpace.NewSpace(ctx, id, commonspace.Deps{TreeSyncer: treesyncer.NewTreeSyncer(id), SyncStatus: statusService, PeerStatus: peerstatus.NewP2PStatus(id)})
if err != nil {
return
}