Skip to content
Snippets Groups Projects
Select Git revision
  • 61d09121be6d04323f20652a0ed89f54eea1ec29
  • 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

multi.go

Blame
  • processor.go 2.25 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 broadcast
    
    import (
    	"encoding/binary"
    	jww "github.com/spf13/jwalterweatherman"
    	"gitlab.com/elixxir/client/cmix/identity/receptionID"
    	"gitlab.com/elixxir/client/cmix/rounds"
    	crypto "gitlab.com/elixxir/crypto/broadcast"
    	"gitlab.com/elixxir/primitives/format"
    )
    
    // Error messages.
    const (
    	errDecrypt = "[BCAST] Failed to decrypt payload for broadcast %s (%q): %+v"
    )
    
    // processor struct for message handling
    type processor struct {
    	c      *crypto.Channel
    	cb     ListenerFunc
    	method Method
    }
    
    // Process decrypts the broadcast message and sends the results on the callback.
    func (p *processor) Process(msg format.Message,
    	receptionID receptionID.EphemeralIdentity, round rounds.Round) {
    
    	var payload []byte
    	var err error
    	switch p.method {
    	case Asymmetric:
    		encPartSize := p.c.RsaPubKey.Size()               // Size returned by multicast RSA encryption
    		encodedMessage := msg.GetContents()[:encPartSize] // Only one message is encoded, rest of it is random data
    		decodedMessage, decryptErr := p.c.DecryptAsymmetric(encodedMessage)
    		if decryptErr != nil {
    			jww.ERROR.Printf(errDecrypt, p.c.ReceptionID, p.c.Name, decryptErr)
    			return
    		}
    		size := binary.BigEndian.Uint16(decodedMessage[:internalPayloadSizeLength])
    		payload = decodedMessage[internalPayloadSizeLength : size+internalPayloadSizeLength]
    
    	case Symmetric:
    		payload, err = p.c.DecryptSymmetric(msg.GetContents(), msg.GetMac(), msg.GetKeyFP())
    		if err != nil {
    			jww.ERROR.Printf(errDecrypt, p.c.ReceptionID, p.c.Name, err)
    			return
    		}
    	default:
    		jww.ERROR.Printf("Unrecognized broadcast method %d", p.method)
    	}
    
    	go p.cb(payload, receptionID, round)
    }
    
    // String returns a string identifying the symmetricProcessor for debugging purposes.
    func (p *processor) String() string {
    	return "broadcastChannel-" + p.c.Name
    }