mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-11 10:18:28 +09:00
Merge branch 'master' of github.com:anytypeio/go-anytype-middleware into feat-df4akx-template
This commit is contained in:
commit
a904562878
19 changed files with 430 additions and 386 deletions
|
@ -1,6 +1,13 @@
|
|||
FROM cimg/base:2020.01
|
||||
FROM alpine:3.13
|
||||
|
||||
RUN apk add --no-cache \
|
||||
wget \
|
||||
openssl \
|
||||
ca-certificates \
|
||||
libc6-compat \
|
||||
libstdc++
|
||||
|
||||
COPY ./dist/server /bin/server
|
||||
COPY .circleci/testdata /testdata
|
||||
|
||||
ENTRYPOINT ["/bin/server"]
|
||||
ENTRYPOINT ["/bin/server"]
|
|
@ -552,6 +552,11 @@ workflows:
|
|||
- build-lib-darwin-windows:
|
||||
requires:
|
||||
- unit-test
|
||||
filters:
|
||||
branches:
|
||||
only: master
|
||||
tags:
|
||||
only: /.*/
|
||||
- build-lib-linux:
|
||||
requires:
|
||||
- unit-test
|
||||
|
|
|
@ -8,7 +8,6 @@ function stop_and_cleanup() {
|
|||
docker-compose stop -t 1
|
||||
docker-compose logs --no-color --tail="all" > /tmp/docker_nodes.log 2>&1
|
||||
docker-compose run --rm test python ./utils/send_results.py --build-id=${CIRCLE_BUILD_NUM} --build-url=${CIRCLE_BUILD_URL} --git-branch=${CIRCLE_BRANCH} --exit-code=${EXIT_CODE}
|
||||
docker-compose down
|
||||
}
|
||||
|
||||
function start_test() {
|
||||
|
@ -20,10 +19,19 @@ trap stop_and_cleanup SIGINT SIGTERM EXIT
|
|||
docker-compose pull test
|
||||
|
||||
TAG="latest"
|
||||
if [ "${CIRCLE_SHA1}" != "" ]; then
|
||||
TAG=${CIRCLE_SHA1}
|
||||
if [ "${BASE_TAG}" == "" ]; then
|
||||
BASE_TAG="master"
|
||||
fi
|
||||
|
||||
export TAG
|
||||
if [ "${CIRCLE_SHA1}" != "" ]; then
|
||||
TAG=${CIRCLE_SHA1}
|
||||
if [ "${BASE_TAG}" == "latest" ]; then
|
||||
BASE_TAG=${CIRCLE_SHA1}
|
||||
fi
|
||||
fi
|
||||
|
||||
start_test
|
||||
echo ${BASE_TAG}
|
||||
export TAG
|
||||
export BASE_TAG
|
||||
|
||||
start_test
|
|
@ -41,6 +41,11 @@ func Command(cmd *C.char, data unsafe.Pointer, dataLen C.int, callback C.proxyFu
|
|||
})
|
||||
}
|
||||
|
||||
//export Shutdown
|
||||
func Shutdown() {
|
||||
service.Shutdown(nil)
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
}
|
||||
|
|
|
@ -204,6 +204,10 @@ static napi_value GetMethod(napi_env env, napi_callback_info info) {
|
|||
}
|
||||
|
||||
static void addon_is_unloading(napi_env env, void * data, void * hint) {
|
||||
printf("native addon is unloading\n");
|
||||
SetEventHandler(NULL, NULL);
|
||||
Shutdown();
|
||||
|
||||
AddonData * addon_data = (AddonData * ) data;
|
||||
assert(napi_delete_reference(env,
|
||||
addon_data->thread_item_constructor) == napi_ok);
|
||||
|
@ -352,6 +356,8 @@ NAPI_MODULE_INIT( /*napi_env env, napi_value exports*/ ) {
|
|||
AddonData * addon_data =
|
||||
memset(malloc(sizeof( * addon_data)), 0, sizeof( * addon_data));
|
||||
|
||||
printf("native addon init\n");
|
||||
|
||||
// Attach the addon data to the exports object to ensure that they are
|
||||
// destroyed together.
|
||||
assert(napi_wrap(env,
|
||||
|
|
97
cmd/cli/cafe.go
Normal file
97
cmd/cli/cafe.go
Normal file
|
@ -0,0 +1,97 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
core2 "github.com/anytypeio/go-anytype-middleware/pkg/lib/core"
|
||||
"github.com/anytypeio/go-anytype-middleware/pkg/lib/wallet"
|
||||
"github.com/anytypeio/go-anytype-middleware/util/console"
|
||||
"github.com/spf13/cobra"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
var cafeCmd = &cobra.Command{
|
||||
Use: "cafe",
|
||||
Short: "Cafe-specific commands",
|
||||
}
|
||||
|
||||
var (
|
||||
mnemonic string
|
||||
account string
|
||||
)
|
||||
|
||||
var findProfiles = &cobra.Command{
|
||||
Use: "findprofiles",
|
||||
Short: "Find profiles by mnemonic or accountId",
|
||||
Run: func(c *cobra.Command, args []string) {
|
||||
var (
|
||||
appMnemonic string
|
||||
appAccount wallet.Keypair
|
||||
accountsToFind []string
|
||||
err error
|
||||
)
|
||||
|
||||
if mnemonic != "" {
|
||||
for i:=0; i<10; i++ {
|
||||
ac, err := core2.WalletAccountAt(mnemonic, i, "")
|
||||
if err != nil {
|
||||
console.Fatal("failed to get account from provided mnemonic: %s", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
accountsToFind = append(accountsToFind, ac.Address())
|
||||
}
|
||||
} else if account != "" {
|
||||
accountsToFind = []string{account}
|
||||
} else {
|
||||
console.Fatal("no mnemonic or account provided")
|
||||
return
|
||||
}
|
||||
// create temp wallet in order to do requests to cafe
|
||||
appMnemonic, err = core2.WalletGenerateMnemonic(12)
|
||||
appAccount, err = core2.WalletAccountAt(appMnemonic, 0, "")
|
||||
|
||||
rootPath, err := ioutil.TempDir(os.TempDir(), "anytype_*")
|
||||
rawSeed, err := appAccount.Raw()
|
||||
|
||||
err = core2.WalletInitRepo(rootPath, rawSeed)
|
||||
|
||||
var opts = []core2.ServiceOption{core2.WithRootPathAndAccount(rootPath, appAccount.Address())}
|
||||
a, _ := core2.New(opts...)
|
||||
err = a.Start()
|
||||
if err != nil {
|
||||
fmt.Println("failed to start: "+ err.Error())
|
||||
return
|
||||
}
|
||||
var found bool
|
||||
var ch = make(chan core2.Profile)
|
||||
closeCh := make(chan struct{})
|
||||
go func() {
|
||||
defer close(closeCh)
|
||||
select {
|
||||
case profile, ok := <-ch:
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
found = true
|
||||
console.Success("got profile: id=%s name=%s", profile.AccountAddr, profile.Name)
|
||||
}
|
||||
}()
|
||||
err = a.FindProfilesByAccountIDs(context.Background(), accountsToFind, ch)
|
||||
if err != nil {
|
||||
console.Fatal("failed to query cafe: " + err.Error())
|
||||
}
|
||||
<-closeCh
|
||||
if !found {
|
||||
console.Fatal("no accounts found on cafe")
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
// subcommands
|
||||
cafeCmd.AddCommand(findProfiles)
|
||||
findProfiles.PersistentFlags().StringVarP(&mnemonic, "mnemonic", "", "", "mnemonic to find profiles on")
|
||||
findProfiles.PersistentFlags().StringVarP(&account, "account", "a", "", "account to find profiles on")
|
||||
}
|
|
@ -14,6 +14,7 @@ var CliCmd = &cobra.Command{
|
|||
func init() {
|
||||
// subcommands
|
||||
CliCmd.AddCommand(migrateCmd)
|
||||
CliCmd.AddCommand(cafeCmd)
|
||||
// local flags
|
||||
}
|
||||
|
||||
|
|
|
@ -3,14 +3,21 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/anytypeio/go-anytype-middleware/metrics"
|
||||
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
|
||||
grpc_zap "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap"
|
||||
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
||||
"github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc"
|
||||
"github.com/opentracing/opentracing-go"
|
||||
"github.com/uber/jaeger-client-go"
|
||||
"net"
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strconv"
|
||||
"syscall"
|
||||
|
||||
"github.com/anytypeio/go-anytype-middleware/core/event"
|
||||
|
@ -21,6 +28,8 @@ import (
|
|||
|
||||
"github.com/anytypeio/go-anytype-middleware/core"
|
||||
"github.com/anytypeio/go-anytype-middleware/pb/service"
|
||||
|
||||
jaegercfg "github.com/uber/jaeger-client-go/config"
|
||||
)
|
||||
|
||||
const defaultAddr = "127.0.0.1:31007"
|
||||
|
@ -82,13 +91,74 @@ func main() {
|
|||
log.Fatalf("failed to listen: %v", err)
|
||||
}
|
||||
webaddr = webLis.Addr().String()
|
||||
var (
|
||||
unaryInterceptors []grpc.UnaryServerInterceptor
|
||||
streamInterceptors []grpc.StreamServerInterceptor
|
||||
)
|
||||
|
||||
var unaryServerInterceptor grpc.UnaryServerInterceptor
|
||||
if metrics.Enabled {
|
||||
unaryServerInterceptor = grpc_prometheus.UnaryServerInterceptor
|
||||
unaryInterceptors = append(unaryInterceptors, grpc_prometheus.UnaryServerInterceptor)
|
||||
}
|
||||
|
||||
server := grpc.NewServer(grpc.MaxRecvMsgSize(20*1024*1024), grpc.UnaryInterceptor(unaryServerInterceptor))
|
||||
grpcDebug, _ := strconv.Atoi(os.Getenv("ANYTYPE_GRPC_LOG"))
|
||||
if grpcDebug > 0 {
|
||||
decider := func(_ context.Context, _ string, _ interface{}) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
grpcLogger := logging.Logger("grpc")
|
||||
|
||||
unaryInterceptors = append(unaryInterceptors, grpc_zap.UnaryServerInterceptor(grpcLogger.Desugar()))
|
||||
streamInterceptors = append(streamInterceptors, grpc_zap.StreamServerInterceptor(grpcLogger.Desugar()))
|
||||
if grpcDebug > 1 {
|
||||
unaryInterceptors = append(unaryInterceptors, grpc_zap.PayloadUnaryServerInterceptor(grpcLogger.Desugar(), decider))
|
||||
}
|
||||
if grpcDebug > 2 {
|
||||
streamInterceptors = append(streamInterceptors, grpc_zap.PayloadStreamServerInterceptor(grpcLogger.Desugar(), decider))
|
||||
}
|
||||
}
|
||||
|
||||
grpcTrace, _ := strconv.Atoi(os.Getenv("ANYTYPE_GRPC_TRACE"))
|
||||
if grpcTrace > 0 {
|
||||
jLogger := jaeger.StdLogger
|
||||
|
||||
cfg, err := jaegercfg.FromEnv()
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
if cfg.ServiceName == "" {
|
||||
cfg.ServiceName = "mw"
|
||||
}
|
||||
// Initialize tracer with a logger and a metrics factory
|
||||
tracer, closer, err := cfg.NewTracer(jaegercfg.Logger(jLogger))
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
defer closer.Close()
|
||||
|
||||
var (
|
||||
unaryOptions []otgrpc.Option
|
||||
streamOptions []otgrpc.Option
|
||||
)
|
||||
|
||||
// Set the singleton opentracing.Tracer with the Jaeger tracer.
|
||||
opentracing.SetGlobalTracer(tracer)
|
||||
if grpcTrace > 1 {
|
||||
unaryOptions = append(unaryOptions, otgrpc.LogPayloads())
|
||||
}
|
||||
if grpcTrace > 2 {
|
||||
streamOptions = append(streamOptions, otgrpc.LogPayloads())
|
||||
}
|
||||
|
||||
unaryInterceptors = append(unaryInterceptors, otgrpc.OpenTracingServerInterceptor(tracer, unaryOptions...))
|
||||
streamInterceptors = append(streamInterceptors, otgrpc.OpenTracingStreamServerInterceptor(tracer, streamOptions...))
|
||||
}
|
||||
|
||||
server := grpc.NewServer(grpc.MaxRecvMsgSize(20*1024*1024),
|
||||
grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(unaryInterceptors...)),
|
||||
grpc.StreamInterceptor(grpc_middleware.ChainStreamServer(streamInterceptors...)),
|
||||
)
|
||||
|
||||
service.RegisterClientCommandsServer(server, mw)
|
||||
if metrics.Enabled {
|
||||
grpc_prometheus.EnableHandlingTimeHistogram()
|
||||
|
|
125
core/account.go
125
core/account.go
|
@ -166,7 +166,7 @@ func (mw *Middleware) AccountCreate(req *pb.RpcAccountCreateRequest) *pb.RpcAcco
|
|||
|
||||
newAcc := &model.Account{Id: account.Address()}
|
||||
|
||||
if mw.app, err = anytype.StartNewApp(at, mw.EventSender, &config.Config{}); err != nil {
|
||||
if mw.app, err = anytype.StartNewApp(at, mw.EventSender, &config.Config{NewAccount: true}); err != nil {
|
||||
return response(newAcc, pb.RpcAccountCreateResponseError_ACCOUNT_CREATED_BUT_FAILED_TO_START_NODE, err)
|
||||
}
|
||||
|
||||
|
@ -274,6 +274,11 @@ func (mw *Middleware) AccountRecover(_ *pb.RpcAccountRecoverRequest) *pb.RpcAcco
|
|||
}
|
||||
}
|
||||
|
||||
// stop current account
|
||||
if err := mw.stop(); err != nil {
|
||||
return response(pb.RpcAccountRecoverResponseError_FAILED_TO_STOP_RUNNING_NODE, err)
|
||||
}
|
||||
|
||||
// do not unlock on defer because client may do AccountSelect before all remote accounts arrives
|
||||
// it is ok to unlock just after we've started with the 1st account
|
||||
at, err := core.New(
|
||||
|
@ -405,78 +410,80 @@ func (mw *Middleware) AccountSelect(req *pb.RpcAccountSelectRequest) *pb.RpcAcco
|
|||
mw.m.Lock()
|
||||
defer mw.m.Unlock()
|
||||
|
||||
if mw.app == nil || req.Id != mw.app.MustComponent(core.CName).(core.Service).Account() {
|
||||
// in case user selected account other than the first one(used to perform search)
|
||||
// or this is the first time in this session we run the Anytype node
|
||||
if err := mw.stop(); err != nil {
|
||||
return response(nil, pb.RpcAccountSelectResponseError_FAILED_TO_STOP_SEARCHER_NODE, err)
|
||||
// we already have this account running, lets just stop events
|
||||
if mw.app != nil && req.Id == mw.app.MustComponent(core.CName).(core.Service).Account() {
|
||||
mw.app.MustComponent("blockService").(block.Service).CloseBlocks()
|
||||
return response(&model.Account{Id: req.Id}, pb.RpcAccountSelectResponseError_NULL, nil)
|
||||
}
|
||||
|
||||
// in case user selected account other than the first one(used to perform search)
|
||||
// or this is the first time in this session we run the Anytype node
|
||||
if err := mw.stop(); err != nil {
|
||||
return response(nil, pb.RpcAccountSelectResponseError_FAILED_TO_STOP_SEARCHER_NODE, err)
|
||||
}
|
||||
|
||||
if req.RootPath != "" {
|
||||
mw.rootPath = req.RootPath
|
||||
}
|
||||
|
||||
if _, err := os.Stat(filepath.Join(mw.rootPath, req.Id)); os.IsNotExist(err) {
|
||||
if mw.mnemonic == "" {
|
||||
return response(nil, pb.RpcAccountSelectResponseError_LOCAL_REPO_NOT_EXISTS_AND_MNEMONIC_NOT_SET, err)
|
||||
}
|
||||
|
||||
if req.RootPath != "" {
|
||||
mw.rootPath = req.RootPath
|
||||
}
|
||||
|
||||
if _, err := os.Stat(filepath.Join(mw.rootPath, req.Id)); os.IsNotExist(err) {
|
||||
if mw.mnemonic == "" {
|
||||
return response(nil, pb.RpcAccountSelectResponseError_LOCAL_REPO_NOT_EXISTS_AND_MNEMONIC_NOT_SET, err)
|
||||
}
|
||||
|
||||
var account wallet.Keypair
|
||||
for i := 0; i < 100; i++ {
|
||||
account, err = core.WalletAccountAt(mw.mnemonic, i, "")
|
||||
if err != nil {
|
||||
return response(nil, pb.RpcAccountSelectResponseError_UNKNOWN_ERROR, err)
|
||||
}
|
||||
if account.Address() == req.Id {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
var accountPreviouslyWasFoundRemotely bool
|
||||
for _, foundAccount := range mw.foundAccounts {
|
||||
if foundAccount.Id == account.Address() {
|
||||
accountPreviouslyWasFoundRemotely = true
|
||||
}
|
||||
}
|
||||
|
||||
// do not allow to create repo if it wasn't previously(in the same session) found on the cafe
|
||||
if !accountPreviouslyWasFoundRemotely {
|
||||
return response(nil, pb.RpcAccountSelectResponseError_FAILED_TO_CREATE_LOCAL_REPO, fmt.Errorf("first you need to recover your account from remote cafe or create the new one with invite code"))
|
||||
}
|
||||
|
||||
seedRaw, err := account.Raw()
|
||||
var account wallet.Keypair
|
||||
for i := 0; i < 100; i++ {
|
||||
account, err = core.WalletAccountAt(mw.mnemonic, i, "")
|
||||
if err != nil {
|
||||
return response(nil, pb.RpcAccountSelectResponseError_UNKNOWN_ERROR, err)
|
||||
}
|
||||
|
||||
if err = core.WalletInitRepo(mw.rootPath, seedRaw); err != nil {
|
||||
return response(nil, pb.RpcAccountSelectResponseError_FAILED_TO_CREATE_LOCAL_REPO, err)
|
||||
if account.Address() == req.Id {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
at, err := core.New(
|
||||
core.WithRootPathAndAccount(mw.rootPath, req.Id),
|
||||
core.WithSnapshotMarshalerFunc(change.NewSnapshotChange),
|
||||
)
|
||||
var accountPreviouslyWasFoundRemotely bool
|
||||
for _, foundAccount := range mw.foundAccounts {
|
||||
if foundAccount.Id == account.Address() {
|
||||
accountPreviouslyWasFoundRemotely = true
|
||||
}
|
||||
}
|
||||
|
||||
// do not allow to create repo if it wasn't previously(in the same session) found on the cafe
|
||||
if !accountPreviouslyWasFoundRemotely {
|
||||
return response(nil, pb.RpcAccountSelectResponseError_FAILED_TO_CREATE_LOCAL_REPO, fmt.Errorf("first you need to recover your account from remote cafe or create the new one with invite code"))
|
||||
}
|
||||
|
||||
seedRaw, err := account.Raw()
|
||||
if err != nil {
|
||||
return response(nil, pb.RpcAccountSelectResponseError_UNKNOWN_ERROR, err)
|
||||
}
|
||||
|
||||
if mw.app, err = anytype.StartNewApp(at, mw.EventSender, &config.Config{AccountSelect: true}); err != nil {
|
||||
if err == core.ErrRepoCorrupted {
|
||||
return response(nil, pb.RpcAccountSelectResponseError_LOCAL_REPO_EXISTS_BUT_CORRUPTED, err)
|
||||
}
|
||||
|
||||
if strings.Contains(err.Error(), errSubstringMultipleAnytypeInstance) {
|
||||
return response(nil, pb.RpcAccountSelectResponseError_ANOTHER_ANYTYPE_PROCESS_IS_RUNNING, err)
|
||||
}
|
||||
|
||||
return response(nil, pb.RpcAccountSelectResponseError_FAILED_TO_RUN_NODE, err)
|
||||
if err = core.WalletInitRepo(mw.rootPath, seedRaw); err != nil {
|
||||
return response(nil, pb.RpcAccountSelectResponseError_FAILED_TO_CREATE_LOCAL_REPO, err)
|
||||
}
|
||||
} else if req.Id == mw.app.MustComponent(core.CName).(core.Service).Account() {
|
||||
// in order to stop send events we need to close all opened blocks in case client still has them
|
||||
mw.app.MustComponent("blockService").(block.Service).CloseBlocks()
|
||||
}
|
||||
|
||||
at, err := core.New(
|
||||
core.WithRootPathAndAccount(mw.rootPath, req.Id),
|
||||
core.WithSnapshotMarshalerFunc(change.NewSnapshotChange),
|
||||
)
|
||||
if err != nil {
|
||||
return response(nil, pb.RpcAccountSelectResponseError_UNKNOWN_ERROR, err)
|
||||
}
|
||||
|
||||
if mw.app, err = anytype.StartNewApp(at, mw.EventSender, &config.Config{}); err != nil {
|
||||
if err == core.ErrRepoCorrupted {
|
||||
return response(nil, pb.RpcAccountSelectResponseError_LOCAL_REPO_EXISTS_BUT_CORRUPTED, err)
|
||||
}
|
||||
|
||||
if strings.Contains(err.Error(), errSubstringMultipleAnytypeInstance) {
|
||||
return response(nil, pb.RpcAccountSelectResponseError_ANOTHER_ANYTYPE_PROCESS_IS_RUNNING, err)
|
||||
}
|
||||
|
||||
return response(nil, pb.RpcAccountSelectResponseError_FAILED_TO_RUN_NODE, err)
|
||||
}
|
||||
|
||||
return response(&model.Account{Id: req.Id}, pb.RpcAccountSelectResponseError_NULL, nil)
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import "github.com/anytypeio/go-anytype-middleware/app"
|
|||
const CName = "config"
|
||||
|
||||
type Config struct {
|
||||
AccountSelect bool
|
||||
NewAccount bool // set to true if a new account is creating. This option controls whether mw should wait for the existing data to arrive before creating the new log
|
||||
}
|
||||
|
||||
func (c Config) Init(a *app.App) (err error) {
|
||||
|
|
|
@ -59,7 +59,7 @@ func (mw *Middleware) DebugSync(req *pb.RpcDebugSyncRequest) *pb.RpcDebugSyncRes
|
|||
return &pb.RpcDebugSyncResponse{}
|
||||
}
|
||||
at := mw.app.MustComponent(core.CName).(core.Service)
|
||||
mw.m.Unlock()
|
||||
mw.m.RUnlock()
|
||||
|
||||
response := func(threads []*pb.RpcDebugthreadInfo, threadsWithoutRepl int32, threadsWithoutHeadDownloaded int32, totalRecords int32, totalSize int32, code pb.RpcDebugSyncResponseErrorCode, err error) *pb.RpcDebugSyncResponse {
|
||||
m := &pb.RpcDebugSyncResponse{DeviceId: at.Device(), Threads: threads, ThreadsWithoutReplInOwnLog: threadsWithoutRepl, ThreadsWithoutHeadDownloaded: threadsWithoutHeadDownloaded, TotalThreads: int32(len(threads)), TotalRecords: totalRecords, TotalSize: totalSize, Error: &pb.RpcDebugSyncResponseError{Code: code}}
|
||||
|
|
|
@ -6,9 +6,11 @@ services:
|
|||
image: docker.pkg.github.com/anytypeio/python-anytype-testing/tests:latest
|
||||
volumes:
|
||||
- ./allure-results:/app/allure-results
|
||||
- shared-temp:/tmp/shared
|
||||
links:
|
||||
- middleware-node-a
|
||||
- middleware-node-b
|
||||
- middleware-node-base
|
||||
environment:
|
||||
TEST_MIDDLEWARE_NODE_A_ADDRESS_HOST: middleware-node-a
|
||||
TEST_MIDDLEWARE_NODE_A_ADDRESS_PORT: 31007
|
||||
|
@ -16,6 +18,9 @@ services:
|
|||
TEST_MIDDLEWARE_NODE_B_ADDRESS_HOST: middleware-node-b
|
||||
TEST_MIDDLEWARE_NODE_B_ADDRESS_PORT: 41007
|
||||
TEST_MIDDLEWARE_NODE_B_ADDRESS_GATEWAY_PORT: 42007
|
||||
TEST_MIDDLEWARE_NODE_BASE_ADDRESS_HOST: middleware-node-base
|
||||
TEST_MIDDLEWARE_NODE_BASE_ADDRESS_PORT: 51007
|
||||
TEST_MIDDLEWARE_NODE_BASE_ADDRESS_GATEWAY_PORT: 52007
|
||||
command: bash -c "make test"
|
||||
|
||||
middleware-node-a:
|
||||
|
@ -25,8 +30,15 @@ services:
|
|||
environment:
|
||||
ANYTYPE_GRPC_ADDR: "0.0.0.0:31007"
|
||||
ANYTYPE_GATEWAY_ADDR: "0.0.0.0:32007"
|
||||
ANYTYPE_LOG_LEVEL: "*=DEBUG"
|
||||
|
||||
ANYTYPE_LOG_LEVEL: "anytype-mw-app=DEBUG;grpc=DEBUG;anytype-gateway=DEBUG"
|
||||
ANYTYPE_LOG_NOGELF: 1
|
||||
ANYTYPE_GRPC_LOG: 3
|
||||
# local tracing
|
||||
#ANYTYPE_GRPC_TRACE: 3
|
||||
#JAEGER_AGENT_HOST: "docker.for.mac.localhost"
|
||||
#JAEGER_SERVICE_NAME: "mw-a"
|
||||
volumes:
|
||||
- shared-temp:/tmp/shared
|
||||
middleware-node-b:
|
||||
stop_grace_period: 1s
|
||||
stop_signal: SIGABRT
|
||||
|
@ -34,4 +46,32 @@ services:
|
|||
environment:
|
||||
ANYTYPE_GRPC_ADDR: "0.0.0.0:41007"
|
||||
ANYTYPE_GATEWAY_ADDR: "0.0.0.0:42007"
|
||||
ANYTYPE_LOG_LEVEL: "*=DEBUG"
|
||||
ANYTYPE_LOG_LEVEL: "anytype-mw-app=DEBUG;grpc=DEBUG;anytype-gateway=DEBUG"
|
||||
ANYTYPE_LOG_NOGELF: 1
|
||||
ANYTYPE_GRPC_LOG: 3
|
||||
# local tracing
|
||||
#ANYTYPE_GRPC_TRACE: 3
|
||||
#JAEGER_AGENT_HOST: "docker.for.mac.localhost"
|
||||
#JAEGER_SERVICE_NAME: "mw-b"
|
||||
#JAEGER_SERVICE_NAME: "mw-b"
|
||||
volumes:
|
||||
- shared-temp:/tmp/shared
|
||||
middleware-node-base:
|
||||
stop_grace_period: 1s
|
||||
stop_signal: SIGABRT
|
||||
image: docker.pkg.github.com/anytypeio/go-anytype-middleware/server:${BASE_TAG}
|
||||
environment:
|
||||
ANYTYPE_GRPC_ADDR: "0.0.0.0:51007"
|
||||
ANYTYPE_GATEWAY_ADDR: "0.0.0.0:52007"
|
||||
ANYTYPE_LOG_LEVEL: "anytype-mw-app=DEBUG;grpc=DEBUG;anytype-gateway=DEBUG"
|
||||
ANYTYPE_LOG_NOGELF: 1
|
||||
ANYTYPE_GRPC_LOG: 3
|
||||
# local tracing
|
||||
#ANYTYPE_GRPC_TRACE: 3
|
||||
#JAEGER_AGENT_HOST: "docker.for.mac.localhost"
|
||||
#JAEGER_SERVICE_NAME: "mw-b"
|
||||
#JAEGER_SERVICE_NAME: "mw-b"
|
||||
volumes:
|
||||
- shared-temp:/tmp/shared
|
||||
volumes:
|
||||
shared-temp:
|
|
@ -1 +0,0 @@
|
|||
Not Found
|
9
go.mod
9
go.mod
|
@ -3,6 +3,7 @@ module github.com/anytypeio/go-anytype-middleware
|
|||
go 1.14
|
||||
|
||||
require (
|
||||
github.com/HdrHistogram/hdrhistogram-go v1.1.0 // indirect
|
||||
github.com/JohannesKaufmann/html-to-markdown v0.0.0-00010101000000-000000000000
|
||||
github.com/PuerkitoBio/goquery v1.6.1
|
||||
github.com/anytypeio/go-slip10 v0.0.0-20200330112030-a352ca8495e4
|
||||
|
@ -19,7 +20,9 @@ require (
|
|||
github.com/gogo/status v1.1.0
|
||||
github.com/golang/mock v1.4.4
|
||||
github.com/google/uuid v1.2.0
|
||||
github.com/grpc-ecosystem/go-grpc-middleware v1.2.2
|
||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
|
||||
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645
|
||||
github.com/h2non/filetype v1.1.1
|
||||
github.com/hashicorp/golang-lru v0.5.4
|
||||
github.com/hsanjuan/ipfs-lite v1.1.18
|
||||
|
@ -46,6 +49,7 @@ require (
|
|||
github.com/libp2p/go-libp2p-swarm v0.4.2
|
||||
github.com/libp2p/go-libp2p-tls v0.1.3
|
||||
github.com/libp2p/go-tcp-transport v0.2.1
|
||||
github.com/logrusorgru/aurora v2.0.3+incompatible
|
||||
github.com/magiconair/properties v1.8.4
|
||||
github.com/mauidude/go-readability v0.0.0-20141216012317-2f30b1a346f1
|
||||
github.com/mb0/diff v0.0.0-20131118162322-d8d9a906c24d
|
||||
|
@ -56,13 +60,16 @@ require (
|
|||
github.com/multiformats/go-multiaddr v0.3.1
|
||||
github.com/multiformats/go-multibase v0.0.3
|
||||
github.com/multiformats/go-multihash v0.0.14
|
||||
github.com/opentracing/opentracing-go v1.2.0
|
||||
github.com/otiai10/opengraph v1.1.3
|
||||
github.com/prometheus/client_golang v1.9.0
|
||||
github.com/prometheus/client_golang v1.10.0
|
||||
github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd
|
||||
github.com/spf13/cobra v0.0.5
|
||||
github.com/stretchr/testify v1.7.0
|
||||
github.com/textileio/go-threads v1.0.2-0.20210304072541-d0f91da84404
|
||||
github.com/tyler-smith/go-bip39 v1.0.1-0.20190808214741-c55f737395bc
|
||||
github.com/uber/jaeger-client-go v2.25.0+incompatible
|
||||
github.com/uber/jaeger-lib v2.4.0+incompatible // indirect
|
||||
github.com/yuin/goldmark v1.3.1
|
||||
go.uber.org/zap v1.16.0
|
||||
golang.org/x/text v0.3.5
|
||||
|
|
|
@ -192,7 +192,7 @@ func (a *Anytype) Run() (err error) {
|
|||
if err = a.Start(); err != nil {
|
||||
return
|
||||
}
|
||||
return a.InitPredefinedBlocks(context.TODO(), a.config.AccountSelect)
|
||||
return a.InitPredefinedBlocks(context.TODO(), a.config.NewAccount)
|
||||
}
|
||||
|
||||
func (a *Anytype) Account() string {
|
||||
|
@ -389,7 +389,7 @@ func (a *Anytype) start() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (a *Anytype) InitPredefinedBlocks(ctx context.Context, accountSelect bool) error {
|
||||
func (a *Anytype) InitPredefinedBlocks(ctx context.Context, newAccount bool) error {
|
||||
cctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
|
@ -402,7 +402,7 @@ func (a *Anytype) InitPredefinedBlocks(ctx context.Context, accountSelect bool)
|
|||
}
|
||||
}()
|
||||
|
||||
ids, err := a.threadService.EnsurePredefinedThreads(cctx, !accountSelect)
|
||||
ids, err := a.threadService.EnsurePredefinedThreads(cctx, newAccount)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -26,10 +26,6 @@ type Profile struct {
|
|||
|
||||
func (a *Anytype) FindProfilesByAccountIDs(ctx context.Context, AccountAddrs []string, ch chan Profile) error {
|
||||
var errDeadlineExceeded = status.Error(codes.DeadlineExceeded, "deadline exceeded")
|
||||
select {
|
||||
case <-a.onlineCh:
|
||||
case <-ctx.Done():
|
||||
}
|
||||
|
||||
if a.cafe == nil {
|
||||
close(ch)
|
||||
|
|
|
@ -69,6 +69,7 @@ func GatewayAddr() string {
|
|||
func (g *gateway) Init(a *app.App) (err error) {
|
||||
g.Node = a.MustComponent(core.CName).(core.Service)
|
||||
g.addr = GatewayAddr()
|
||||
log.Debugf("gateway.Init: %s", g.addr)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -81,6 +82,7 @@ func (g *gateway) Run() error {
|
|||
return fmt.Errorf("gateway already started")
|
||||
}
|
||||
|
||||
log.Infof("gateway.Run: %s", g.addr)
|
||||
handler := http.NewServeMux()
|
||||
g.server = &http.Server{
|
||||
Addr: g.addr,
|
||||
|
@ -129,9 +131,13 @@ func (g *gateway) Run() error {
|
|||
|
||||
// Close stops the gateway
|
||||
func (g *gateway) Close() error {
|
||||
log.Debugf("gateway.Close: %s", g.addr)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||
defer cancel()
|
||||
return g.server.Shutdown(ctx)
|
||||
err := g.server.Shutdown(ctx)
|
||||
defer log.Errorf("gateway.Close finished: %s: %v", g.addr, err)
|
||||
return err
|
||||
}
|
||||
|
||||
// Addr returns the gateway's address
|
||||
|
|
40
util/console/console.go
Normal file
40
util/console/console.go
Normal file
|
@ -0,0 +1,40 @@
|
|||
package console
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/logrusorgru/aurora"
|
||||
)
|
||||
|
||||
func Message(format string, args ...interface{}) {
|
||||
if len(format) > 0 {
|
||||
fmt.Println(aurora.Sprintf(aurora.BrightBlack("> "+format), args...))
|
||||
}
|
||||
}
|
||||
|
||||
func Success(format string, args ...interface{}) {
|
||||
fmt.Println(aurora.Sprintf(aurora.Green("> Success! %s"),
|
||||
aurora.Sprintf(aurora.BrightBlack(format), args...)))
|
||||
}
|
||||
|
||||
func Warn(format string, args ...interface{}) {
|
||||
fmt.Println(aurora.Sprintf(aurora.Magenta("> Warning! %s"),
|
||||
aurora.Sprintf(aurora.BrightBlack(format), args...)))
|
||||
}
|
||||
|
||||
func Error(format string, args ...interface{}) {
|
||||
fmt.Println(aurora.Sprintf(aurora.Yellow("> Error! %s"),
|
||||
aurora.Sprintf(aurora.BrightBlack(format), args...)))
|
||||
}
|
||||
|
||||
func End(format string, args ...interface{}) {
|
||||
Message(format, args...)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
func Fatal(format string, args ...interface{}) {
|
||||
fmt.Println(aurora.Sprintf(aurora.Red("> Fatal! %s"),
|
||||
aurora.Sprintf(aurora.BrightBlack(format), args...)))
|
||||
os.Exit(1)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue