feat(GODT-2442): add gRPC interface to send feedback.

This commit is contained in:
Jakub
2023-03-06 16:42:07 +01:00
parent 8c0bb22de3
commit f03688ba72
10 changed files with 1399 additions and 1122 deletions

View File

@ -298,6 +298,21 @@ func (bridge *Bridge) SetAddressMode(ctx context.Context, userID string, mode va
}, bridge.usersLock)
}
// SendBadEventUserFeedback sets the address mode for the given user.
func (bridge *Bridge) SendBadEventUserFeedback(ctx context.Context, userID string, doResync bool) error {
l := logrus.WithField("userID", userID).WithField("doResycn", doResync)
l.Info("Passing bad event feedback to user")
user, ok := bridge.users[userID]
if !ok {
return ErrNoSuchUser
}
user.SendBadEventFeedback(doResync)
return nil
}
func (bridge *Bridge) loginUser(ctx context.Context, client *proton.Client, authUID, authRef string, keyPass []byte) (string, error) {
apiUser, err := client.GetUser(ctx)
if err != nil {

View File

@ -85,6 +85,10 @@ func TestBridge_User_RefreshEvent(t *testing.T) {
}
func TestBridge_User_BadMessage_BadEvent(t *testing.T) {
t.Run("Logout-Login", badMessage_badEvent)
}
func badMessage_badEvent(t *testing.T) {
withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, storeKey []byte) {
// Create a user.
userID, addrID, err := s.CreateUser("user", password)

View File

@ -153,7 +153,7 @@ func (bridge *Bridge) handleUserBadEvent(ctx context.Context, user *user.User, e
// blockEventsIMAPandSMTP()
if doResyc, err := bridge.getBadEventUserFeedback(); err != nil || !doResyc {
if doResyc, err := bridge.getBadEventUserFeedback(user.ID()); err != nil || !doResyc {
if rerr := bridge.reporter.ReportMessageWithContext("Failed to handle event: logout", reportContext); rerr != nil {
logrus.WithError(rerr).Error("Failed to report failed event handling")
}
@ -179,8 +179,13 @@ func (bridge *Bridge) handleUserBadEvent(ctx context.Context, user *user.User, e
}, bridge.usersLock)
}
func (bridge *Bridge) getBadEventUserFeedback() (doResyc bool, err error) {
return true, nil
func (bridge *Bridge) getBadEventUserFeedback(userID string) (doResyc bool, err error) {
user, ok := bridge.users[userID]
if !ok {
return false, ErrNoSuchUser
}
return user.GetBadEventFeedback(), nil
}
func (bridge *Bridge) handleUncategorizedErrorEvent(event events.UncategorizedEventError) {

View File

@ -17,8 +17,8 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.28.0
// protoc v3.21.3
// protoc-gen-go v1.28.1
// protoc v3.21.12
// source: focus.proto
package proto

View File

@ -1,7 +1,24 @@
// Copyright (c) 2022 Proton Technologies AG
//
// This file is part of ProtonMail Bridge.
//
// ProtonMail Bridge is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ProtonMail Bridge is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with ProtonMail Bridge. If not, see <https://www.gnu.org/licenses/>.
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.2.0
// - protoc v3.21.3
// - protoc-gen-go-grpc v1.3.0
// - protoc v3.21.12
// source: focus.proto
package proto
@ -19,6 +36,11 @@ import (
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7
const (
Focus_Raise_FullMethodName = "/focus.Focus/Raise"
Focus_Version_FullMethodName = "/focus.Focus/Version"
)
// FocusClient is the client API for Focus service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
@ -37,7 +59,7 @@ func NewFocusClient(cc grpc.ClientConnInterface) FocusClient {
func (c *focusClient) Raise(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*emptypb.Empty, error) {
out := new(emptypb.Empty)
err := c.cc.Invoke(ctx, "/focus.Focus/Raise", in, out, opts...)
err := c.cc.Invoke(ctx, Focus_Raise_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
@ -46,7 +68,7 @@ func (c *focusClient) Raise(ctx context.Context, in *emptypb.Empty, opts ...grpc
func (c *focusClient) Version(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*VersionResponse, error) {
out := new(VersionResponse)
err := c.cc.Invoke(ctx, "/focus.Focus/Version", in, out, opts...)
err := c.cc.Invoke(ctx, Focus_Version_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
@ -95,7 +117,7 @@ func _Focus_Raise_Handler(srv interface{}, ctx context.Context, dec func(interfa
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/focus.Focus/Raise",
FullMethod: Focus_Raise_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(FocusServer).Raise(ctx, req.(*emptypb.Empty))
@ -113,7 +135,7 @@ func _Focus_Version_Handler(srv interface{}, ctx context.Context, dec func(inter
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/focus.Focus/Version",
FullMethod: Focus_Version_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(FocusServer).Version(ctx, req.(*emptypb.Empty))

File diff suppressed because it is too large Load Diff

View File

@ -91,6 +91,7 @@ service Bridge {
rpc GetUserList(google.protobuf.Empty) returns (UserListResponse);
rpc GetUser(google.protobuf.StringValue) returns (User);
rpc SetUserSplitMode(UserSplitModeRequest) returns (google.protobuf.Empty);
rpc SendBadEventUserFeedback(UserBadEventFeedbackRequest) returns (google.protobuf.Empty);
rpc LogoutUser(google.protobuf.StringValue) returns (google.protobuf.Empty);
rpc RemoveUser(google.protobuf.StringValue) returns (google.protobuf.Empty);
rpc ConfigureUserAppleMail(ConfigureAppleMailRequest) returns (google.protobuf.Empty);
@ -203,6 +204,12 @@ message UserSplitModeRequest {
bool active = 2;
}
message UserBadEventFeedbackRequest {
string userID = 1;
bool doResync = 2;
}
message UserListResponse {
repeated User users = 1;
}
@ -479,4 +486,4 @@ enum ErrorCode {
message GenericErrorEvent {
ErrorCode code = 1;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -95,6 +95,24 @@ func (s *Service) SetUserSplitMode(ctx context.Context, splitMode *UserSplitMode
return &emptypb.Empty{}, nil
}
func (s *Service) SendBadEventUserFeedback(ctx context.Context, feedback *UserBadEventFeedbackRequest) (*emptypb.Empty, error) {
l := s.log.WithField("UserID", feedback.UserID).WithField("doResync", feedback.DoResync)
l.Debug("SendBadEventUserFeedback")
user, err := s.bridge.GetUserInfo(feedback.UserID)
if err != nil {
return nil, status.Errorf(codes.NotFound, "user not found %v", feedback.UserID)
}
if err := s.bridge.SendBadEventUserFeedback(context.Background(), user.UserID, feedback.DoResync); err != nil {
l.WithError(err).Error("Failed to send bad event feedback")
}
l.Info("Sending bad event feedback finished.")
return &emptypb.Empty{}, nil
}
func (s *Service) LogoutUser(ctx context.Context, userID *wrapperspb.StringValue) (*emptypb.Empty, error) {
s.log.WithField("UserID", userID.Value).Debug("LogoutUser")

View File

@ -90,6 +90,9 @@ type User struct {
syncWorkers int
showAllMail uint32
// doResyncFeedback must be non-blocking for first attempt (i.e. buffered)
doResyncFeedback chan bool
}
// New returns a new user.
@ -148,6 +151,8 @@ func New(
syncWorkers: syncWorkers,
showAllMail: b32(showAllMail),
doResyncFeedback: make(chan bool, 1),
}
// Initialize the user's update channels for its current address mode.
@ -299,6 +304,16 @@ func (user *User) SetAddressMode(_ context.Context, mode vault.AddressMode) erro
}, user.eventLock, user.apiAddrsLock, user.updateChLock)
}
// SendBadEventFeedback sends user feedback whether should do message re-sync.
func (user *User) SendBadEventFeedback(doResync bool) {
user.doResyncFeedback <- doResync
}
// GetBadEventFeedback read the user feedback whether should do message re-sync.
func (user *User) GetBadEventFeedback() bool {
return <-user.doResyncFeedback
}
// SetShowAllMail sets whether to show the All Mail mailbox.
func (user *User) SetShowAllMail(show bool) {
user.log.WithField("show", show).Info("Setting show all mail")