Skip to content

Commit

Permalink
Scaffold identity server (#371)
Browse files Browse the repository at this point in the history
This generates the protos, and stubs out the identity service API endpoints. I'll work on the DB changes next.
  • Loading branch information
richardhuaaa authored Apr 11, 2024
1 parent ac22dc7 commit 4c761e5
Show file tree
Hide file tree
Showing 42 changed files with 6,449 additions and 903 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This repo provides software for the nodes that currently form the XMTP network.

At this time, all nodes in the XMTP network are run by XMTP Labs, whose mission is to promote and support the development and global adoption of XMTP.

All new development is focused on [xmtpd](https://github.com/xmtp/xmtpd), an **experimental** version of XMTP node software.
All new development is focused on [xmtpd](https://github.com/xmtp/xmtpd), an **experimental** version of XMTP node software.

After `xmtpd` meets specific functional requirements, the plan is for it to become the node software that powers the XMTP network. In the future, anyone will be able to run an `xmtpd` node that participates in the XMTP network.

Expand All @@ -15,6 +15,8 @@ After `xmtpd` meets specific functional requirements, the plan is for it to beco
- [Go](https://go.dev/doc/install)
- [Docker](https://www.docker.com/get-started/)

You must have the _exact_ go version listed in `go.mod` - you can verify this by running `go version`.

### Install dependencies and start the DB

1. `dev/up`
Expand Down
2 changes: 1 addition & 1 deletion dev/up
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if ! which golangci-lint &>/dev/null; then brew install golangci-lint; fi
if ! which shellcheck &>/dev/null; then brew install shellcheck; fi
if ! which protoc &>/dev/null; then brew install protobuf; fi
if ! which protoc-gen-go &>/dev/null; then go install google.golang.org/protobuf/cmd/protoc-gen-go@latest; fi
if ! which mockgen &>/dev/null; then go install go.uber.org/mock/mockgen@latest; fi
if [ `mockgen --version` != "v0.4.0" ]; then go install go.uber.org/mock/mockgen@v0.4.0; fi
if ! which protolint &>/dev/null; then go install github.com/yoheimuta/protolint/cmd/protolint@latest; fi

dev/generate
Expand Down
16 changes: 15 additions & 1 deletion pkg/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
swgui "github.com/swaggest/swgui/v3"
wakupb "github.com/waku-org/go-waku/waku/v2/protocol/pb"
wakurelay "github.com/waku-org/go-waku/waku/v2/protocol/relay"
identityv1pb "github.com/xmtp/xmtp-node-go/pkg/proto/identity/api/v1"
proto "github.com/xmtp/xmtp-node-go/pkg/proto/message_api/v1"
mlsv1pb "github.com/xmtp/xmtp-node-go/pkg/proto/mls/api/v1"
messagev1openapi "github.com/xmtp/xmtp-node-go/pkg/proto/openapi"
Expand All @@ -33,6 +34,7 @@ import (
"github.com/pires/go-proxyproto"
messagev1 "github.com/xmtp/xmtp-node-go/pkg/api/message/v1"
apicontext "github.com/xmtp/xmtp-node-go/pkg/api/message/v1/context"
identityv1 "github.com/xmtp/xmtp-node-go/pkg/identity/api/v1"
mlsv1 "github.com/xmtp/xmtp-node-go/pkg/mls/api/v1"
)

Expand All @@ -51,6 +53,7 @@ type Server struct {
httpListener net.Listener
messagev1 *messagev1.Service
mlsv1 *mlsv1.Service
identityv1 *identityv1.Service
wg sync.WaitGroup
ctx context.Context
ctxCancel func()
Expand Down Expand Up @@ -155,13 +158,19 @@ func (s *Server) startGRPC() error {
}
proto.RegisterMessageApiServer(grpcServer, s.messagev1)

// Enable the MLS server if a store is provided
// Enable the MLS and identity servers if a store is provided
if s.Config.MLSStore != nil && s.Config.MLSValidator != nil && s.Config.EnableMls {
s.mlsv1, err = mlsv1.NewService(s.Log, s.Config.MLSStore, s.Config.MLSValidator, s.natsServer, publishToWakuRelay)
if err != nil {
return errors.Wrap(err, "creating mls service")
}
mlsv1pb.RegisterMlsApiServer(grpcServer, s.mlsv1)

s.identityv1, err = identityv1.NewService(s.Log, s.Config.MLSStore)
if err != nil {
return errors.Wrap(err, "creating identity service")
}
identityv1pb.RegisterIdentityApiServer(grpcServer, s.identityv1)
}

// Initialize waku relay subscription.
Expand Down Expand Up @@ -251,6 +260,11 @@ func (s *Server) startHTTP() error {
if err != nil {
return errors.Wrap(err, "registering mls handler")
}

err = identityv1pb.RegisterIdentityApiHandler(s.ctx, gwmux, conn)
if err != nil {
return errors.Wrap(err, "registering identity handler")
}
}

addr := addrString(s.HTTPAddress, s.HTTPPort)
Expand Down
2 changes: 1 addition & 1 deletion pkg/authn/authn.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions pkg/identity/api/v1/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package api

import (
"context"

mlsstore "github.com/xmtp/xmtp-node-go/pkg/mls/store"
api "github.com/xmtp/xmtp-node-go/pkg/proto/identity/api/v1"
"go.uber.org/zap"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

type Service struct {
api.UnimplementedIdentityApiServer

log *zap.Logger
store mlsstore.MlsStore

ctx context.Context
ctxCancel func()
}

func NewService(log *zap.Logger, store mlsstore.MlsStore) (s *Service, err error) {
s = &Service{
log: log.Named("identity"),
store: store,
}
s.ctx, s.ctxCancel = context.WithCancel(context.Background())

s.log.Info("Starting identity service")
return s, nil
}

func (s *Service) Close() {
s.log.Info("closing")

if s.ctxCancel != nil {
s.ctxCancel()
}

s.log.Info("closed")
}

func (s *Service) PublishIdentityUpdate(ctx context.Context, req *api.PublishIdentityUpdateRequest) (*api.PublishIdentityUpdateResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "unimplemented")
}

func (s *Service) GetIdentityUpdates(ctx context.Context, req *api.GetIdentityUpdatesRequest) (*api.GetIdentityUpdatesResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "unimplemented")
}

func (s *Service) GetInboxIds(ctx context.Context, req *api.GetInboxIdsRequest) (*api.GetInboxIdsResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "unimplemented")
}
Loading

0 comments on commit 4c761e5

Please sign in to comment.