Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,9 @@ func (c *Client) getInteractions(callback InteractionCallback) error {

// handle root-tld data if any
for _, data := range response.TLDData {
if len(data) == 0 {
continue
}
interaction := &server.Interaction{}
if err := jsoniter.UnmarshalFromString(data, interaction); err != nil {
gologger.Error().Msgf("Could not unmarshal interaction data interaction: %v\n", err)
Expand Down
31 changes: 25 additions & 6 deletions pkg/storage/storagedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,18 @@ func (s *StorageDB) SetIDPublicKey(correlationID, secretKey, publicKey string) e

func (s *StorageDB) SetID(ID string) error {
data := &CorrelationData{}

s.cache.Put(ID, data)
return nil
}

// AddInteraction adds an interaction data to the correlation ID after encrypting
// it with Public Key for the provided correlation ID.
func (s *StorageDB) AddInteraction(correlationID string, data []byte) error {
if len(data) == 0 {
return nil
}

item, found := s.cache.GetIfPresent(correlationID)
if !found {
return ErrCorrelationIdNotFound
Expand All @@ -137,10 +142,15 @@ func (s *StorageDB) AddInteraction(correlationID string, data []byte) error {
}

if s.Options.UseDisk() {
ct, err := AESEncrypt(value.AESKey, data)
if err != nil {
return errors.Wrap(err, "could not encrypt event data")
ct := string(data)
if len(value.AESKey) > 0 {
var err error
ct, err = AESEncrypt(value.AESKey, data)
if err != nil {
return errors.Wrap(err, "could not encrypt event data")
}
}

value.Lock()
existingData, _ := s.db.Get([]byte(correlationID), nil)
_ = s.db.Put([]byte(correlationID), AppendMany("\n", existingData, []byte(ct)), nil)
Expand All @@ -156,6 +166,10 @@ func (s *StorageDB) AddInteraction(correlationID string, data []byte) error {

// AddInteractionWithId adds an interaction data to the id bucket
func (s *StorageDB) AddInteractionWithId(id string, data []byte) error {
if len(data) == 0 {
return nil
}

item, ok := s.cache.GetIfPresent(id)
if !ok {
return ErrCorrelationIdNotFound
Expand All @@ -166,10 +180,15 @@ func (s *StorageDB) AddInteractionWithId(id string, data []byte) error {
}

if s.Options.UseDisk() {
ct, err := AESEncrypt(value.AESKey, data)
if err != nil {
return errors.Wrap(err, "could not encrypt event data")
ct := string(data)
if len(value.AESKey) > 0 {
var err error
ct, err = AESEncrypt(value.AESKey, data)
if err != nil {
return errors.Wrap(err, "could not encrypt event data")
}
}

value.Lock()
existingData, _ := s.db.Get([]byte(id), nil)
_ = s.db.Put([]byte(id), AppendMany("\n", existingData, []byte(ct)), nil)
Expand Down
Loading