diff --git a/Makefile b/Makefile index f5234926..b5fd9d69 100644 --- a/Makefile +++ b/Makefile @@ -17,14 +17,18 @@ protos-go: @echo 'Generating protobuf packages (Go)...' $(eval P_TIMESTAMP := Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types) $(eval P_STRUCT := Mgoogle/protobuf/struct.proto=github.com/gogo/protobuf/types) - @$(eval P_ACL_CHANGES := Mdata/pb/protos/aclchanges.proto=github.com/anytypeio/go-anytype-infrastructure-experiments/aclchanges/pb) - @$(eval P_THREAD := Mdata/pb/protos/aclchanges.proto=github.com/anytypeio/go-anytype-infrastructure-experiments/thread/pb) - @$(eval P_PLAINTEXT_CHANGES := Mdata/pb/protos/plaintextchanges.proto=github.com/anytypeio/go-anytype-infrastructure-experiments/testutils/testchanges/pb) + @$(eval ROOT_PKG := pkg) + @$(eval P_TREE_STORAGE_PATH_PB := $(ROOT_PKG)/acl/treestorage/pb) + @$(eval P_ACL_CHANGES_PATH_PB := $(ROOT_PKG)/acl/aclchanges/pb) + @$(eval P_PLAINTEXT_CHANGES_PATH_PB := $(ROOT_PKG)/acl/testutils/testchanges/pb) - $(eval PKGMAP := $$(P_TIMESTAMP),$$(P_STRUCT),$$(P_ACL_CHANGES)) - GOGO_NO_UNDERSCORE=1 GOGO_EXPORT_ONEOF_INTERFACE=1 protoc --gogofaster_out=$(PKGMAP):./aclchanges/pb aclchanges/pb/protos/*.*; mv aclchanges/pb/aclchanges/pb/protos/*.go aclchanges/pb; rm -rf aclchanges/pb/aclchanges - $(eval PKGMAP := $$(P_TIMESTAMP),$$(P_STRUCT),$$(P_THREAD)) - GOGO_NO_UNDERSCORE=1 GOGO_EXPORT_ONEOF_INTERFACE=1 protoc --gogofaster_out=$(PKGMAP):./thread/pb thread/pb/protos/*.*; mv thread/pb/thread/pb/protos/*.go thread/pb; rm -rf thread/pb/thread + # TODO: check if PKGMAP should include other proto files + $(eval PKGMAP := $$(P_TIMESTAMP),$$(P_STRUCT)) + GOGO_NO_UNDERSCORE=1 GOGO_EXPORT_ONEOF_INTERFACE=1 protoc --gogofaster_out=$(PKGMAP):./$(P_ACL_CHANGES_PATH_PB) $(P_ACL_CHANGES_PATH_PB)/protos/*.*; mv $(P_ACL_CHANGES_PATH_PB)/$(P_ACL_CHANGES_PATH_PB)/protos/*.go $(P_ACL_CHANGES_PATH_PB); rm -rf $(P_ACL_CHANGES_PATH_PB)/$(ROOT_PKG) + $(eval PKGMAP := $$(P_TIMESTAMP),$$(P_STRUCT)) + GOGO_NO_UNDERSCORE=1 GOGO_EXPORT_ONEOF_INTERFACE=1 protoc --gogofaster_out=$(PKGMAP):./$(P_TREE_STORAGE_PATH_PB) $(P_TREE_STORAGE_PATH_PB)/protos/*.*; mv $(P_TREE_STORAGE_PATH_PB)/$(P_TREE_STORAGE_PATH_PB)/protos/*.go $(P_TREE_STORAGE_PATH_PB); rm -rf $(P_TREE_STORAGE_PATH_PB)/$(ROOT_PKG) + $(eval PKGMAP := $$(P_TIMESTAMP),$$(P_STRUCT)) + GOGO_NO_UNDERSCORE=1 GOGO_EXPORT_ONEOF_INTERFACE=1 protoc --gogofaster_out=$(PKGMAP):./$(P_PLAINTEXT_CHANGES_PATH_PB) $(P_PLAINTEXT_CHANGES_PATH_PB)/protos/*.*; mv $(P_PLAINTEXT_CHANGES_PATH_PB)/$(P_PLAINTEXT_CHANGES_PATH_PB)/protos/*.go $(P_PLAINTEXT_CHANGES_PATH_PB); rm -rf $(P_PLAINTEXT_CHANGES_PATH_PB)/$(ROOT_PKG) build: @$(eval FLAGS := $$(shell govvv -flags -pkg github.com/anytypeio/go-anytype-infrastructure-experiments/app)) diff --git a/go.mod b/go.mod index ff3c2334..8e627098 100644 --- a/go.mod +++ b/go.mod @@ -6,53 +6,38 @@ require ( github.com/awalterschulze/gographviz v0.0.0-20190522210029-fa59802746ab github.com/goccy/go-graphviz v0.0.9 github.com/gogo/protobuf v1.3.2 - github.com/libp2p/go-libp2p-core v0.8.5 + github.com/ipfs/go-cid v0.0.7 github.com/mr-tron/base58 v1.2.0 - github.com/multiformats/go-base32 v0.0.3 - github.com/multiformats/go-multiaddr v0.3.3 - github.com/multiformats/go-multiaddr-dns v0.3.1 github.com/multiformats/go-multibase v0.0.3 github.com/multiformats/go-multihash v0.0.15 github.com/prometheus/common v0.18.0 github.com/stretchr/testify v1.7.0 github.com/textileio/go-threads v1.0.2-0.20210304072541-d0f91da84404 + go.uber.org/zap v1.21.0 gopkg.in/yaml.v3 v3.0.1 ) require ( github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect - github.com/btcsuite/btcd v0.21.0-beta // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect github.com/fogleman/gg v1.3.0 // indirect - github.com/gogo/googleapis v1.3.1 // indirect - github.com/gogo/status v1.1.0 // indirect github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect - github.com/golang/protobuf v1.4.3 // indirect - github.com/grpc-ecosystem/go-grpc-middleware v1.2.1 // indirect - github.com/ipfs/go-cid v0.0.7 // indirect github.com/klauspost/cpuid/v2 v2.0.4 // indirect github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect - github.com/libp2p/go-buffer-pool v0.0.2 // indirect - github.com/libp2p/go-openssl v0.0.7 // indirect github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 // indirect github.com/minio/sha256-simd v1.0.0 // indirect + github.com/multiformats/go-base32 v0.0.3 // indirect github.com/multiformats/go-base36 v0.1.0 // indirect github.com/multiformats/go-varint v0.0.6 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/sirupsen/logrus v1.6.0 // indirect - github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 // indirect go.uber.org/atomic v1.9.0 // indirect go.uber.org/multierr v1.8.0 // indirect - go.uber.org/zap v1.21.0 // indirect golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 // indirect golang.org/x/image v0.0.0-20200119044424-58c23975cae1 // indirect golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect - google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect - google.golang.org/grpc v1.33.2 // indirect - google.golang.org/protobuf v1.25.0 // indirect gopkg.in/alecthomas/kingpin.v2 v2.2.6 // indirect ) diff --git a/go.sum b/go.sum index c650950f..d26fb236 100644 --- a/go.sum +++ b/go.sum @@ -49,6 +49,7 @@ github.com/aws/aws-sdk-go v1.29.15/go.mod h1:1KvfttTE3SPKMpo8g2c6jL3ZKfXtFvKscTg github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g= github.com/benbjohnson/clock v1.0.2/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM= github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM= +github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= @@ -60,7 +61,6 @@ github.com/btcsuite/btcd v0.0.0-20190523000118-16327141da8c/go.mod h1:3J08xEfcug github.com/btcsuite/btcd v0.0.0-20190605094302-a0d1e3e36d50/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI= github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI= github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= -github.com/btcsuite/btcd v0.21.0-beta h1:At9hIZdJW0s9E/fAz28nrz6AmcNlSVucCH796ZteX1M= github.com/btcsuite/btcd v0.21.0-beta/go.mod h1:ZSWyehm27aAuS9bvkATT+Xte3hjHZ+MRgMY/8NJ7K94= github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= github.com/btcsuite/btcutil v0.0.0-20190207003914-4c204d697803/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= @@ -114,7 +114,6 @@ github.com/dgraph-io/badger v1.6.0/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6ps github.com/dgraph-io/badger v1.6.1/go.mod h1:FRmFw3uxvcpa8zG3Rxs0th+hCLIuaQg8HlNV5bjgnuU= github.com/dgraph-io/badger v1.6.2/go.mod h1:JW2yswe3V058sS0kZ2h/AXeDSqFjxnZcRrVH//y2UQE= github.com/dgraph-io/ristretto v0.0.2/go.mod h1:KPxhHT9ZxKefz+PCeOGsrHpl1qZ7i70dGTu2u+Ahh6E= -github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-farm v0.0.0-20190104051053-3adb47b1fb0f/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= @@ -188,7 +187,6 @@ github.com/goccy/go-graphviz v0.0.9 h1:s/FMMJ1Joj6La3S5ApO3Jk2cwM4LpXECC2muFx3IP github.com/goccy/go-graphviz v0.0.9/go.mod h1:wXVsXxmyMQU6TN3zGRttjNn3h+iCAS7xQFC6TlNvLhk= 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= github.com/gogo/googleapis v1.3.1/go.mod h1:d+q1s/xVJxZGKWwC/6UfPIF33J+G1Tq4GYv9Y+Tg/EU= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= @@ -197,7 +195,6 @@ github.com/gogo/protobuf v1.3.0/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXP github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/gogo/status v1.1.0 h1:+eIkrewn5q6b30y+g/BJINVVdi2xH7je5MPJ3ZPK3JA= github.com/gogo/status v1.1.0/go.mod h1:BFv9nrluPLmrS0EmGVvLaPNmRosr9KapBYd5/hpY1WM= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= @@ -223,7 +220,6 @@ github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:W github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= @@ -235,7 +231,6 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= @@ -262,7 +257,6 @@ github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= -github.com/grpc-ecosystem/go-grpc-middleware v1.2.1 h1:V59tBiPuMkySHwJkuq/OYkK0WnOLwCwD3UkTbEMr12U= github.com/grpc-ecosystem/go-grpc-middleware v1.2.1/go.mod h1:EaizFBKfUKtMIF5iaDEhniwNedqGo9FuLFzppDr3uwI= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/grpc-ecosystem/grpc-gateway v1.5.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw= @@ -457,7 +451,6 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/libp2p/go-addr-util v0.0.1/go.mod h1:4ac6O7n9rIAKB1dnd+s8IbbMXkt+oBpzX4/+RACcnlQ= github.com/libp2p/go-addr-util v0.0.2/go.mod h1:Ecd6Fb3yIuLzq4bD7VcywcVSBtefcAwnUISBM3WG15E= github.com/libp2p/go-buffer-pool v0.0.1/go.mod h1:xtyIz9PMobb13WaxR6Zo1Pd1zXJKYg0a8KiIvDp3TzQ= -github.com/libp2p/go-buffer-pool v0.0.2 h1:QNK2iAFa8gjAe1SPz6mHSMuCcjs+X1wlHzeOSqcmlfs= github.com/libp2p/go-buffer-pool v0.0.2/go.mod h1:MvaB6xw5vOrDl8rYZGLFdKAuk/hRoRZd1Vi32+RXyFM= github.com/libp2p/go-cidranger v1.1.0/go.mod h1:KWZTfSr+r9qEo9OkI9/SIEeAtw+NNoU0dXIXt15Okic= github.com/libp2p/go-conn-security v0.0.1/go.mod h1:bGmu51N0KU9IEjX7kl2PQjgZa40JQWnayTvNMgD/vyk= @@ -528,7 +521,6 @@ github.com/libp2p/go-libp2p-core v0.7.0/go.mod h1:FfewUH/YpvWbEB+ZY9AQRQ4TAD8sJB github.com/libp2p/go-libp2p-core v0.8.0/go.mod h1:FfewUH/YpvWbEB+ZY9AQRQ4TAD8sJBt/G1rVvhz5XT8= github.com/libp2p/go-libp2p-core v0.8.1/go.mod h1:FfewUH/YpvWbEB+ZY9AQRQ4TAD8sJBt/G1rVvhz5XT8= github.com/libp2p/go-libp2p-core v0.8.2/go.mod h1:FfewUH/YpvWbEB+ZY9AQRQ4TAD8sJBt/G1rVvhz5XT8= -github.com/libp2p/go-libp2p-core v0.8.5 h1:aEgbIcPGsKy6zYcC+5AJivYFedhYa4sW7mIpWpUaLKw= github.com/libp2p/go-libp2p-core v0.8.5/go.mod h1:FfewUH/YpvWbEB+ZY9AQRQ4TAD8sJBt/G1rVvhz5XT8= github.com/libp2p/go-libp2p-crypto v0.0.1/go.mod h1:yJkNyDmO341d5wwXxDUGO0LykUVT72ImHNUqh5D/dBE= github.com/libp2p/go-libp2p-crypto v0.0.2/go.mod h1:eETI5OUfBnvARGOHrJz2eWNyTUxEGZnBxMcbUjfIj4I= @@ -663,7 +655,6 @@ github.com/libp2p/go-openssl v0.0.2/go.mod h1:v8Zw2ijCSWBQi8Pq5GAixw6DbFfa9u6VIY github.com/libp2p/go-openssl v0.0.3/go.mod h1:unDrJpgy3oFr+rqXsarWifmJuNnJR4chtO1HmaZjggc= github.com/libp2p/go-openssl v0.0.4/go.mod h1:unDrJpgy3oFr+rqXsarWifmJuNnJR4chtO1HmaZjggc= github.com/libp2p/go-openssl v0.0.5/go.mod h1:unDrJpgy3oFr+rqXsarWifmJuNnJR4chtO1HmaZjggc= -github.com/libp2p/go-openssl v0.0.7 h1:eCAzdLejcNVBzP/iZM9vqHnQm+XyCEbSSIheIPRGNsw= github.com/libp2p/go-openssl v0.0.7/go.mod h1:unDrJpgy3oFr+rqXsarWifmJuNnJR4chtO1HmaZjggc= github.com/libp2p/go-reuseport v0.0.1/go.mod h1:jn6RmB1ufnQwl0Q1f+YxAj8isJgDCQzaaxIFYDhcYEA= github.com/libp2p/go-reuseport v0.0.2/go.mod h1:SPD+5RwGC7rcnzngoYC86GjPzjSywuQyMVAheVBD9nQ= @@ -777,7 +768,6 @@ github.com/multiformats/go-multiaddr v0.2.1/go.mod h1:s/Apk6IyxfvMjDafnhJgJ3/46z github.com/multiformats/go-multiaddr v0.2.2/go.mod h1:NtfXiOtHvghW9KojvtySjH5y0u0xW5UouOmQQrn6a3Y= github.com/multiformats/go-multiaddr v0.3.0/go.mod h1:dF9kph9wfJ+3VLAaeBqo9Of8x4fJxp6ggJGteB8HQTI= github.com/multiformats/go-multiaddr v0.3.1/go.mod h1:uPbspcUPd5AfaP6ql3ujFY+QWzmBD8uLLL4bXW0XfGc= -github.com/multiformats/go-multiaddr v0.3.3 h1:vo2OTSAqnENB2rLk79pLtr+uhj+VAzSe3uef5q0lRSs= github.com/multiformats/go-multiaddr v0.3.3/go.mod h1:lCKNGP1EQ1eZ35Za2wlqnabm9xQkib3fyB+nZXHLag0= github.com/multiformats/go-multiaddr-dns v0.0.1/go.mod h1:9kWcqw/Pj6FwxAwW38n/9403szc57zJPs45fmnznu3Q= github.com/multiformats/go-multiaddr-dns v0.0.2/go.mod h1:9kWcqw/Pj6FwxAwW38n/9403szc57zJPs45fmnznu3Q= @@ -961,7 +951,6 @@ github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJ github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:UdhH50NIW0fCiwBSr0co2m7BnFLdv4fQTgdqdJTHFeE= github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA= github.com/spacemonkeygo/openssl v0.0.0-20181017203307-c2dcc5cca94a/go.mod h1:7AyxJNCJ7SBZ1MfVQCWD6Uqo2oubI2Eq2y2eqf+A5r0= -github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 h1:RC6RW7j+1+HkWaX/Yh71Ee5ZHaHYt7ZP4sQgUrm6cDU= github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572/go.mod h1:w0SWMsp6j9O/dk4/ZpIhL+3CkG8ofA2vuv7k+ltqUMc= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= @@ -1048,6 +1037,7 @@ go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.0.0/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= +go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI= go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= @@ -1153,7 +1143,6 @@ golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/net v0.0.0-20210423184538-5f58ad60dda6 h1:0PC75Fz/kyMGhL0e1QnypqK2kQMqKt9csD1GnMJR+Zk= golang.org/x/net v0.0.0-20210423184538-5f58ad60dda6/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -1227,7 +1216,6 @@ golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210317225723-c4fcb01b228e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210426080607-c94f62235c83 h1:kHSDPqCtsHZOg0nVylfTo20DDhE9gG4Y0jn7hKQ0QAM= golang.org/x/sys v0.0.0-20210426080607-c94f62235c83/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -1238,7 +1226,6 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -1275,7 +1262,6 @@ golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.0.0-20180910000450-7ca32eb868bf/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= google.golang.org/api v0.0.0-20181030000543-1d582fd0359e/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= @@ -1296,7 +1282,6 @@ google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRn google.golang.org/genproto v0.0.0-20190530194941-fb225487d101/go.mod h1:z3L6/3dTEVtUr6QSP8miRzeRqwQOioJ9I66odjN4I7s= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= google.golang.org/grpc v1.12.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= @@ -1315,7 +1300,6 @@ google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8 google.golang.org/grpc v1.28.1/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= -google.golang.org/grpc v1.33.2 h1:EQyQC3sa8M+p6Ulc8yy9SWSS2GVwyRc83gAbG8lrl4o= google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= @@ -1325,7 +1309,6 @@ google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzi google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= @@ -1350,8 +1333,8 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/pkg/acl/account/accountdata.go b/pkg/acl/account/accountdata.go index 2c06b02a..a8b1c1b7 100644 --- a/pkg/acl/account/accountdata.go +++ b/pkg/acl/account/accountdata.go @@ -3,7 +3,7 @@ package account import "github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys" type AccountData struct { - Identity string + Identity string // TODO: this is essentially the same as sign key SignKey keys.SigningPrivKey EncKey keys.EncryptionPrivKey } diff --git a/pkg/acl/aclchanges/pb/aclchanges.pb.go b/pkg/acl/aclchanges/pb/aclchanges.pb.go index 39c15341..afbadf76 100644 --- a/pkg/acl/aclchanges/pb/aclchanges.pb.go +++ b/pkg/acl/aclchanges/pb/aclchanges.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: aclchanges/pb/protos/aclchanges.proto +// source: pkg/acl/aclchanges/pb/protos/aclchanges.proto package pb @@ -50,7 +50,7 @@ func (x ACLChangeUserPermissions) String() string { } func (ACLChangeUserPermissions) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_ffc88c8445fc0f24, []int{0, 0} + return fileDescriptor_45c6d2b8abd0fd90, []int{0, 0} } // the element of change tree used to store and internal apply smartBlock history @@ -70,7 +70,7 @@ func (m *ACLChange) Reset() { *m = ACLChange{} } func (m *ACLChange) String() string { return proto.CompactTextString(m) } func (*ACLChange) ProtoMessage() {} func (*ACLChange) Descriptor() ([]byte, []int) { - return fileDescriptor_ffc88c8445fc0f24, []int{0} + return fileDescriptor_45c6d2b8abd0fd90, []int{0} } func (m *ACLChange) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -170,7 +170,7 @@ func (m *ACLChangeACLContentValue) Reset() { *m = ACLChangeACLContentVal func (m *ACLChangeACLContentValue) String() string { return proto.CompactTextString(m) } func (*ACLChangeACLContentValue) ProtoMessage() {} func (*ACLChangeACLContentValue) Descriptor() ([]byte, []int) { - return fileDescriptor_ffc88c8445fc0f24, []int{0, 0} + return fileDescriptor_45c6d2b8abd0fd90, []int{0, 0} } func (m *ACLChangeACLContentValue) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -301,7 +301,7 @@ func (m *ACLChangeACLData) Reset() { *m = ACLChangeACLData{} } func (m *ACLChangeACLData) String() string { return proto.CompactTextString(m) } func (*ACLChangeACLData) ProtoMessage() {} func (*ACLChangeACLData) Descriptor() ([]byte, []int) { - return fileDescriptor_ffc88c8445fc0f24, []int{0, 1} + return fileDescriptor_45c6d2b8abd0fd90, []int{0, 1} } func (m *ACLChangeACLData) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -353,7 +353,7 @@ func (m *ACLChangeACLSnapshot) Reset() { *m = ACLChangeACLSnapshot{} } func (m *ACLChangeACLSnapshot) String() string { return proto.CompactTextString(m) } func (*ACLChangeACLSnapshot) ProtoMessage() {} func (*ACLChangeACLSnapshot) Descriptor() ([]byte, []int) { - return fileDescriptor_ffc88c8445fc0f24, []int{0, 2} + return fileDescriptor_45c6d2b8abd0fd90, []int{0, 2} } func (m *ACLChangeACLSnapshot) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -399,7 +399,7 @@ func (m *ACLChangeACLState) Reset() { *m = ACLChangeACLState{} } func (m *ACLChangeACLState) String() string { return proto.CompactTextString(m) } func (*ACLChangeACLState) ProtoMessage() {} func (*ACLChangeACLState) Descriptor() ([]byte, []int) { - return fileDescriptor_ffc88c8445fc0f24, []int{0, 3} + return fileDescriptor_45c6d2b8abd0fd90, []int{0, 3} } func (m *ACLChangeACLState) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -461,7 +461,7 @@ func (m *ACLChangeUserState) Reset() { *m = ACLChangeUserState{} } func (m *ACLChangeUserState) String() string { return proto.CompactTextString(m) } func (*ACLChangeUserState) ProtoMessage() {} func (*ACLChangeUserState) Descriptor() ([]byte, []int) { - return fileDescriptor_ffc88c8445fc0f24, []int{0, 4} + return fileDescriptor_45c6d2b8abd0fd90, []int{0, 4} } func (m *ACLChangeUserState) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -537,7 +537,7 @@ func (m *ACLChangeUserAdd) Reset() { *m = ACLChangeUserAdd{} } func (m *ACLChangeUserAdd) String() string { return proto.CompactTextString(m) } func (*ACLChangeUserAdd) ProtoMessage() {} func (*ACLChangeUserAdd) Descriptor() ([]byte, []int) { - return fileDescriptor_ffc88c8445fc0f24, []int{0, 5} + return fileDescriptor_45c6d2b8abd0fd90, []int{0, 5} } func (m *ACLChangeUserAdd) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -604,7 +604,7 @@ func (m *ACLChangeUserConfirm) Reset() { *m = ACLChangeUserConfirm{} } func (m *ACLChangeUserConfirm) String() string { return proto.CompactTextString(m) } func (*ACLChangeUserConfirm) ProtoMessage() {} func (*ACLChangeUserConfirm) Descriptor() ([]byte, []int) { - return fileDescriptor_ffc88c8445fc0f24, []int{0, 6} + return fileDescriptor_45c6d2b8abd0fd90, []int{0, 6} } func (m *ACLChangeUserConfirm) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -659,7 +659,7 @@ func (m *ACLChangeUserInvite) Reset() { *m = ACLChangeUserInvite{} } func (m *ACLChangeUserInvite) String() string { return proto.CompactTextString(m) } func (*ACLChangeUserInvite) ProtoMessage() {} func (*ACLChangeUserInvite) Descriptor() ([]byte, []int) { - return fileDescriptor_ffc88c8445fc0f24, []int{0, 7} + return fileDescriptor_45c6d2b8abd0fd90, []int{0, 7} } func (m *ACLChangeUserInvite) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -735,7 +735,7 @@ func (m *ACLChangeUserJoin) Reset() { *m = ACLChangeUserJoin{} } func (m *ACLChangeUserJoin) String() string { return proto.CompactTextString(m) } func (*ACLChangeUserJoin) ProtoMessage() {} func (*ACLChangeUserJoin) Descriptor() ([]byte, []int) { - return fileDescriptor_ffc88c8445fc0f24, []int{0, 8} + return fileDescriptor_45c6d2b8abd0fd90, []int{0, 8} } func (m *ACLChangeUserJoin) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -808,7 +808,7 @@ func (m *ACLChangeUserRemove) Reset() { *m = ACLChangeUserRemove{} } func (m *ACLChangeUserRemove) String() string { return proto.CompactTextString(m) } func (*ACLChangeUserRemove) ProtoMessage() {} func (*ACLChangeUserRemove) Descriptor() ([]byte, []int) { - return fileDescriptor_ffc88c8445fc0f24, []int{0, 9} + return fileDescriptor_45c6d2b8abd0fd90, []int{0, 9} } func (m *ACLChangeUserRemove) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -861,7 +861,7 @@ func (m *ACLChangeReadKeyReplace) Reset() { *m = ACLChangeReadKeyReplace func (m *ACLChangeReadKeyReplace) String() string { return proto.CompactTextString(m) } func (*ACLChangeReadKeyReplace) ProtoMessage() {} func (*ACLChangeReadKeyReplace) Descriptor() ([]byte, []int) { - return fileDescriptor_ffc88c8445fc0f24, []int{0, 10} + return fileDescriptor_45c6d2b8abd0fd90, []int{0, 10} } func (m *ACLChangeReadKeyReplace) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -920,7 +920,7 @@ func (m *ACLChangeUserPermissionChange) Reset() { *m = ACLChangeUserPerm func (m *ACLChangeUserPermissionChange) String() string { return proto.CompactTextString(m) } func (*ACLChangeUserPermissionChange) ProtoMessage() {} func (*ACLChangeUserPermissionChange) Descriptor() ([]byte, []int) { - return fileDescriptor_ffc88c8445fc0f24, []int{0, 11} + return fileDescriptor_45c6d2b8abd0fd90, []int{0, 11} } func (m *ACLChangeUserPermissionChange) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -982,68 +982,69 @@ func init() { } func init() { - proto.RegisterFile("aclchanges/pb/protos/aclchanges.proto", fileDescriptor_ffc88c8445fc0f24) + proto.RegisterFile("pkg/acl/aclchanges/pb/protos/aclchanges.proto", fileDescriptor_45c6d2b8abd0fd90) } -var fileDescriptor_ffc88c8445fc0f24 = []byte{ - // 907 bytes of a gzipped FileDescriptorProto +var fileDescriptor_45c6d2b8abd0fd90 = []byte{ + // 913 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x56, 0x4d, 0x6f, 0xe3, 0x44, - 0x18, 0xf6, 0x24, 0x6d, 0x1d, 0xbf, 0x0e, 0x6d, 0x18, 0xf5, 0x60, 0x79, 0x8b, 0x15, 0x2a, 0x3e, - 0x22, 0x84, 0x52, 0x29, 0x8b, 0xf8, 0x12, 0x12, 0x34, 0x5d, 0x20, 0xa1, 0x1c, 0x56, 0xb3, 0x02, - 0x04, 0x12, 0x87, 0xa9, 0x3d, 0x6c, 0x2d, 0x92, 0xb1, 0xe5, 0x99, 0x54, 0xe4, 0xc2, 0x3f, 0x40, - 0xf0, 0x5b, 0xb8, 0x72, 0xe0, 0xba, 0xc7, 0x3d, 0x72, 0x44, 0xed, 0x3f, 0xe0, 0x17, 0xa0, 0xf9, - 0xb0, 0xe3, 0xa4, 0x71, 0x91, 0x50, 0x25, 0xc4, 0x6d, 0xe6, 0x99, 0xe7, 0x99, 0xbc, 0x1f, 0xcf, - 0x3b, 0x0e, 0xbc, 0x4a, 0xe3, 0x59, 0x7c, 0x49, 0xf9, 0x53, 0x26, 0x4e, 0xf2, 0x8b, 0x93, 0xbc, - 0xc8, 0x64, 0x26, 0x4e, 0x56, 0xe0, 0x50, 0x23, 0xd8, 0xa5, 0x7c, 0x29, 0x97, 0x39, 0x3b, 0xfe, - 0xed, 0x10, 0xbc, 0xd3, 0xb3, 0xcf, 0xcf, 0xf4, 0x29, 0xee, 0x83, 0x2f, 0x0b, 0xc6, 0x26, 0x8c, - 0x26, 0xd3, 0x44, 0x04, 0xa8, 0xdf, 0x1e, 0x78, 0xa4, 0x0e, 0xe1, 0x08, 0x80, 0xc6, 0xb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d, 0x17, 0x6d, 0x9c, 0x0a, 0x00, + 0x00, } func (m *ACLChange) Marshal() (dAtA []byte, err error) { diff --git a/pkg/acl/acltree/acltree.go b/pkg/acl/acltree/acltree.go index fdde9c0c..b1aea86b 100644 --- a/pkg/acl/acltree/acltree.go +++ b/pkg/acl/acltree/acltree.go @@ -2,7 +2,7 @@ package acltree import ( "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/account" - "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/thread" + "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treestorage" "sync" "github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys" @@ -40,7 +40,7 @@ type ACLTree interface { } type aclTree struct { - thread thread.Thread + thread treestorage.TreeStorage accountData *account.AccountData updateListener TreeUpdateListener @@ -58,7 +58,7 @@ type aclTree struct { } func BuildACLTree( - t thread.Thread, + t treestorage.TreeStorage, acc *account.AccountData, listener TreeUpdateListener) (ACLTree, error) { decoder := keys.NewEd25519Decoder() @@ -210,7 +210,7 @@ func (a *aclTree) AddContent(build func(builder ChangeBuilder) error) (*Change, } a.fullTree.AddFast(ch) - err = a.thread.AddRawChange(&thread.RawChange{ + err = a.thread.AddRawChange(&treestorage.RawChange{ Payload: marshalled, Signature: ch.Signature(), Id: ch.Id, diff --git a/pkg/acl/acltree/acltree_test.go b/pkg/acl/acltree/acltree_test.go index 19f3f450..2720dfda 100644 --- a/pkg/acl/acltree/acltree_test.go +++ b/pkg/acl/acltree/acltree_test.go @@ -3,7 +3,7 @@ package acltree import ( "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/account" "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges/pb" - "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/testutils/threadbuilder" + "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/testutils/treestoragebuilder" "testing" "github.com/stretchr/testify/assert" @@ -16,7 +16,7 @@ func (m *mockListener) Update(tree ACLTree) {} func (m *mockListener) Rebuild(tree ACLTree) {} func TestACLTree_UserJoinBuild(t *testing.T) { - thr, err := threadbuilder.NewThreadBuilderWithTestName("userjoinexample.yml") + thr, err := treestoragebuilder.NewTreeStorageBuilderWithTestName("userjoinexample.yml") if err != nil { t.Fatal(err) } @@ -50,7 +50,7 @@ func TestACLTree_UserJoinBuild(t *testing.T) { } func TestACLTree_UserJoinUpdate_Append(t *testing.T) { - thr, err := threadbuilder.NewThreadBuilderWithTestName("userjoinexampleupdate.yml") + thr, err := treestoragebuilder.NewTreeStorageBuilderWithTestName("userjoinexampleupdate.yml") if err != nil { t.Fatal(err) } @@ -99,7 +99,7 @@ func TestACLTree_UserJoinUpdate_Append(t *testing.T) { } func TestACLTree_UserJoinUpdate_Rebuild(t *testing.T) { - thr, err := threadbuilder.NewThreadBuilderWithTestName("userjoinexampleupdate.yml") + thr, err := treestoragebuilder.NewTreeStorageBuilderWithTestName("userjoinexampleupdate.yml") if err != nil { t.Fatal(err) } @@ -149,7 +149,7 @@ func TestACLTree_UserJoinUpdate_Rebuild(t *testing.T) { } func TestACLTree_UserRemoveBuild(t *testing.T) { - thr, err := threadbuilder.NewThreadBuilderWithTestName("userremoveexample.yml") + thr, err := treestoragebuilder.NewTreeStorageBuilderWithTestName("userremoveexample.yml") if err != nil { t.Fatal(err) } @@ -179,7 +179,7 @@ func TestACLTree_UserRemoveBuild(t *testing.T) { } func TestACLTree_UserRemoveBeforeBuild(t *testing.T) { - thr, err := threadbuilder.NewThreadBuilderWithTestName("userremovebeforeexample.yml") + thr, err := treestoragebuilder.NewTreeStorageBuilderWithTestName("userremovebeforeexample.yml") if err != nil { t.Fatal(err) } @@ -210,7 +210,7 @@ func TestACLTree_UserRemoveBeforeBuild(t *testing.T) { } func TestACLTree_InvalidSnapshotBuild(t *testing.T) { - thr, err := threadbuilder.NewThreadBuilderWithTestName("invalidsnapshotexample.yml") + thr, err := treestoragebuilder.NewTreeStorageBuilderWithTestName("invalidsnapshotexample.yml") if err != nil { t.Fatal(err) } @@ -240,7 +240,7 @@ func TestACLTree_InvalidSnapshotBuild(t *testing.T) { } func TestACLTree_ValidSnapshotBuild(t *testing.T) { - thr, err := threadbuilder.NewThreadBuilderWithTestName("validsnapshotexample.yml") + thr, err := treestoragebuilder.NewTreeStorageBuilderWithTestName("validsnapshotexample.yml") if err != nil { t.Fatal(err) } diff --git a/pkg/acl/acltree/acltreebuilder.go b/pkg/acl/acltree/acltreebuilder.go index e1f3a8a4..61e6e6fc 100644 --- a/pkg/acl/acltree/acltreebuilder.go +++ b/pkg/acl/acltree/acltreebuilder.go @@ -2,7 +2,7 @@ package acltree import ( "fmt" - "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/thread" + "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treestorage" "github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys" "github.com/anytypeio/go-anytype-infrastructure-experiments/util/slice" @@ -13,15 +13,15 @@ type aclTreeBuilder struct { identityKeys map[string]keys.SigningPubKey signingPubKeyDecoder keys.SigningPubKeyDecoder tree *Tree - thread thread.Thread + treeStorage treestorage.TreeStorage *changeLoader } -func newACLTreeBuilder(t thread.Thread, decoder keys.SigningPubKeyDecoder) *aclTreeBuilder { +func newACLTreeBuilder(t treestorage.TreeStorage, decoder keys.SigningPubKeyDecoder) *aclTreeBuilder { return &aclTreeBuilder{ signingPubKeyDecoder: decoder, - thread: t, + treeStorage: t, changeLoader: newChangeLoader( t, decoder, @@ -38,8 +38,8 @@ func (tb *aclTreeBuilder) Init() { func (tb *aclTreeBuilder) Build() (*Tree, error) { var headsAndOrphans []string - headsAndOrphans = append(headsAndOrphans, tb.thread.Orphans()...) - headsAndOrphans = append(headsAndOrphans, tb.thread.Heads()...) + headsAndOrphans = append(headsAndOrphans, tb.treeStorage.Orphans()...) + headsAndOrphans = append(headsAndOrphans, tb.treeStorage.Heads()...) aclHeads, err := tb.getACLHeads(headsAndOrphans) if err != nil { @@ -94,7 +94,7 @@ func (tb *aclTreeBuilder) dfsFromStart(heads []string) (buf []*Change, root *Cha possibleRoots = append(possibleRoots, ch) } } - header := tb.thread.Header() + header := tb.treeStorage.Header() for _, r := range possibleRoots { if r.Id == header.FirstChangeId { return buf, r, nil @@ -123,7 +123,7 @@ func (tb *aclTreeBuilder) getACLHeads(heads []string) (aclTreeHeads []string, er } if len(aclTreeHeads) == 0 { - return nil, fmt.Errorf("no usable ACL heads in thread") + return nil, fmt.Errorf("no usable ACL heads in tree storage") } return aclTreeHeads, nil } diff --git a/pkg/acl/acltree/threadutility.go b/pkg/acl/acltree/acltreestorage.go similarity index 80% rename from pkg/acl/acltree/threadutility.go rename to pkg/acl/acltree/acltreestorage.go index 4b4a03e4..d8fd51f5 100644 --- a/pkg/acl/acltree/threadutility.go +++ b/pkg/acl/acltree/acltreestorage.go @@ -2,14 +2,14 @@ package acltree import ( "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/account" - "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/thread" + "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treestorage" "github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys" ) -func BuildThreadWithACL( +func BuildTreeStorageWithACL( acc *account.AccountData, build func(builder ChangeBuilder) error, - create func(change *thread.RawChange) (thread.Thread, error)) (thread.Thread, error) { + create func(change *treestorage.RawChange) (treestorage.TreeStorage, error)) (treestorage.TreeStorage, error) { bld := newChangeBuilder() bld.Init( newACLState(acc.Identity, acc.EncKey, keys.NewEd25519Decoder()), @@ -26,7 +26,7 @@ func BuildThreadWithACL( return nil, err } - rawChange := &thread.RawChange{ + rawChange := &treestorage.RawChange{ Payload: payload, Signature: change.Signature(), Id: change.CID(), diff --git a/pkg/acl/acltree/threadutility_test.go b/pkg/acl/acltree/acltreestorage_test.go similarity index 86% rename from pkg/acl/acltree/threadutility_test.go rename to pkg/acl/acltree/acltreestorage_test.go index 92128dca..dbeb469c 100644 --- a/pkg/acl/acltree/threadutility_test.go +++ b/pkg/acl/acltree/acltreestorage_test.go @@ -4,14 +4,14 @@ import ( "context" "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/account" "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges/pb" - "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/testutils/threadbuilder" - "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/thread" + "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/testutils/treestoragebuilder" + "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treestorage" "github.com/stretchr/testify/assert" "testing" ) func TestBuildThreadWithACL(t *testing.T) { - keychain := threadbuilder.NewKeychain() + keychain := treestoragebuilder.NewKeychain() keychain.AddSigningKey("A") keychain.AddEncryptionKey("A") data := &account.AccountData{ @@ -19,7 +19,7 @@ func TestBuildThreadWithACL(t *testing.T) { SignKey: keychain.SigningKeys["A"], EncKey: keychain.EncryptionKeys["A"], } - thr, err := BuildThreadWithACL( + thr, err := BuildTreeStorageWithACL( data, func(builder ChangeBuilder) error { return builder.UserAdd( @@ -27,7 +27,7 @@ func TestBuildThreadWithACL(t *testing.T) { keychain.EncryptionKeys["A"].GetPublic(), pb.ACLChange_Admin) }, - thread.NewInMemoryThread) + treestorage.NewInMemoryTreeStorage) if err != nil { t.Fatalf("build should not return error") } @@ -38,7 +38,7 @@ func TestBuildThreadWithACL(t *testing.T) { t.Fatalf("thread should have non-empty header") } assert.Equal(t, thr.Heads()[0], thr.Header().FirstChangeId) - assert.NotEmpty(t, thr.ID()) + assert.NotEmpty(t, thr.TreeID()) ch, err := thr.GetChange(context.Background(), thr.Header().FirstChangeId) if err != nil { t.Fatalf("get change should not return error: %v", err) diff --git a/pkg/acl/acltree/change.go b/pkg/acl/acltree/change.go index ba34b032..db1215fe 100644 --- a/pkg/acl/acltree/change.go +++ b/pkg/acl/acltree/change.go @@ -3,7 +3,7 @@ package acltree import ( "fmt" "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges/pb" - "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/thread" + "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treestorage" "github.com/gogo/protobuf/proto" "github.com/textileio/go-threads/crypto/symmetric" @@ -47,7 +47,7 @@ func (ch *Change) IsACLChange() bool { return ch.Content.GetAclData() != nil } -func NewFromRawChange(rawChange *thread.RawChange) (*Change, error) { +func NewFromRawChange(rawChange *treestorage.RawChange) (*Change, error) { unmarshalled := &pb.ACLChange{} err := proto.Unmarshal(rawChange.Payload, unmarshalled) if err != nil { diff --git a/pkg/acl/acltree/changeloader.go b/pkg/acl/acltree/changeloader.go index c0b2699d..afc45be9 100644 --- a/pkg/acl/acltree/changeloader.go +++ b/pkg/acl/acltree/changeloader.go @@ -4,7 +4,7 @@ import ( "context" "fmt" "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges/pb" - "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/thread" + "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treestorage" "time" "github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys" @@ -15,17 +15,17 @@ type changeLoader struct { cache map[string]*Change identityKeys map[string]keys.SigningPubKey signingPubKeyDecoder keys.SigningPubKeyDecoder - thread thread.Thread + treeStorage treestorage.TreeStorage changeCreator func(id string, ch *pb.ACLChange) *Change } func newChangeLoader( - thread thread.Thread, + treeStorage treestorage.TreeStorage, signingPubKeyDecoder keys.SigningPubKeyDecoder, changeCreator func(id string, ch *pb.ACLChange) *Change) *changeLoader { return &changeLoader{ signingPubKeyDecoder: signingPubKeyDecoder, - thread: thread, + treeStorage: treeStorage, changeCreator: changeCreator, } } @@ -45,7 +45,7 @@ func (c *changeLoader) loadChange(id string) (ch *Change, err error) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*30) defer cancel() - change, err := c.thread.GetChange(ctx, id) + change, err := c.treeStorage.GetChange(ctx, id) if err != nil { return nil, err } @@ -73,7 +73,7 @@ func (c *changeLoader) verify(identity string, payload, signature []byte) (isVer return identityKey.Verify(payload, signature) } -func (c *changeLoader) makeVerifiedACLChange(change *thread.RawChange) (aclChange *pb.ACLChange, err error) { +func (c *changeLoader) makeVerifiedACLChange(change *treestorage.RawChange) (aclChange *pb.ACLChange, err error) { aclChange = new(pb.ACLChange) // TODO: think what should we do with such cases, because this can be used by attacker to break our Tree diff --git a/pkg/acl/acltree/treebuilder.go b/pkg/acl/acltree/treebuilder.go index 0e0dbea7..20acd0ed 100644 --- a/pkg/acl/acltree/treebuilder.go +++ b/pkg/acl/acltree/treebuilder.go @@ -3,7 +3,7 @@ package acltree import ( "errors" "fmt" - "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/thread" + "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treestorage" "github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys" //"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/lib/logging" @@ -21,15 +21,15 @@ type treeBuilder struct { identityKeys map[string]keys.SigningPubKey signingPubKeyDecoder keys.SigningPubKeyDecoder tree *Tree - thread thread.Thread + treeStorage treestorage.TreeStorage *changeLoader } -func newTreeBuilder(t thread.Thread, decoder keys.SigningPubKeyDecoder) *treeBuilder { +func newTreeBuilder(t treestorage.TreeStorage, decoder keys.SigningPubKeyDecoder) *treeBuilder { return &treeBuilder{ signingPubKeyDecoder: decoder, - thread: t, + treeStorage: t, changeLoader: newChangeLoader( t, decoder, @@ -46,8 +46,8 @@ func (tb *treeBuilder) Init() { func (tb *treeBuilder) Build(fromStart bool) (*Tree, error) { var headsAndOrphans []string - headsAndOrphans = append(headsAndOrphans, tb.thread.Orphans()...) - headsAndOrphans = append(headsAndOrphans, tb.thread.Heads()...) + headsAndOrphans = append(headsAndOrphans, tb.treeStorage.Orphans()...) + headsAndOrphans = append(headsAndOrphans, tb.treeStorage.Heads()...) if fromStart { if err := tb.buildTreeFromStart(headsAndOrphans); err != nil { @@ -109,7 +109,7 @@ func (tb *treeBuilder) dfsFromStart(heads []string) (buf []*Change, root *Change possibleRoots = append(possibleRoots, ch) } } - header := tb.thread.Header() + header := tb.treeStorage.Header() for _, r := range possibleRoots { if r.Id == header.FirstChangeId { return buf, r, nil diff --git a/pkg/acl/plaintextdocument/document.go b/pkg/acl/example/plaintextdocument/document.go similarity index 94% rename from pkg/acl/plaintextdocument/document.go rename to pkg/acl/example/plaintextdocument/document.go index 1fdc2cfe..48bd9cf3 100644 --- a/pkg/acl/plaintextdocument/document.go +++ b/pkg/acl/example/plaintextdocument/document.go @@ -6,7 +6,7 @@ import ( aclpb "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges/pb" "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/acltree" "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/testutils/testchanges/pb" - "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/thread" + "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treestorage" "github.com/gogo/protobuf/proto" ) @@ -111,12 +111,12 @@ func (p *plainTextDocument) Rebuild(tree acltree.ACLTree) { } func NewInMemoryPlainTextDocument(acc *account.AccountData, text string) (PlainTextDocument, error) { - return NewPlainTextDocument(acc, thread.NewInMemoryThread, text) + return NewPlainTextDocument(acc, treestorage.NewInMemoryTreeStorage, text) } func NewPlainTextDocument( acc *account.AccountData, - create func(change *thread.RawChange) (thread.Thread, error), + create func(change *treestorage.RawChange) (treestorage.TreeStorage, error), text string) (PlainTextDocument, error) { changeBuilder := func(builder acltree.ChangeBuilder) error { err := builder.UserAdd(acc.Identity, acc.EncKey.GetPublic(), aclpb.ACLChange_Admin) @@ -126,7 +126,7 @@ func NewPlainTextDocument( builder.AddChangeContent(createInitialChangeContent(text)) return nil } - t, err := acltree.BuildThreadWithACL( + t, err := acltree.BuildTreeStorageWithACL( acc, changeBuilder, create) diff --git a/pkg/acl/plaintextdocument/document_test.go b/pkg/acl/example/plaintextdocument/document_test.go similarity index 80% rename from pkg/acl/plaintextdocument/document_test.go rename to pkg/acl/example/plaintextdocument/document_test.go index 8b6e0a13..f5e1badb 100644 --- a/pkg/acl/plaintextdocument/document_test.go +++ b/pkg/acl/example/plaintextdocument/document_test.go @@ -2,14 +2,14 @@ package plaintextdocument import ( "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/account" - "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/testutils/threadbuilder" - "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/thread" + "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/testutils/treestoragebuilder" + "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treestorage" "github.com/stretchr/testify/assert" "testing" ) func TestDocument_NewPlainTextDocument(t *testing.T) { - keychain := threadbuilder.NewKeychain() + keychain := treestoragebuilder.NewKeychain() keychain.AddSigningKey("A") keychain.AddEncryptionKey("A") data := &account.AccountData{ @@ -18,7 +18,7 @@ func TestDocument_NewPlainTextDocument(t *testing.T) { EncKey: keychain.EncryptionKeys["A"], } - doc, err := NewPlainTextDocument(data, thread.NewInMemoryThread, "Some text") + doc, err := NewPlainTextDocument(data, treestorage.NewInMemoryTreeStorage, "Some text") if err != nil { t.Fatalf("should not create document with error: %v", err) } @@ -26,7 +26,7 @@ func TestDocument_NewPlainTextDocument(t *testing.T) { } func TestDocument_PlainTextDocument_AddText(t *testing.T) { - keychain := threadbuilder.NewKeychain() + keychain := treestoragebuilder.NewKeychain() keychain.AddSigningKey("A") keychain.AddEncryptionKey("A") data := &account.AccountData{ @@ -35,7 +35,7 @@ func TestDocument_PlainTextDocument_AddText(t *testing.T) { EncKey: keychain.EncryptionKeys["A"], } - doc, err := NewPlainTextDocument(data, thread.NewInMemoryThread, "Some text") + doc, err := NewPlainTextDocument(data, treestorage.NewInMemoryTreeStorage, "Some text") if err != nil { t.Fatalf("should not create document with error: %v", err) } diff --git a/pkg/acl/plaintextdocument/plaintextdocstate.go b/pkg/acl/example/plaintextdocument/plaintextdocstate.go similarity index 100% rename from pkg/acl/plaintextdocument/plaintextdocstate.go rename to pkg/acl/example/plaintextdocument/plaintextdocstate.go diff --git a/pkg/acl/testutils/testchanges/pb/testdocumentchanges.pb.go b/pkg/acl/testutils/testchanges/pb/testdocumentchanges.pb.go index ac95a1b7..08119459 100644 --- a/pkg/acl/testutils/testchanges/pb/testdocumentchanges.pb.go +++ b/pkg/acl/testutils/testchanges/pb/testdocumentchanges.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: data/pb/protos/plaintextchanges.proto +// source: pkg/acl/testutils/testchanges/pb/protos/testdocumentchanges.proto package pb @@ -29,7 +29,7 @@ func (m *PlainTextChange) Reset() { *m = PlainTextChange{} } func (m *PlainTextChange) String() string { return proto.CompactTextString(m) } func (*PlainTextChange) ProtoMessage() {} func (*PlainTextChange) Descriptor() ([]byte, []int) { - return fileDescriptor_970a1e91eeb094c9, []int{0} + return fileDescriptor_c659347c98347eed, []int{0} } func (m *PlainTextChange) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -68,7 +68,7 @@ func (m *PlainTextChangeContent) Reset() { *m = PlainTextChangeContent{} func (m *PlainTextChangeContent) String() string { return proto.CompactTextString(m) } func (*PlainTextChangeContent) ProtoMessage() {} func (*PlainTextChangeContent) Descriptor() ([]byte, []int) { - return fileDescriptor_970a1e91eeb094c9, []int{0, 0} + return fileDescriptor_c659347c98347eed, []int{0, 0} } func (m *PlainTextChangeContent) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -138,7 +138,7 @@ func (m *PlainTextChangeTextAppend) Reset() { *m = PlainTextChangeTextAp func (m *PlainTextChangeTextAppend) String() string { return proto.CompactTextString(m) } func (*PlainTextChangeTextAppend) ProtoMessage() {} func (*PlainTextChangeTextAppend) Descriptor() ([]byte, []int) { - return fileDescriptor_970a1e91eeb094c9, []int{0, 1} + return fileDescriptor_c659347c98347eed, []int{0, 1} } func (m *PlainTextChangeTextAppend) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -182,7 +182,7 @@ func (m *PlainTextChangeSnapshot) Reset() { *m = PlainTextChangeSnapshot func (m *PlainTextChangeSnapshot) String() string { return proto.CompactTextString(m) } func (*PlainTextChangeSnapshot) ProtoMessage() {} func (*PlainTextChangeSnapshot) Descriptor() ([]byte, []int) { - return fileDescriptor_970a1e91eeb094c9, []int{0, 2} + return fileDescriptor_c659347c98347eed, []int{0, 2} } func (m *PlainTextChangeSnapshot) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -227,7 +227,7 @@ func (m *PlainTextChangeData) Reset() { *m = PlainTextChangeData{} } func (m *PlainTextChangeData) String() string { return proto.CompactTextString(m) } func (*PlainTextChangeData) ProtoMessage() {} func (*PlainTextChangeData) Descriptor() ([]byte, []int) { - return fileDescriptor_970a1e91eeb094c9, []int{0, 3} + return fileDescriptor_c659347c98347eed, []int{0, 3} } func (m *PlainTextChangeData) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -279,28 +279,29 @@ func init() { } func init() { - proto.RegisterFile("data/pb/protos/plaintextchanges.proto", fileDescriptor_970a1e91eeb094c9) + proto.RegisterFile("pkg/acl/testutils/testchanges/pb/protos/testdocumentchanges.proto", fileDescriptor_c659347c98347eed) } -var fileDescriptor_970a1e91eeb094c9 = []byte{ - // 259 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4d, 0x49, 0x2c, 0x49, - 0xd4, 0x2f, 0x48, 0xd2, 0x2f, 0x28, 0xca, 0x2f, 0xc9, 0x2f, 0xd6, 0x2f, 0xc8, 0x49, 0xcc, 0xcc, - 0x2b, 0x49, 0xad, 0x28, 0x49, 0xce, 0x48, 0xcc, 0x4b, 0x4f, 0x2d, 0xd6, 0x03, 0x8b, 0x0b, 0xb1, - 0x27, 0xe6, 0x55, 0x96, 0x54, 0x16, 0xa4, 0x2a, 0x6d, 0x62, 0xe2, 0xe2, 0x0f, 0x00, 0xa9, 0x09, - 0x49, 0xad, 0x28, 0x71, 0x06, 0xab, 0x91, 0x8a, 0xe4, 0x62, 0x77, 0xce, 0xcf, 0x2b, 0x49, 0xcd, - 0x2b, 0x11, 0x72, 0xe5, 0xe2, 0x02, 0x69, 0x76, 0x2c, 0x28, 0x48, 0xcd, 0x4b, 0x91, 0x60, 0x54, - 0x60, 0xd4, 0xe0, 0x36, 0x52, 0xd6, 0x83, 0x6a, 0xd6, 0x43, 0xd3, 0xa8, 0x17, 0x02, 0x57, 0xea, - 0xc1, 0x10, 0x84, 0xa4, 0xd1, 0x89, 0x9d, 0x8b, 0xb5, 0x2c, 0x31, 0xa7, 0x34, 0x55, 0x4a, 0x81, - 0x8b, 0x0b, 0xa1, 0x48, 0x48, 0x88, 0x8b, 0x05, 0xa4, 0x08, 0x6c, 0x2e, 0x67, 0x10, 0x98, 0x2d, - 0x25, 0xc7, 0xc5, 0x11, 0x9c, 0x97, 0x58, 0x50, 0x9c, 0x91, 0x5f, 0x82, 0x55, 0xbe, 0x91, 0x91, - 0x8b, 0xc5, 0x25, 0xb1, 0x24, 0x51, 0xc8, 0x8a, 0x8b, 0x3d, 0x19, 0xe2, 0x4a, 0x09, 0x46, 0x05, - 0x66, 0x0d, 0x6e, 0x23, 0x05, 0x9c, 0xee, 0x82, 0xfa, 0x26, 0x08, 0xa6, 0x41, 0xc8, 0x96, 0x8b, - 0xa3, 0x18, 0x6a, 0x89, 0x04, 0x13, 0xd8, 0x53, 0x8a, 0x38, 0x35, 0xc3, 0x5c, 0x13, 0x04, 0xd7, - 0xe2, 0x24, 0x73, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, - 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0x4c, 0x05, 0x49, - 0x49, 0x6c, 0xe0, 0x20, 0x36, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0xd3, 0x1e, 0xb0, 0x6a, 0x8b, - 0x01, 0x00, 0x00, +var fileDescriptor_c659347c98347eed = []byte{ + // 278 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x72, 0x2c, 0xc8, 0x4e, 0xd7, + 0x4f, 0x4c, 0xce, 0xd1, 0x2f, 0x49, 0x2d, 0x2e, 0x29, 0x2d, 0xc9, 0xcc, 0x29, 0x06, 0xb3, 0x92, + 0x33, 0x12, 0xf3, 0xd2, 0x53, 0x8b, 0xf5, 0x0b, 0x92, 0xf4, 0x0b, 0x8a, 0xf2, 0x4b, 0xf2, 0x21, + 0xa2, 0x29, 0xf9, 0xc9, 0xa5, 0xb9, 0xa9, 0x79, 0x30, 0x59, 0x3d, 0xb0, 0x94, 0x10, 0x7b, 0x62, + 0x5e, 0x65, 0x49, 0x65, 0x41, 0xaa, 0xd2, 0x26, 0x26, 0x2e, 0xfe, 0x80, 0x9c, 0xc4, 0xcc, 0xbc, + 0x90, 0xd4, 0x8a, 0x12, 0x67, 0xb0, 0x1a, 0xa9, 0x48, 0x2e, 0x76, 0xe7, 0xfc, 0xbc, 0x92, 0xd4, + 0xbc, 0x12, 0x21, 0x57, 0x2e, 0xae, 0x92, 0xd4, 0x8a, 0x12, 0xc7, 0x82, 0x82, 0xd4, 0xbc, 0x14, + 0x09, 0x46, 0x05, 0x46, 0x0d, 0x6e, 0x23, 0x65, 0x3d, 0xa8, 0x66, 0x3d, 0x34, 0x8d, 0x7a, 0x21, + 0x70, 0xa5, 0x1e, 0x0c, 0x41, 0x48, 0x1a, 0x9d, 0xd8, 0xb9, 0x58, 0xcb, 0x12, 0x73, 0x4a, 0x53, + 0xa5, 0x14, 0xb8, 0xb8, 0x10, 0x8a, 0x84, 0x84, 0xb8, 0x58, 0x40, 0x8a, 0xc0, 0xe6, 0x72, 0x06, + 0x81, 0xd9, 0x52, 0x72, 0x5c, 0x1c, 0xc1, 0x79, 0x89, 0x05, 0xc5, 0x19, 0xf9, 0x25, 0x58, 0xe5, + 0x1b, 0x19, 0xb9, 0x58, 0x5c, 0x12, 0x4b, 0x12, 0x85, 0xac, 0xb8, 0xd8, 0x93, 0x21, 0xae, 0x94, + 0x60, 0x54, 0x60, 0xd6, 0xe0, 0x36, 0x52, 0xc0, 0xe9, 0x2e, 0xa8, 0x6f, 0x82, 0x60, 0x1a, 0x84, + 0x6c, 0xb9, 0x38, 0x8a, 0xa1, 0x96, 0x48, 0x30, 0x81, 0x3d, 0xa5, 0x88, 0x53, 0x33, 0xcc, 0x35, + 0x41, 0x70, 0x2d, 0x4e, 0x32, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, + 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0x10, 0xc5, + 0x54, 0x90, 0x94, 0xc4, 0x06, 0x0e, 0x62, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7a, 0x12, + 0x4d, 0x4e, 0xa7, 0x01, 0x00, 0x00, } func (m *PlainTextChange) Marshal() (dAtA []byte, err error) { @@ -372,7 +373,7 @@ func (m *PlainTextChangeContentValueOfTextAppend) MarshalToSizedBuffer(dAtA []by return 0, err } i -= size - i = encodeVarintPlaintextchanges(dAtA, i, uint64(size)) + i = encodeVarintTestdocumentchanges(dAtA, i, uint64(size)) } i-- dAtA[i] = 0xa @@ -402,7 +403,7 @@ func (m *PlainTextChangeTextAppend) MarshalToSizedBuffer(dAtA []byte) (int, erro if len(m.Text) > 0 { i -= len(m.Text) copy(dAtA[i:], m.Text) - i = encodeVarintPlaintextchanges(dAtA, i, uint64(len(m.Text))) + i = encodeVarintTestdocumentchanges(dAtA, i, uint64(len(m.Text))) i-- dAtA[i] = 0xa } @@ -432,7 +433,7 @@ func (m *PlainTextChangeSnapshot) MarshalToSizedBuffer(dAtA []byte) (int, error) if len(m.Text) > 0 { i -= len(m.Text) copy(dAtA[i:], m.Text) - i = encodeVarintPlaintextchanges(dAtA, i, uint64(len(m.Text))) + i = encodeVarintTestdocumentchanges(dAtA, i, uint64(len(m.Text))) i-- dAtA[i] = 0xa } @@ -466,7 +467,7 @@ func (m *PlainTextChangeData) MarshalToSizedBuffer(dAtA []byte) (int, error) { return 0, err } i -= size - i = encodeVarintPlaintextchanges(dAtA, i, uint64(size)) + i = encodeVarintTestdocumentchanges(dAtA, i, uint64(size)) } i-- dAtA[i] = 0x12 @@ -479,7 +480,7 @@ func (m *PlainTextChangeData) MarshalToSizedBuffer(dAtA []byte) (int, error) { return 0, err } i -= size - i = encodeVarintPlaintextchanges(dAtA, i, uint64(size)) + i = encodeVarintTestdocumentchanges(dAtA, i, uint64(size)) } i-- dAtA[i] = 0xa @@ -488,8 +489,8 @@ func (m *PlainTextChangeData) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func encodeVarintPlaintextchanges(dAtA []byte, offset int, v uint64) int { - offset -= sovPlaintextchanges(v) +func encodeVarintTestdocumentchanges(dAtA []byte, offset int, v uint64) int { + offset -= sovTestdocumentchanges(v) base := offset for v >= 1<<7 { dAtA[offset] = uint8(v&0x7f | 0x80) @@ -528,7 +529,7 @@ func (m *PlainTextChangeContentValueOfTextAppend) Size() (n int) { _ = l if m.TextAppend != nil { l = m.TextAppend.Size() - n += 1 + l + sovPlaintextchanges(uint64(l)) + n += 1 + l + sovTestdocumentchanges(uint64(l)) } return n } @@ -540,7 +541,7 @@ func (m *PlainTextChangeTextAppend) Size() (n int) { _ = l l = len(m.Text) if l > 0 { - n += 1 + l + sovPlaintextchanges(uint64(l)) + n += 1 + l + sovTestdocumentchanges(uint64(l)) } return n } @@ -553,7 +554,7 @@ func (m *PlainTextChangeSnapshot) Size() (n int) { _ = l l = len(m.Text) if l > 0 { - n += 1 + l + sovPlaintextchanges(uint64(l)) + n += 1 + l + sovTestdocumentchanges(uint64(l)) } return n } @@ -567,21 +568,21 @@ func (m *PlainTextChangeData) Size() (n int) { if len(m.Content) > 0 { for _, e := range m.Content { l = e.Size() - n += 1 + l + sovPlaintextchanges(uint64(l)) + n += 1 + l + sovTestdocumentchanges(uint64(l)) } } if m.Snapshot != nil { l = m.Snapshot.Size() - n += 1 + l + sovPlaintextchanges(uint64(l)) + n += 1 + l + sovTestdocumentchanges(uint64(l)) } return n } -func sovPlaintextchanges(x uint64) (n int) { +func sovTestdocumentchanges(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } -func sozPlaintextchanges(x uint64) (n int) { - return sovPlaintextchanges(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +func sozTestdocumentchanges(x uint64) (n int) { + return sovTestdocumentchanges(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } func (m *PlainTextChange) Unmarshal(dAtA []byte) error { l := len(dAtA) @@ -591,7 +592,7 @@ func (m *PlainTextChange) Unmarshal(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowPlaintextchanges + return ErrIntOverflowTestdocumentchanges } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -614,12 +615,12 @@ func (m *PlainTextChange) Unmarshal(dAtA []byte) error { switch fieldNum { default: iNdEx = preIndex - skippy, err := skipPlaintextchanges(dAtA[iNdEx:]) + skippy, err := skipTestdocumentchanges(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthPlaintextchanges + return ErrInvalidLengthTestdocumentchanges } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -641,7 +642,7 @@ func (m *PlainTextChangeContent) Unmarshal(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowPlaintextchanges + return ErrIntOverflowTestdocumentchanges } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -669,7 +670,7 @@ func (m *PlainTextChangeContent) Unmarshal(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowPlaintextchanges + return ErrIntOverflowTestdocumentchanges } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -682,11 +683,11 @@ func (m *PlainTextChangeContent) Unmarshal(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLengthPlaintextchanges + return ErrInvalidLengthTestdocumentchanges } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLengthPlaintextchanges + return ErrInvalidLengthTestdocumentchanges } if postIndex > l { return io.ErrUnexpectedEOF @@ -699,12 +700,12 @@ func (m *PlainTextChangeContent) Unmarshal(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skipPlaintextchanges(dAtA[iNdEx:]) + skippy, err := skipTestdocumentchanges(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthPlaintextchanges + return ErrInvalidLengthTestdocumentchanges } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -726,7 +727,7 @@ func (m *PlainTextChangeTextAppend) Unmarshal(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowPlaintextchanges + return ErrIntOverflowTestdocumentchanges } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -754,7 +755,7 @@ func (m *PlainTextChangeTextAppend) Unmarshal(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowPlaintextchanges + return ErrIntOverflowTestdocumentchanges } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -768,11 +769,11 @@ func (m *PlainTextChangeTextAppend) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthPlaintextchanges + return ErrInvalidLengthTestdocumentchanges } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthPlaintextchanges + return ErrInvalidLengthTestdocumentchanges } if postIndex > l { return io.ErrUnexpectedEOF @@ -781,12 +782,12 @@ func (m *PlainTextChangeTextAppend) Unmarshal(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skipPlaintextchanges(dAtA[iNdEx:]) + skippy, err := skipTestdocumentchanges(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthPlaintextchanges + return ErrInvalidLengthTestdocumentchanges } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -808,7 +809,7 @@ func (m *PlainTextChangeSnapshot) Unmarshal(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowPlaintextchanges + return ErrIntOverflowTestdocumentchanges } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -836,7 +837,7 @@ func (m *PlainTextChangeSnapshot) Unmarshal(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowPlaintextchanges + return ErrIntOverflowTestdocumentchanges } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -850,11 +851,11 @@ func (m *PlainTextChangeSnapshot) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthPlaintextchanges + return ErrInvalidLengthTestdocumentchanges } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthPlaintextchanges + return ErrInvalidLengthTestdocumentchanges } if postIndex > l { return io.ErrUnexpectedEOF @@ -863,12 +864,12 @@ func (m *PlainTextChangeSnapshot) Unmarshal(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skipPlaintextchanges(dAtA[iNdEx:]) + skippy, err := skipTestdocumentchanges(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthPlaintextchanges + return ErrInvalidLengthTestdocumentchanges } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -890,7 +891,7 @@ func (m *PlainTextChangeData) Unmarshal(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowPlaintextchanges + return ErrIntOverflowTestdocumentchanges } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -918,7 +919,7 @@ func (m *PlainTextChangeData) Unmarshal(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowPlaintextchanges + return ErrIntOverflowTestdocumentchanges } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -931,11 +932,11 @@ func (m *PlainTextChangeData) Unmarshal(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLengthPlaintextchanges + return ErrInvalidLengthTestdocumentchanges } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLengthPlaintextchanges + return ErrInvalidLengthTestdocumentchanges } if postIndex > l { return io.ErrUnexpectedEOF @@ -952,7 +953,7 @@ func (m *PlainTextChangeData) Unmarshal(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowPlaintextchanges + return ErrIntOverflowTestdocumentchanges } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -965,11 +966,11 @@ func (m *PlainTextChangeData) Unmarshal(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLengthPlaintextchanges + return ErrInvalidLengthTestdocumentchanges } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLengthPlaintextchanges + return ErrInvalidLengthTestdocumentchanges } if postIndex > l { return io.ErrUnexpectedEOF @@ -983,12 +984,12 @@ func (m *PlainTextChangeData) Unmarshal(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skipPlaintextchanges(dAtA[iNdEx:]) + skippy, err := skipTestdocumentchanges(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthPlaintextchanges + return ErrInvalidLengthTestdocumentchanges } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -1002,7 +1003,7 @@ func (m *PlainTextChangeData) Unmarshal(dAtA []byte) error { } return nil } -func skipPlaintextchanges(dAtA []byte) (n int, err error) { +func skipTestdocumentchanges(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 depth := 0 @@ -1010,7 +1011,7 @@ func skipPlaintextchanges(dAtA []byte) (n int, err error) { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowPlaintextchanges + return 0, ErrIntOverflowTestdocumentchanges } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -1027,7 +1028,7 @@ func skipPlaintextchanges(dAtA []byte) (n int, err error) { case 0: for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowPlaintextchanges + return 0, ErrIntOverflowTestdocumentchanges } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -1043,7 +1044,7 @@ func skipPlaintextchanges(dAtA []byte) (n int, err error) { var length int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowPlaintextchanges + return 0, ErrIntOverflowTestdocumentchanges } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -1056,14 +1057,14 @@ func skipPlaintextchanges(dAtA []byte) (n int, err error) { } } if length < 0 { - return 0, ErrInvalidLengthPlaintextchanges + return 0, ErrInvalidLengthTestdocumentchanges } iNdEx += length case 3: depth++ case 4: if depth == 0 { - return 0, ErrUnexpectedEndOfGroupPlaintextchanges + return 0, ErrUnexpectedEndOfGroupTestdocumentchanges } depth-- case 5: @@ -1072,7 +1073,7 @@ func skipPlaintextchanges(dAtA []byte) (n int, err error) { return 0, fmt.Errorf("proto: illegal wireType %d", wireType) } if iNdEx < 0 { - return 0, ErrInvalidLengthPlaintextchanges + return 0, ErrInvalidLengthTestdocumentchanges } if depth == 0 { return iNdEx, nil @@ -1082,7 +1083,7 @@ func skipPlaintextchanges(dAtA []byte) (n int, err error) { } var ( - ErrInvalidLengthPlaintextchanges = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowPlaintextchanges = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupPlaintextchanges = fmt.Errorf("proto: unexpected end of group") + ErrInvalidLengthTestdocumentchanges = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTestdocumentchanges = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTestdocumentchanges = fmt.Errorf("proto: unexpected end of group") ) diff --git a/pkg/acl/testutils/threadbuilder/keychain.go b/pkg/acl/testutils/treestoragebuilder/keychain.go similarity index 99% rename from pkg/acl/testutils/threadbuilder/keychain.go rename to pkg/acl/testutils/treestoragebuilder/keychain.go index 1596e7d2..1ba1099a 100644 --- a/pkg/acl/testutils/threadbuilder/keychain.go +++ b/pkg/acl/testutils/treestoragebuilder/keychain.go @@ -1,4 +1,4 @@ -package threadbuilder +package treestoragebuilder import ( "hash/fnv" diff --git a/pkg/acl/testutils/threadbuilder/threadbuilder.go b/pkg/acl/testutils/treestoragebuilder/treestoragebuilder.go similarity index 76% rename from pkg/acl/testutils/threadbuilder/threadbuilder.go rename to pkg/acl/testutils/treestoragebuilder/treestoragebuilder.go index 11121251..5ac1faa4 100644 --- a/pkg/acl/testutils/threadbuilder/threadbuilder.go +++ b/pkg/acl/testutils/treestoragebuilder/treestoragebuilder.go @@ -1,4 +1,4 @@ -package threadbuilder +package treestoragebuilder import ( "context" @@ -7,8 +7,8 @@ import ( "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges/pb" testpb "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/testutils/testchanges/pb" "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/testutils/yamltests" - "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/thread" - threadpb "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/thread/pb" + "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treestorage" + storagepb "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treestorage/pb" "github.com/anytypeio/go-anytype-infrastructure-experiments/util/slice" "io/ioutil" "path" @@ -21,7 +21,7 @@ import ( const plainTextDocType uint16 = 1 -type threadChange struct { +type treeChange struct { *pb.ACLChange id string readKey *SymKey @@ -31,63 +31,63 @@ type threadChange struct { } type updateUseCase struct { - changes map[string]*threadChange + changes map[string]*treeChange } -type ThreadBuilder struct { - threadId string - allChanges map[string]*threadChange +type TreeStorageBuilder struct { + treeId string + allChanges map[string]*treeChange updates map[string]*updateUseCase heads []string orphans []string keychain *Keychain - header *threadpb.ThreadHeader + header *storagepb.TreeHeader } -func NewThreadBuilder(keychain *Keychain) *ThreadBuilder { - return &ThreadBuilder{ - allChanges: make(map[string]*threadChange), +func NewTreeStorageBuilder(keychain *Keychain) *TreeStorageBuilder { + return &TreeStorageBuilder{ + allChanges: make(map[string]*treeChange), updates: make(map[string]*updateUseCase), keychain: keychain, } } -func NewThreadBuilderWithTestName(name string) (*ThreadBuilder, error) { +func NewTreeStorageBuilderWithTestName(name string) (*TreeStorageBuilder, error) { filePath := path.Join(yamltests.Path(), name) - return NewThreadBuilderFromFile(filePath) + return NewTreeStorageBuilderFromFile(filePath) } -func NewThreadBuilderFromFile(file string) (*ThreadBuilder, error) { +func NewTreeStorageBuilderFromFile(file string) (*TreeStorageBuilder, error) { content, err := ioutil.ReadFile(file) if err != nil { return nil, err } - thread := YMLThread{} - err = yaml.Unmarshal(content, &thread) + ymlTree := YMLTree{} + err = yaml.Unmarshal(content, &ymlTree) if err != nil { return nil, err } - tb := NewThreadBuilder(NewKeychain()) - tb.Parse(&thread) + tb := NewTreeStorageBuilder(NewKeychain()) + tb.Parse(&ymlTree) return tb, nil } -func (t *ThreadBuilder) ID() string { - return t.threadId +func (t *TreeStorageBuilder) TreeID() string { + return t.treeId } -func (t *ThreadBuilder) GetKeychain() *Keychain { +func (t *TreeStorageBuilder) GetKeychain() *Keychain { return t.keychain } -func (t *ThreadBuilder) Heads() []string { +func (t *TreeStorageBuilder) Heads() []string { return t.heads } -func (t *ThreadBuilder) AddRawChange(change *thread.RawChange) error { +func (t *TreeStorageBuilder) AddRawChange(change *treestorage.RawChange) error { aclChange := new(pb.ACLChange) var err error @@ -108,7 +108,7 @@ func (t *ThreadBuilder) AddRawChange(change *thread.RawChange) error { // get correct signing key signKey := t.keychain.SigningKeysByIdentity[aclChange.Identity] - t.allChanges[change.Id] = &threadChange{ + t.allChanges[change.Id] = &treeChange{ ACLChange: aclChange, id: change.Id, readKey: readKey, @@ -118,11 +118,11 @@ func (t *ThreadBuilder) AddRawChange(change *thread.RawChange) error { return nil } -func (t *ThreadBuilder) AddOrphans(orphans ...string) { +func (t *TreeStorageBuilder) AddOrphans(orphans ...string) { t.orphans = append(t.orphans, orphans...) } -func (t *ThreadBuilder) AddChange(change aclchanges.Change) error { +func (t *TreeStorageBuilder) AddChange(change aclchanges.Change) error { aclChange := change.ProtoChange() var err error var changesData []byte @@ -139,7 +139,7 @@ func (t *ThreadBuilder) AddChange(change aclchanges.Change) error { // get correct signing key signKey := t.keychain.SigningKeysByIdentity[aclChange.Identity] - t.allChanges[change.CID()] = &threadChange{ + t.allChanges[change.CID()] = &treeChange{ ACLChange: aclChange, id: change.CID(), readKey: readKey, @@ -149,25 +149,25 @@ func (t *ThreadBuilder) AddChange(change aclchanges.Change) error { return nil } -func (t *ThreadBuilder) Orphans() []string { +func (t *TreeStorageBuilder) Orphans() []string { return t.orphans } -func (t *ThreadBuilder) SetHeads(heads []string) { +func (t *TreeStorageBuilder) SetHeads(heads []string) { // we should copy here instead of just setting the value t.heads = heads } -func (t *ThreadBuilder) RemoveOrphans(orphans ...string) { +func (t *TreeStorageBuilder) RemoveOrphans(orphans ...string) { t.orphans = slice.Difference(t.orphans, orphans) } -func (t *ThreadBuilder) GetChange(ctx context.Context, recordID string) (*thread.RawChange, error) { +func (t *TreeStorageBuilder) GetChange(ctx context.Context, recordID string) (*treestorage.RawChange, error) { return t.getChange(recordID, t.allChanges), nil } -func (t *ThreadBuilder) GetUpdates(useCase string) []*thread.RawChange { - var res []*thread.RawChange +func (t *TreeStorageBuilder) GetUpdates(useCase string) []*treestorage.RawChange { + var res []*treestorage.RawChange update := t.updates[useCase] for _, ch := range update.changes { rawCh := t.getChange(ch.id, update.changes) @@ -176,11 +176,11 @@ func (t *ThreadBuilder) GetUpdates(useCase string) []*thread.RawChange { return res } -func (t *ThreadBuilder) Header() *threadpb.ThreadHeader { +func (t *TreeStorageBuilder) Header() *storagepb.TreeHeader { return t.header } -func (t *ThreadBuilder) getChange(changeId string, m map[string]*threadChange) *thread.RawChange { +func (t *TreeStorageBuilder) getChange(changeId string, m map[string]*treeChange) *treestorage.RawChange { rec := m[changeId] if rec.changesDataDecrypted != nil { @@ -202,7 +202,7 @@ func (t *ThreadBuilder) getChange(changeId string, m map[string]*threadChange) * panic("should be able to sign final acl message!") } - transformedRec := &thread.RawChange{ + transformedRec := &treestorage.RawChange{ Payload: aclMarshaled, Signature: signature, Id: changeId, @@ -210,25 +210,25 @@ func (t *ThreadBuilder) getChange(changeId string, m map[string]*threadChange) * return transformedRec } -func (t *ThreadBuilder) Parse(thread *YMLThread) { +func (t *TreeStorageBuilder) Parse(tree *YMLTree) { // Just to clarify - we are generating new identities for the ones that // are specified in the yml file, because our identities should be Ed25519 // the same thing is happening for the encryption keys - t.keychain.ParseKeys(&thread.Keys) - t.threadId = t.parseThreadId(thread.Description) - for _, ch := range thread.Changes { + t.keychain.ParseKeys(&tree.Keys) + t.treeId = t.parseTreeId(tree.Description) + for _, ch := range tree.Changes { newChange := t.parseChange(ch) t.allChanges[newChange.id] = newChange } - t.parseGraph(thread) - t.parseOrphans(thread) - t.parseHeader(thread) - t.parseUpdates(thread.Updates) + t.parseGraph(tree) + t.parseOrphans(tree) + t.parseHeader(tree) + t.parseUpdates(tree.Updates) } -func (t *ThreadBuilder) parseChange(ch *Change) *threadChange { - newChange := &threadChange{ +func (t *TreeStorageBuilder) parseChange(ch *Change) *treeChange { + newChange := &treeChange{ id: ch.Id, } k := t.keychain.GetKey(ch.ReadKey).(*SymKey) @@ -274,26 +274,20 @@ func (t *ThreadBuilder) parseChange(ch *Change) *threadChange { return newChange } -func (t *ThreadBuilder) parseThreadId(description *ThreadDescription) string { +func (t *TreeStorageBuilder) parseTreeId(description *TreeDescription) string { if description == nil { - panic("no author in thread") + panic("no author in tree") } - key := t.keychain.SigningKeys[description.Author] - id, err := thread.CreateACLThreadID(key.GetPublic(), plainTextDocType) - if err != nil { - panic(err) - } - - return id.String() + return description.Author + ".tree.id" } -func (t *ThreadBuilder) parseChangeSnapshot(s *PlainTextSnapshot) *testpb.PlainTextChangeSnapshot { +func (t *TreeStorageBuilder) parseChangeSnapshot(s *PlainTextSnapshot) *testpb.PlainTextChangeSnapshot { return &testpb.PlainTextChangeSnapshot{ Text: s.Text, } } -func (t *ThreadBuilder) parseACLSnapshot(s *ACLSnapshot) *pb.ACLChangeACLSnapshot { +func (t *TreeStorageBuilder) parseACLSnapshot(s *ACLSnapshot) *pb.ACLChangeACLSnapshot { newState := &pb.ACLChangeACLState{} for _, state := range s.UserStates { aclUserState := &pb.ACLChangeUserState{} @@ -313,7 +307,7 @@ func (t *ThreadBuilder) parseACLSnapshot(s *ACLSnapshot) *pb.ACLChangeACLSnapsho } } -func (t *ThreadBuilder) parseDocumentChange(ch *PlainTextChange) (convCh *testpb.PlainTextChangeContent) { +func (t *TreeStorageBuilder) parseDocumentChange(ch *PlainTextChange) (convCh *testpb.PlainTextChangeContent) { switch { case ch.TextAppend != nil: convCh = &testpb.PlainTextChangeContent{ @@ -331,7 +325,7 @@ func (t *ThreadBuilder) parseDocumentChange(ch *PlainTextChange) (convCh *testpb return convCh } -func (t *ThreadBuilder) parseACLChange(ch *ACLChange) (convCh *pb.ACLChangeACLContentValue) { +func (t *TreeStorageBuilder) parseACLChange(ch *ACLChange) (convCh *pb.ACLChangeACLContentValue) { switch { case ch.UserAdd != nil: add := ch.UserAdd @@ -452,7 +446,7 @@ func (t *ThreadBuilder) parseACLChange(ch *ACLChange) (convCh *pb.ACLChangeACLCo return convCh } -func (t *ThreadBuilder) encryptReadKeys(keys []string, encKey keys.EncryptionPrivKey) (enc [][]byte) { +func (t *TreeStorageBuilder) encryptReadKeys(keys []string, encKey keys.EncryptionPrivKey) (enc [][]byte) { for _, k := range keys { realKey := t.keychain.GetKey(k).(*SymKey).Key.Bytes() res, err := encKey.GetPublic().Encrypt(realKey) @@ -465,7 +459,7 @@ func (t *ThreadBuilder) encryptReadKeys(keys []string, encKey keys.EncryptionPri return } -func (t *ThreadBuilder) convertPermission(perm string) pb.ACLChangeUserPermissions { +func (t *TreeStorageBuilder) convertPermission(perm string) pb.ACLChangeUserPermissions { switch perm { case "admin": return pb.ACLChange_Admin @@ -478,7 +472,7 @@ func (t *ThreadBuilder) convertPermission(perm string) pb.ACLChangeUserPermissio } } -func (t *ThreadBuilder) traverseFromHeads(f func(t *threadChange) error) error { +func (t *TreeStorageBuilder) traverseFromHeads(f func(t *treeChange) error) error { uniqMap := map[string]struct{}{} stack := make([]string, len(t.orphans), 10) copy(stack, t.orphans) @@ -502,10 +496,10 @@ func (t *ThreadBuilder) traverseFromHeads(f func(t *threadChange) error) error { return nil } -func (t *ThreadBuilder) parseUpdates(updates []*Update) { +func (t *TreeStorageBuilder) parseUpdates(updates []*Update) { for _, update := range updates { useCase := &updateUseCase{ - changes: map[string]*threadChange{}, + changes: map[string]*treeChange{}, } for _, ch := range update.Changes { newChange := t.parseChange(ch) @@ -522,8 +516,8 @@ func (t *ThreadBuilder) parseUpdates(updates []*Update) { } } -func (t *ThreadBuilder) parseGraph(thread *YMLThread) { - for _, node := range thread.Graph { +func (t *TreeStorageBuilder) parseGraph(tree *YMLTree) { + for _, node := range tree.Graph { rec := t.allChanges[node.Id] rec.AclHeadIds = node.ACLHeads rec.TreeHeadIds = node.TreeHeads @@ -531,13 +525,13 @@ func (t *ThreadBuilder) parseGraph(thread *YMLThread) { } } -func (t *ThreadBuilder) parseOrphans(thread *YMLThread) { - t.orphans = thread.Orphans +func (t *TreeStorageBuilder) parseOrphans(tree *YMLTree) { + t.orphans = tree.Orphans } -func (t *ThreadBuilder) parseHeader(thread *YMLThread) { - t.header = &threadpb.ThreadHeader{ - FirstChangeId: thread.Header.FirstChangeId, - IsWorkspace: thread.Header.IsWorkspace, +func (t *TreeStorageBuilder) parseHeader(tree *YMLTree) { + t.header = &storagepb.TreeHeader{ + FirstChangeId: tree.Header.FirstChangeId, + IsWorkspace: tree.Header.IsWorkspace, } } diff --git a/pkg/acl/testutils/threadbuilder/threadbuildergraph.go b/pkg/acl/testutils/treestoragebuilder/treestoragebuildergraph.go similarity index 72% rename from pkg/acl/testutils/threadbuilder/threadbuildergraph.go rename to pkg/acl/testutils/treestoragebuilder/treestoragebuildergraph.go index edb98971..11c6609d 100644 --- a/pkg/acl/testutils/threadbuilder/threadbuildergraph.go +++ b/pkg/acl/testutils/treestoragebuilder/treestoragebuildergraph.go @@ -2,10 +2,10 @@ // +build !linux,!darwin android ios nographviz // +build !amd64 -package threadbuilder +package treestoragebuilder import "fmt" -func (t *ThreadBuilder) Graph() (string, error) { +func (t *TreeStorageBuilder) Graph() (string, error) { return "", fmt.Errorf("building graphs is not supported") } diff --git a/pkg/acl/testutils/threadbuilder/threadbuildergraph_nix.go b/pkg/acl/testutils/treestoragebuilder/treestoragebuildergraph_nix.go similarity index 95% rename from pkg/acl/testutils/threadbuilder/threadbuildergraph_nix.go rename to pkg/acl/testutils/treestoragebuilder/treestoragebuildergraph_nix.go index 2abf3cc9..d856ce3a 100644 --- a/pkg/acl/testutils/threadbuilder/threadbuildergraph_nix.go +++ b/pkg/acl/testutils/treestoragebuilder/treestoragebuildergraph_nix.go @@ -5,7 +5,7 @@ // +build !nographviz // +build amd64 arm64 -package threadbuilder +package treestoragebuilder import ( "fmt" @@ -26,14 +26,14 @@ type EdgeParameters struct { label string } -func (t *ThreadBuilder) Graph() (string, error) { +func (t *TreeStorageBuilder) Graph() (string, error) { // TODO: check updates on https://github.com/goccy/go-graphviz/issues/52 or make a fix yourself to use better library here graph := gographviz.NewGraph() graph.SetName("G") graph.SetDir(true) var nodes = make(map[string]struct{}) - var addNodes = func(r *threadChange) error { + var addNodes = func(r *treeChange) error { // TODO: revisit function after checking style := "solid" @@ -114,7 +114,7 @@ func (t *ThreadBuilder) Graph() (string, error) { return nil } - var addLinks = func(t *threadChange) error { + var addLinks = func(t *treeChange) error { for _, prevId := range t.AclHeadIds { err := createEdge(t.id, prevId, EdgeParameters{ style: "dashed", diff --git a/pkg/acl/testutils/threadbuilder/ymlentities.go b/pkg/acl/testutils/treestoragebuilder/ymlentities.go similarity index 92% rename from pkg/acl/testutils/threadbuilder/ymlentities.go rename to pkg/acl/testutils/treestoragebuilder/ymlentities.go index 34d9cbaf..0a873d99 100644 --- a/pkg/acl/testutils/threadbuilder/ymlentities.go +++ b/pkg/acl/testutils/treestoragebuilder/ymlentities.go @@ -1,6 +1,6 @@ -package threadbuilder +package treestoragebuilder -type ThreadDescription struct { +type TreeDescription struct { Author string `yaml:"author"` } @@ -102,10 +102,10 @@ type Update struct { Graph []*GraphNode `yaml:"graph"` } -type YMLThread struct { - Description *ThreadDescription `yaml:"thread"` - Changes []*Change `yaml:"changes"` - Updates []*Update `yaml:"updates"` +type YMLTree struct { + Description *TreeDescription `yaml:"tree"` + Changes []*Change `yaml:"changes"` + Updates []*Update `yaml:"updates"` Keys Keys `yaml:"keys"` diff --git a/pkg/acl/testutils/threadbuilder/ymlentities_test.go b/pkg/acl/testutils/treestoragebuilder/ymlentities_test.go similarity index 51% rename from pkg/acl/testutils/threadbuilder/ymlentities_test.go rename to pkg/acl/testutils/treestoragebuilder/ymlentities_test.go index a702152b..2ae2e716 100644 --- a/pkg/acl/testutils/threadbuilder/ymlentities_test.go +++ b/pkg/acl/testutils/treestoragebuilder/ymlentities_test.go @@ -1,4 +1,4 @@ -package threadbuilder +package treestoragebuilder import ( "fmt" @@ -6,7 +6,7 @@ import ( ) func Test_YamlParse(t *testing.T) { - tb, _ := NewThreadBuilderWithTestName("userjoinexampleupdate.yml") + tb, _ := NewTreeStorageBuilderWithTestName("userjoinexampleupdate.yml") gr, _ := tb.Graph() fmt.Println(gr) } diff --git a/pkg/acl/testutils/yamltests/invalidsnapshotexample.yml b/pkg/acl/testutils/yamltests/invalidsnapshotexample.yml index e592f7d6..f3eaf00c 100644 --- a/pkg/acl/testutils/yamltests/invalidsnapshotexample.yml +++ b/pkg/acl/testutils/yamltests/invalidsnapshotexample.yml @@ -1,4 +1,4 @@ -thread: +tree: author: A changes: - id: A.1.1 diff --git a/pkg/acl/testutils/yamltests/userjoinexample.yml b/pkg/acl/testutils/yamltests/userjoinexample.yml index 2736d311..ff15f1f6 100644 --- a/pkg/acl/testutils/yamltests/userjoinexample.yml +++ b/pkg/acl/testutils/yamltests/userjoinexample.yml @@ -1,4 +1,4 @@ -thread: +tree: author: A changes: - id: A.1.1 diff --git a/pkg/acl/testutils/yamltests/userjoinexampleupdate.yml b/pkg/acl/testutils/yamltests/userjoinexampleupdate.yml index 04ea7450..1e7d2b01 100644 --- a/pkg/acl/testutils/yamltests/userjoinexampleupdate.yml +++ b/pkg/acl/testutils/yamltests/userjoinexampleupdate.yml @@ -1,4 +1,4 @@ -thread: +tree: author: A changes: - id: A.1.1 diff --git a/pkg/acl/testutils/yamltests/userremovebeforeexample.yml b/pkg/acl/testutils/yamltests/userremovebeforeexample.yml index c19ccaa6..2cd58df4 100644 --- a/pkg/acl/testutils/yamltests/userremovebeforeexample.yml +++ b/pkg/acl/testutils/yamltests/userremovebeforeexample.yml @@ -1,4 +1,4 @@ -thread: +tree: author: A changes: - id: A.1.1 diff --git a/pkg/acl/testutils/yamltests/userremoveexample.yml b/pkg/acl/testutils/yamltests/userremoveexample.yml index bf1dfc57..c3da9fe2 100644 --- a/pkg/acl/testutils/yamltests/userremoveexample.yml +++ b/pkg/acl/testutils/yamltests/userremoveexample.yml @@ -1,4 +1,4 @@ -thread: +tree: author: A changes: - id: A.1.1 diff --git a/pkg/acl/testutils/yamltests/validsnapshotexample.yml b/pkg/acl/testutils/yamltests/validsnapshotexample.yml index 9d5821ec..c75cda0a 100644 --- a/pkg/acl/testutils/yamltests/validsnapshotexample.yml +++ b/pkg/acl/testutils/yamltests/validsnapshotexample.yml @@ -1,4 +1,4 @@ -thread: +tree: author: A changes: - id: A.1.1 diff --git a/pkg/acl/thread/threadid.go b/pkg/acl/thread/threadid.go deleted file mode 100644 index 406f9eea..00000000 --- a/pkg/acl/thread/threadid.go +++ /dev/null @@ -1,72 +0,0 @@ -package thread - -import ( - "crypto/rand" - "encoding/binary" - "fmt" - "github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys" - "hash/fnv" - - "github.com/textileio/go-threads/core/thread" -) - -func CreateACLThreadID(k keys.SigningPubKey, docType uint16) (thread.ID, error) { - rndlen := 32 - buf := make([]byte, 8+rndlen) - - // adding random bytes in the end - _, err := rand.Read(buf[8 : 8+rndlen]) - if err != nil { - panic("random read failed") - } - - keyBytes, err := k.Bytes() - if err != nil { - return thread.Undef, err - } - - hasher := fnv.New64() - hasher.Write(keyBytes) - res := hasher.Sum64() - - // putting hash of the pubkey in the beginning - binary.LittleEndian.PutUint64(buf[:8], res) - - return threadIDFromBytes(docType, buf) -} - -func VerifyACLThreadID(k keys.SigningPubKey, threadId thread.ID) (bool, error) { - bytes := threadId.Bytes() - pubKeyBytes := threadId.Bytes()[len(bytes)-40 : len(bytes)-32] - hash := binary.LittleEndian.Uint64(pubKeyBytes) - - keyBytes, err := k.Bytes() - if err != nil { - return false, err - } - - hasher := fnv.New64() - hasher.Write(keyBytes) - realHash := hasher.Sum64() - - return hash == realHash, nil -} - -func threadIDFromBytes( - docType uint16, - b []byte) (thread.ID, error) { - blen := len(b) - - // two 8 bytes (max) numbers plus num - buf := make([]byte, 2*binary.MaxVarintLen64+blen) - n := binary.PutUvarint(buf, thread.V1) - n += binary.PutUvarint(buf[n:], uint64(thread.AccessControlled)) - n += binary.PutUvarint(buf[n:], uint64(docType)) - - cn := copy(buf[n:], b) - if cn != blen { - return thread.Undef, fmt.Errorf("copy length is inconsistent") - } - - return thread.Cast(buf[:n+blen]) -} diff --git a/pkg/acl/thread/threadid_test.go b/pkg/acl/thread/threadid_test.go deleted file mode 100644 index bddef215..00000000 --- a/pkg/acl/thread/threadid_test.go +++ /dev/null @@ -1,27 +0,0 @@ -package thread - -import ( - "github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys" - "testing" -) - -func TestCreateACLThreadIDVerify(t *testing.T) { - _, pubKey, err := keys.GenerateRandomEd25519KeyPair() - if err != nil { - t.Fatalf("should not return error after generating key pair: %v", err) - } - - thread, err := CreateACLThreadID(pubKey, 1) - if err != nil { - t.Fatalf("should not return error after generating thread: %v", err) - } - - verified, err := VerifyACLThreadID(pubKey, thread) - if err != nil { - t.Fatalf("verification should not return error: %v", err) - } - - if !verified { - t.Fatalf("the thread should be verified") - } -} diff --git a/pkg/acl/thread/inmemory.go b/pkg/acl/treestorage/inmemory.go similarity index 70% rename from pkg/acl/thread/inmemory.go rename to pkg/acl/treestorage/inmemory.go index a1f7e546..07254c40 100644 --- a/pkg/acl/thread/inmemory.go +++ b/pkg/acl/treestorage/inmemory.go @@ -1,19 +1,19 @@ -package thread +package treestorage import ( "context" "fmt" "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges" - "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/thread/pb" + "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treestorage/pb" "github.com/anytypeio/go-anytype-infrastructure-experiments/util/cid" "github.com/anytypeio/go-anytype-infrastructure-experiments/util/slice" "github.com/gogo/protobuf/proto" "sync" ) -type inMemoryThread struct { +type inMemoryTreeStorage struct { id string - header *pb.ThreadHeader + header *pb.TreeHeader heads []string orphans []string changes map[string]*RawChange @@ -21,8 +21,8 @@ type inMemoryThread struct { sync.RWMutex } -func NewInMemoryThread(firstChange *RawChange) (Thread, error) { - header := &pb.ThreadHeader{ +func NewInMemoryTreeStorage(firstChange *RawChange) (TreeStorage, error) { + header := &pb.TreeHeader{ FirstChangeId: firstChange.Id, IsWorkspace: false, } @@ -38,7 +38,7 @@ func NewInMemoryThread(firstChange *RawChange) (Thread, error) { changes := make(map[string]*RawChange) changes[firstChange.Id] = firstChange - return &inMemoryThread{ + return &inMemoryTreeStorage{ id: threadId, header: header, heads: []string{firstChange.Id}, @@ -48,31 +48,31 @@ func NewInMemoryThread(firstChange *RawChange) (Thread, error) { }, nil } -func (t *inMemoryThread) ID() string { +func (t *inMemoryTreeStorage) TreeID() string { t.RLock() defer t.RUnlock() return t.id } -func (t *inMemoryThread) Header() *pb.ThreadHeader { +func (t *inMemoryTreeStorage) Header() *pb.TreeHeader { t.RLock() defer t.RUnlock() return t.header } -func (t *inMemoryThread) Heads() []string { +func (t *inMemoryTreeStorage) Heads() []string { t.RLock() defer t.RUnlock() return t.heads } -func (t *inMemoryThread) Orphans() []string { +func (t *inMemoryTreeStorage) Orphans() []string { t.RLock() defer t.RUnlock() return t.orphans } -func (t *inMemoryThread) SetHeads(heads []string) { +func (t *inMemoryTreeStorage) SetHeads(heads []string) { t.Lock() defer t.Unlock() t.heads = t.heads[:0] @@ -82,19 +82,19 @@ func (t *inMemoryThread) SetHeads(heads []string) { } } -func (t *inMemoryThread) RemoveOrphans(orphans ...string) { +func (t *inMemoryTreeStorage) RemoveOrphans(orphans ...string) { t.Lock() defer t.Unlock() t.orphans = slice.Difference(t.orphans, orphans) } -func (t *inMemoryThread) AddOrphans(orphans ...string) { +func (t *inMemoryTreeStorage) AddOrphans(orphans ...string) { t.Lock() defer t.Unlock() t.orphans = append(t.orphans, orphans...) } -func (t *inMemoryThread) AddRawChange(change *RawChange) error { +func (t *inMemoryTreeStorage) AddRawChange(change *RawChange) error { t.Lock() defer t.Unlock() // TODO: better to do deep copy @@ -102,7 +102,7 @@ func (t *inMemoryThread) AddRawChange(change *RawChange) error { return nil } -func (t *inMemoryThread) AddChange(change aclchanges.Change) error { +func (t *inMemoryTreeStorage) AddChange(change aclchanges.Change) error { t.Lock() defer t.Unlock() signature := change.Signature() @@ -122,7 +122,7 @@ func (t *inMemoryThread) AddChange(change aclchanges.Change) error { return nil } -func (t *inMemoryThread) GetChange(ctx context.Context, changeId string) (*RawChange, error) { +func (t *inMemoryTreeStorage) GetChange(ctx context.Context, changeId string) (*RawChange, error) { t.RLock() defer t.RUnlock() if res, exists := t.changes[changeId]; exists { diff --git a/pkg/acl/thread/models.go b/pkg/acl/treestorage/models.go similarity index 86% rename from pkg/acl/thread/models.go rename to pkg/acl/treestorage/models.go index ec8ae691..aec74c79 100644 --- a/pkg/acl/thread/models.go +++ b/pkg/acl/treestorage/models.go @@ -1,16 +1,16 @@ -package thread +package treestorage import ( "context" "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges" - "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/thread/pb" + "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treestorage/pb" ) // TODO: change methods to have errors as a return parameter, because we will be dealing with a real database -type Thread interface { - ID() string +type TreeStorage interface { + TreeID() string - Header() *pb.ThreadHeader + Header() *pb.TreeHeader Heads() []string Orphans() []string SetHeads(heads []string) diff --git a/pkg/acl/thread/pb/protos/thread.proto b/pkg/acl/treestorage/pb/protos/tree.proto similarity index 88% rename from pkg/acl/thread/pb/protos/thread.proto rename to pkg/acl/treestorage/pb/protos/tree.proto index 97557b25..13cde492 100644 --- a/pkg/acl/thread/pb/protos/thread.proto +++ b/pkg/acl/treestorage/pb/protos/tree.proto @@ -2,7 +2,7 @@ syntax = "proto3"; package anytype; option go_package = "pb"; -message ThreadHeader { +message TreeHeader { string firstChangeId = 1; bool isWorkspace = 2; // TODO: add user identity, signature and nano timestamp diff --git a/pkg/acl/thread/pb/thread.pb.go b/pkg/acl/treestorage/pb/tree.pb.go similarity index 57% rename from pkg/acl/thread/pb/thread.pb.go rename to pkg/acl/treestorage/pb/tree.pb.go index e941b634..2ffbb2d8 100644 --- a/pkg/acl/thread/pb/thread.pb.go +++ b/pkg/acl/treestorage/pb/tree.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: thread/pb/protos/thread.proto +// source: pkg/acl/treestorage/pb/protos/tree.proto package pb @@ -22,23 +22,23 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -type ThreadHeader struct { +type TreeHeader struct { FirstChangeId string `protobuf:"bytes,1,opt,name=firstChangeId,proto3" json:"firstChangeId,omitempty"` IsWorkspace bool `protobuf:"varint,2,opt,name=isWorkspace,proto3" json:"isWorkspace,omitempty"` } -func (m *ThreadHeader) Reset() { *m = ThreadHeader{} } -func (m *ThreadHeader) String() string { return proto.CompactTextString(m) } -func (*ThreadHeader) ProtoMessage() {} -func (*ThreadHeader) Descriptor() ([]byte, []int) { - return fileDescriptor_b228ffbfd554b168, []int{0} +func (m *TreeHeader) Reset() { *m = TreeHeader{} } +func (m *TreeHeader) String() string { return proto.CompactTextString(m) } +func (*TreeHeader) ProtoMessage() {} +func (*TreeHeader) Descriptor() ([]byte, []int) { + return fileDescriptor_170d9fc6619ff7f1, []int{0} } -func (m *ThreadHeader) XXX_Unmarshal(b []byte) error { +func (m *TreeHeader) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *ThreadHeader) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *TreeHeader) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_ThreadHeader.Marshal(b, m, deterministic) + return xxx_messageInfo_TreeHeader.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -48,26 +48,26 @@ func (m *ThreadHeader) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) return b[:n], nil } } -func (m *ThreadHeader) XXX_Merge(src proto.Message) { - xxx_messageInfo_ThreadHeader.Merge(m, src) +func (m *TreeHeader) XXX_Merge(src proto.Message) { + xxx_messageInfo_TreeHeader.Merge(m, src) } -func (m *ThreadHeader) XXX_Size() int { +func (m *TreeHeader) XXX_Size() int { return m.Size() } -func (m *ThreadHeader) XXX_DiscardUnknown() { - xxx_messageInfo_ThreadHeader.DiscardUnknown(m) +func (m *TreeHeader) XXX_DiscardUnknown() { + xxx_messageInfo_TreeHeader.DiscardUnknown(m) } -var xxx_messageInfo_ThreadHeader proto.InternalMessageInfo +var xxx_messageInfo_TreeHeader proto.InternalMessageInfo -func (m *ThreadHeader) GetFirstChangeId() string { +func (m *TreeHeader) GetFirstChangeId() string { if m != nil { return m.FirstChangeId } return "" } -func (m *ThreadHeader) GetIsWorkspace() bool { +func (m *TreeHeader) GetIsWorkspace() bool { if m != nil { return m.IsWorkspace } @@ -75,26 +75,29 @@ func (m *ThreadHeader) GetIsWorkspace() bool { } func init() { - proto.RegisterType((*ThreadHeader)(nil), "anytype.ThreadHeader") + proto.RegisterType((*TreeHeader)(nil), "anytype.TreeHeader") } -func init() { proto.RegisterFile("thread/pb/protos/thread.proto", fileDescriptor_b228ffbfd554b168) } - -var fileDescriptor_b228ffbfd554b168 = []byte{ - // 156 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2d, 0xc9, 0x28, 0x4a, - 0x4d, 0x4c, 0xd1, 0x2f, 0x48, 0xd2, 0x2f, 0x28, 0xca, 0x2f, 0xc9, 0x2f, 0xd6, 0x87, 0x08, 0xe8, - 0x81, 0x79, 0x42, 0xec, 0x89, 0x79, 0x95, 0x25, 0x95, 0x05, 0xa9, 0x4a, 0x61, 0x5c, 0x3c, 0x21, - 0x60, 0x09, 0x8f, 0xd4, 0xc4, 0x94, 0xd4, 0x22, 0x21, 0x15, 0x2e, 0xde, 0xb4, 0xcc, 0xa2, 0xe2, - 0x12, 0xe7, 0x8c, 0xc4, 0xbc, 0xf4, 0x54, 0xcf, 0x14, 0x09, 0x46, 0x05, 0x46, 0x0d, 0xce, 0x20, - 0x54, 0x41, 0x21, 0x05, 0x2e, 0xee, 0xcc, 0xe2, 0xf0, 0xfc, 0xa2, 0xec, 0xe2, 0x82, 0xc4, 0xe4, - 0x54, 0x09, 0x26, 0x05, 0x46, 0x0d, 0x8e, 0x20, 0x64, 0x21, 0x27, 0x99, 0x13, 0x8f, 0xe4, 0x18, - 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, - 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0x62, 0x2a, 0x48, 0x4a, 0x62, 0x03, 0xbb, 0xc2, 0x18, 0x10, - 0x00, 0x00, 0xff, 0xff, 0x2a, 0xae, 0x9d, 0xc2, 0xa6, 0x00, 0x00, 0x00, +func init() { + proto.RegisterFile("pkg/acl/treestorage/pb/protos/tree.proto", fileDescriptor_170d9fc6619ff7f1) } -func (m *ThreadHeader) Marshal() (dAtA []byte, err error) { +var fileDescriptor_170d9fc6619ff7f1 = []byte{ + // 169 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x28, 0xc8, 0x4e, 0xd7, + 0x4f, 0x4c, 0xce, 0xd1, 0x2f, 0x29, 0x4a, 0x4d, 0x2d, 0x2e, 0xc9, 0x2f, 0x4a, 0x4c, 0x4f, 0xd5, + 0x2f, 0x48, 0xd2, 0x2f, 0x28, 0xca, 0x2f, 0xc9, 0x2f, 0x06, 0x8b, 0xea, 0x81, 0xd9, 0x42, 0xec, + 0x89, 0x79, 0x95, 0x25, 0x95, 0x05, 0xa9, 0x4a, 0x21, 0x5c, 0x5c, 0x21, 0x45, 0xa9, 0xa9, 0x1e, + 0xa9, 0x89, 0x29, 0xa9, 0x45, 0x42, 0x2a, 0x5c, 0xbc, 0x69, 0x99, 0x45, 0xc5, 0x25, 0xce, 0x19, + 0x89, 0x79, 0xe9, 0xa9, 0x9e, 0x29, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0x9c, 0x41, 0xa8, 0x82, 0x42, + 0x0a, 0x5c, 0xdc, 0x99, 0xc5, 0xe1, 0xf9, 0x45, 0xd9, 0xc5, 0x05, 0x89, 0xc9, 0xa9, 0x12, 0x4c, + 0x0a, 0x8c, 0x1a, 0x1c, 0x41, 0xc8, 0x42, 0x4e, 0x32, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, + 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, + 0x2c, 0xc7, 0x10, 0xc5, 0x54, 0x90, 0x94, 0xc4, 0x06, 0x76, 0x83, 0x31, 0x20, 0x00, 0x00, 0xff, + 0xff, 0x25, 0xee, 0xe5, 0x98, 0xaf, 0x00, 0x00, 0x00, +} + +func (m *TreeHeader) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -104,12 +107,12 @@ func (m *ThreadHeader) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *ThreadHeader) MarshalTo(dAtA []byte) (int, error) { +func (m *TreeHeader) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *ThreadHeader) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *TreeHeader) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -127,15 +130,15 @@ func (m *ThreadHeader) MarshalToSizedBuffer(dAtA []byte) (int, error) { if len(m.FirstChangeId) > 0 { i -= len(m.FirstChangeId) copy(dAtA[i:], m.FirstChangeId) - i = encodeVarintThread(dAtA, i, uint64(len(m.FirstChangeId))) + i = encodeVarintTree(dAtA, i, uint64(len(m.FirstChangeId))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func encodeVarintThread(dAtA []byte, offset int, v uint64) int { - offset -= sovThread(v) +func encodeVarintTree(dAtA []byte, offset int, v uint64) int { + offset -= sovTree(v) base := offset for v >= 1<<7 { dAtA[offset] = uint8(v&0x7f | 0x80) @@ -145,7 +148,7 @@ func encodeVarintThread(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *ThreadHeader) Size() (n int) { +func (m *TreeHeader) Size() (n int) { if m == nil { return 0 } @@ -153,7 +156,7 @@ func (m *ThreadHeader) Size() (n int) { _ = l l = len(m.FirstChangeId) if l > 0 { - n += 1 + l + sovThread(uint64(l)) + n += 1 + l + sovTree(uint64(l)) } if m.IsWorkspace { n += 2 @@ -161,13 +164,13 @@ func (m *ThreadHeader) Size() (n int) { return n } -func sovThread(x uint64) (n int) { +func sovTree(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } -func sozThread(x uint64) (n int) { - return sovThread(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +func sozTree(x uint64) (n int) { + return sovTree(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *ThreadHeader) Unmarshal(dAtA []byte) error { +func (m *TreeHeader) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -175,7 +178,7 @@ func (m *ThreadHeader) Unmarshal(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowThread + return ErrIntOverflowTree } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -190,10 +193,10 @@ func (m *ThreadHeader) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: ThreadHeader: wiretype end group for non-group") + return fmt.Errorf("proto: TreeHeader: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: ThreadHeader: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: TreeHeader: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -203,7 +206,7 @@ func (m *ThreadHeader) Unmarshal(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowThread + return ErrIntOverflowTree } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -217,11 +220,11 @@ func (m *ThreadHeader) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthThread + return ErrInvalidLengthTree } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthThread + return ErrInvalidLengthTree } if postIndex > l { return io.ErrUnexpectedEOF @@ -235,7 +238,7 @@ func (m *ThreadHeader) Unmarshal(dAtA []byte) error { var v int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowThread + return ErrIntOverflowTree } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -250,12 +253,12 @@ func (m *ThreadHeader) Unmarshal(dAtA []byte) error { m.IsWorkspace = bool(v != 0) default: iNdEx = preIndex - skippy, err := skipThread(dAtA[iNdEx:]) + skippy, err := skipTree(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthThread + return ErrInvalidLengthTree } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -269,7 +272,7 @@ func (m *ThreadHeader) Unmarshal(dAtA []byte) error { } return nil } -func skipThread(dAtA []byte) (n int, err error) { +func skipTree(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 depth := 0 @@ -277,7 +280,7 @@ func skipThread(dAtA []byte) (n int, err error) { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowThread + return 0, ErrIntOverflowTree } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -294,7 +297,7 @@ func skipThread(dAtA []byte) (n int, err error) { case 0: for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowThread + return 0, ErrIntOverflowTree } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -310,7 +313,7 @@ func skipThread(dAtA []byte) (n int, err error) { var length int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowThread + return 0, ErrIntOverflowTree } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -323,14 +326,14 @@ func skipThread(dAtA []byte) (n int, err error) { } } if length < 0 { - return 0, ErrInvalidLengthThread + return 0, ErrInvalidLengthTree } iNdEx += length case 3: depth++ case 4: if depth == 0 { - return 0, ErrUnexpectedEndOfGroupThread + return 0, ErrUnexpectedEndOfGroupTree } depth-- case 5: @@ -339,7 +342,7 @@ func skipThread(dAtA []byte) (n int, err error) { return 0, fmt.Errorf("proto: illegal wireType %d", wireType) } if iNdEx < 0 { - return 0, ErrInvalidLengthThread + return 0, ErrInvalidLengthTree } if depth == 0 { return iNdEx, nil @@ -349,7 +352,7 @@ func skipThread(dAtA []byte) (n int, err error) { } var ( - ErrInvalidLengthThread = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowThread = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupThread = fmt.Errorf("proto: unexpected end of group") + ErrInvalidLengthTree = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTree = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTree = fmt.Errorf("proto: unexpected end of group") ) diff --git a/util/keys/symmetric.go b/util/keys/symmetric.go new file mode 100644 index 00000000..83ea9eb3 --- /dev/null +++ b/util/keys/symmetric.go @@ -0,0 +1,139 @@ +package keys + +import ( + "crypto/aes" + "crypto/cipher" + "crypto/rand" + "fmt" + + mbase "github.com/multiformats/go-multibase" +) + +const ( + // NonceBytes is the length of GCM nonce. + NonceBytes = 12 + + // KeyBytes is the length of GCM key. + KeyBytes = 32 +) + +// Key is a wrapper for a symmetric key. +type key struct { + raw []byte +} + +func (k *key) Equals(k2 Key) bool { + otherKey, ok := k2.(*key) + if !ok { + return false + } + + otherRaw := otherKey.raw + keyRaw := k.raw + + if len(keyRaw) != len(otherRaw) { + return false + } + + for i := 0; i < len(keyRaw); i++ { + if keyRaw[i] != otherRaw[i] { + return false + } + } + return true +} + +func (k *key) Raw() ([]byte, error) { + return k.raw, nil +} + +// NewRandom returns a random key. +func NewRandom() (Key, error) { + raw := make([]byte, KeyBytes) + if _, err := rand.Read(raw); err != nil { + return nil, err + } + return &key{raw: raw}, nil +} + +// New returns Key if err is nil and panics otherwise. +func New() Key { + k, err := NewRandom() + if err != nil { + panic(err) + } + return k +} + +// FromBytes returns a key by decoding bytes. +func FromBytes(k []byte) (Key, error) { + if len(k) != KeyBytes { + return nil, fmt.Errorf("invalid key") + } + return &key{raw: k}, nil +} + +// FromString returns a key by decoding a base32-encoded string. +func FromString(k string) (Key, error) { + _, b, err := mbase.Decode(k) + if err != nil { + return nil, err + } + return FromBytes(b) +} + +// Bytes returns raw key bytes. +func (k *key) Bytes() []byte { + return k.raw +} + +// MarshalBinary implements BinaryMarshaler. +func (k *key) MarshalBinary() ([]byte, error) { + return k.raw, nil +} + +// String returns the base32-encoded string representation of raw key bytes. +func (k *key) String() string { + str, err := mbase.Encode(mbase.Base32, k.raw) + if err != nil { + panic("should not error with hardcoded mbase: " + err.Error()) + } + return str +} + +// Encrypt performs AES-256 GCM encryption on plaintext. +func (k *key) Encrypt(plaintext []byte) ([]byte, error) { + block, err := aes.NewCipher(k.raw[:KeyBytes]) + if err != nil { + return nil, err + } + aesgcm, err := cipher.NewGCM(block) + if err != nil { + return nil, err + } + nonce := make([]byte, NonceBytes) + if _, err := rand.Read(nonce); err != nil { + return nil, err + } + ciphertext := aesgcm.Seal(nil, nonce, plaintext, nil) + ciphertext = append(nonce[:], ciphertext...) + return ciphertext, nil +} + +// Decrypt uses key to perform AES-256 GCM decryption on ciphertext. +func (k *key) Decrypt(ciphertext []byte) ([]byte, error) { + block, err := aes.NewCipher(k.raw[:KeyBytes]) + if err != nil { + return nil, err + } + aesgcm, err := cipher.NewGCM(block) + if err != nil { + return nil, err + } + nonce := ciphertext[:NonceBytes] + plain, err := aesgcm.Open(nil, nonce, ciphertext[NonceBytes:], nil) + if err != nil { + return nil, err + } + return plain, nil +}