services

package
v0.0.0-...-0e2b5c9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GetLinkedClientsBatchSize = 500

GetLinkedClientsBatchSize is the maximum number of clients pulled from the database at a time when sending them the new client pubkey.

View Source
var NewC2KeyBatchSize = 500

NewC2KeyBatchSize is the maximum number of clients pulled from the database at a time when sending them the new C2 key.

View Source
var NewTopicBatchSize = 500

NewTopicBatchSize is the maximum number of topic clients pulled from the database at a time when sending them the new topic key. Having it too low will create too many queries, and too high will create too slow queries.

Functions

func IsErrRecordNotFound

func IsErrRecordNotFound(err error) bool

IsErrRecordNotFound indicate whenever error is a RecordNotFound error

func ValidateE4NameOrIDPair

func ValidateE4NameOrIDPair(name string, id []byte) ([]byte, error)

ValidateE4NameOrIDPair will check the following logic:

  1. We can pass name AND/OR id
  2. If a name is passed and an ID, these should be consistent.
  3. If just a name is passed, derive the ID here.
  4. If a name is not passed, an empty string is acceptable (but all lookups must be by ID) This option will not be exposed to GRPC or HTTP APIs and is reserved for any future protocol.

Types

type E4

type E4 interface {
	// Client Only Manipulation
	NewClient(ctx context.Context, name string, id, key []byte) error
	NewClientKey(ctx context.Context, id []byte) error
	RemoveClient(ctx context.Context, id []byte) error
	ResetClient(ctx context.Context, id []byte) error
	GetClientsRange(ctx context.Context, offset, count int) ([]IDNamePair, error)
	CountClients(ctx context.Context) (int, error)

	// Individual Topic Manipulaton
	NewTopic(ctx context.Context, topic string) error
	RemoveTopic(ctx context.Context, topic string) error
	GetTopicsRange(ctx context.Context, offset, count int) ([]string, error)
	CountTopics(ctx context.Context) (int, error)

	// Linking, removing topic-client mappings:
	NewTopicClient(ctx context.Context, id []byte, topic string) error
	RemoveTopicClient(ctx context.Context, id []byte, topic string) error

	// Counting topics per client, or clients per topic.
	CountTopicsForClient(ctx context.Context, id []byte) (int, error)
	CountClientsForTopic(ctx context.Context, topic string) (int, error)

	// Retrieving clients per topic or topics per client
	GetTopicsRangeByClient(ctx context.Context, id []byte, offset, count int) ([]string, error)
	GetClientsRangeByTopic(ctx context.Context, topic string, offset, count int) ([]IDNamePair, error)

	// Clients linking / unlinking / counting linked
	LinkClient(ctx context.Context, sourceClientID, targetClientID []byte) error
	UnlinkClient(ctx context.Context, sourceClientID, targetClientID []byte) error
	CountLinkedClients(ctx context.Context, id []byte) (int, error)
	GetLinkedClients(ctx context.Context, id []byte, offset, count int) ([]IDNamePair, error)

	// SendClientPubKey send the sourceClientID public key to targetClientID via a SetPubKeyCmd.
	// Only when C2 is configured in pubkey mode, otherwise an error will be immediately returned.
	SendClientPubKey(ctx context.Context, sourceClientID, targetClientID []byte) error
	// RemoveClientPubKey removes the sourceClientID public key from targetClientID via a RemovePubKeyCmd.
	// Only when C2 is configured in pubkey mode, otherwise an error will be immediately returned.
	RemoveClientPubKey(ctx context.Context, sourceClientID, targetClientID []byte) error
	// ResetClientPubKeys removes all public keys stored on targetClientID via a ResetPubKeyCmd
	// Only when C2 is configured in pubkey mode, otherwise an error will be immediately returned.
	ResetClientPubKeys(ctx context.Context, targetClientID []byte) error
	// NewC2Key generates a random C2 key pair and the public key is sent to all clients via a SetC2KeyCmd.
	// The new key pair is then used by the C2 and replaces the previous one.
	// Only when C2 is configured in pubkey mode, otherwise an error will be immediately returned.
	NewC2Key(ctx context.Context) error
	// ProtectMessage protects the given data with the given topic's key.
	ProtectMessage(ctx context.Context, topic string, data []byte) ([]byte, error)
	// UnprotectMessage unprotect the given data with the given topic's key.
	UnprotectMessage(ctx context.Context, topic string, data []byte) ([]byte, error)

	// GetCryptoMode returns the current configured config.CryptoMode
	GetCryptoMode() config.CryptoMode
}

E4 describe the available methods on the E4 service

func NewE4

func NewE4(
	db models.Database,
	pubSubClient protocols.PubSubClient,
	commandFactory commands.Factory,
	eventDispatcher events.Dispatcher,
	eventFactory events.Factory,
	e4Key crypto.E4Key,
	logger log.FieldLogger,
	dbEncKey []byte,
	cfg config.CryptoCfg,
) E4

NewE4 creates a new E4 service

type ErrClientNotFound

type ErrClientNotFound struct {
}

ErrClientNotFound is a database error when a requested record cannot be found A message containing the missing entity type will be returned to the user

func (ErrClientNotFound) Error

func (e ErrClientNotFound) Error() string

type ErrInternal

type ErrInternal struct {
}

ErrInternal describe an internal error A generic error message will be returned to the user

func (ErrInternal) Error

func (e ErrInternal) Error() string

type ErrInvalidCryptoMode

type ErrInvalidCryptoMode struct {
	Err error
}

ErrInvalidCryptoMode is returned when trying to execute a method retricted by the current mode

func (ErrInvalidCryptoMode) Error

func (e ErrInvalidCryptoMode) Error() string

type ErrTopicNotFound

type ErrTopicNotFound struct {
}

ErrTopicNotFound is a database error when a requested record cannot be found A message containing the missing entity type will be returned to the user

func (ErrTopicNotFound) Error

func (e ErrTopicNotFound) Error() string

type ErrValidation

type ErrValidation struct {
	Err error
}

ErrValidation describes an error when validating service's input parameters its Err will get returned to the user

func (ErrValidation) Error

func (e ErrValidation) Error() string

type IDNamePair

type IDNamePair struct {
	ID   []byte
	Name string
}

IDNamePair stores an E4 client ID and names, omitting the key

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL