Skip to content
Snippets Groups Projects
Select Git revision
  • ab9e8a09ceca64fddd92cdf1e07ac0210d466350
  • release default protected
  • 11-22-implement-kv-interface-defined-in-collectiveversionedkvgo
  • hotfix/TestHostPool_UpdateNdf_AddFilter
  • XX-4719/announcementChannels
  • xx-4717/logLevel
  • jonah/noob-channel
  • master protected
  • XX-4707/tagDiskJson
  • xx-4698/notification-retry
  • hotfix/notifylockup
  • syncNodes
  • hotfix/localCB
  • XX-4677/NewChanManagerMobile
  • XX-4689/DmSync
  • duplicatePrefix
  • XX-4601/HavenInvites
  • finalizedUICallbacks
  • XX-4673/AdminKeySync
  • debugNotifID
  • anne/test
  • v4.7.5
  • v4.7.4
  • v4.7.3
  • v4.7.2
  • v4.7.1
  • v4.6.3
  • v4.6.1
  • v4.5.0
  • v4.4.4
  • v4.3.11
  • v4.3.8
  • v4.3.7
  • v4.3.6
  • v4.3.5
  • v4.2.0
  • v4.3.0
  • v4.3.4
  • v4.3.3
  • v4.3.2
  • v4.3.1
41 results

garbled.go

Blame
  • garbled.go 2.89 KiB
    ///////////////////////////////////////////////////////////////////////////////
    // Copyright © 2020 xx network SEZC                                          //
    //                                                                           //
    // Use of this source code is governed by a license that can be found in the //
    // LICENSE file                                                              //
    ///////////////////////////////////////////////////////////////////////////////
    
    package message
    
    import (
    	"gitlab.com/elixxir/client/interfaces/message"
    	"gitlab.com/elixxir/primitives/format"
    	"time"
    )
    
    // Messages can arrive in the network out of order. When message handling fails
    // to decrypt a message, it is added to the garbled message buffer (which is
    // stored on disk) and the message decryption is retried here whenever triggered.
    
    // This can be triggered through the CheckGarbledMessages on the network manager
    // and is used in the /keyExchange package on successful rekey triggering
    
    // Triggers Garbled message checking if the queue is not full
    // Exposed on the network manager
    func (m *Manager) CheckGarbledMessages() {
    	select {
    	case m.triggerGarbled <- struct{}{}:
    	default:
    	}
    }
    
    //long running thread which processes garbled messages
    func (m *Manager) processGarbledMessages(quitCh <-chan struct{}) {
    	done := false
    	for !done {
    		select {
    		case <-quitCh:
    			done = true
    		case <-m.triggerGarbled:
    			m.handleGarbledMessages()
    		}
    	}
    }
    
    //handler for a single run of garbled messages
    func (m *Manager) handleGarbledMessages() {
    	garbledMsgs := m.Session.GetGarbledMessages()
    	e2eKv := m.Session.E2e()
    	var failedMsgs []format.Message
    	//try to decrypt every garbled message, excising those who's counts are too high
    	for grbldMsg, count, timestamp, has := garbledMsgs.Next(); has; grbldMsg, count, timestamp, has = garbledMsgs.Next() {
    		fingerprint := grbldMsg.GetKeyFP()
    		// Check if the key is there, process it if it is
    		if key, isE2E := e2eKv.PopKey(fingerprint); isE2E {
    			// Decrypt encrypted message
    			msg, err := key.Decrypt(grbldMsg)
    			if err == nil {
    				// get the sender
    				sender := key.GetSession().GetPartner()
    				//remove from the buffer if decryption is successful
    				garbledMsgs.Remove(grbldMsg)
    				//handle the successfully decrypted message
    				xxMsg, ok := m.partitioner.HandlePartition(sender, message.E2E,
    					msg.GetContents(),
    					key.GetSession().GetRelationshipFingerprint())
    				if ok {
    					m.Switchboard.Speak(xxMsg)
    					continue
    				}
    			}