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

utils_test.go

Blame
  • send.go 3.37 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 api
    
    import (
    	"time"
    
    	"github.com/pkg/errors"
    	jww "github.com/spf13/jwalterweatherman"
    	"gitlab.com/elixxir/client/catalog"
    	"gitlab.com/elixxir/client/cmix"
    	"gitlab.com/elixxir/client/cmix/message"
    	"gitlab.com/elixxir/client/e2e"
    	e2eCrypto "gitlab.com/elixxir/crypto/e2e"
    	"gitlab.com/elixxir/primitives/format"
    	"gitlab.com/xx_network/primitives/id"
    	"gitlab.com/xx_network/primitives/id/ephemeral"
    )
    
    //This holds all functions to send messages over the network
    
    // SendE2E sends an end-to-end payload to the provided recipient with
    // the provided msgType. Returns the list of rounds in which parts of
    // the message were sent or an error if it fails.
    func (c *Client) SendE2E(mt catalog.MessageType, recipient *id.ID,
    	payload []byte, param e2e.Params) ([]id.Round,
    	e2eCrypto.MessageID, time.Time, error) {
    	jww.INFO.Printf("SendE2E(%s, %d. %v)", recipient,
    		mt, payload)
    	return c.e2e.SendE2E(mt, recipient, payload, param)
    }
    
    // SendUnsafe sends an unencrypted payload to the provided recipient
    // with the provided msgType. Returns the list of rounds in which parts
    // of the message were sent or an error if it fails.
    // NOTE: Do not use this function unless you know what you are doing.
    // This function always produces an error message in client logging.
    func (c *Client) SendUnsafe(mt catalog.MessageType, recipient *id.ID,
    	payload []byte, param e2e.Params) ([]id.Round, time.Time,
    	error) {
    	jww.INFO.Printf("SendUnsafe(%s, %d. %v)", recipient,
    		mt, payload)
    	return c.e2e.SendUnsafe(mt, recipient, payload, param)
    }
    
    // SendCMIX sends a "raw" CMIX message payload to the provided
    // recipient. Note that both SendE2E and SendUnsafe call SendCMIX.
    // Returns the round ID of the round the payload was sent or an error
    // if it fails.
    func (c *Client) SendCMIX(msg format.Message, recipientID *id.ID,
    	param cmix.CMIXParams) (id.Round, ephemeral.Id, error) {
    	jww.INFO.Printf("Send(%s)", string(msg.GetContents()))
    	return c.network.Send(recipientID, msg.GetKeyFP(),
    		message.GetDefaultService(recipientID),
    		msg.GetContents(), msg.GetMac(), param)
    }
    
    // SendManyCMIX sends many "raw" CMIX message payloads to each of the
    // provided recipients. Used for group chat functionality. Returns the
    // round ID of the round the payload was sent or an error if it fails.
    func (c *Client) SendManyCMIX(messages []cmix.TargetedCmixMessage,
    	params cmix.CMIXParams) (id.Round, []ephemeral.Id, error) {
    	return c.network.SendMany(messages, params)
    }
    
    // NewCMIXMessage Creates a new cMix message with the right properties
    // for the current cMix network.
    // FIXME: this is weird and shouldn't be necessary, but it is.
    func (c *Client) NewCMIXMessage(contents []byte) (format.Message, error) {
    	primeSize := len(c.storage.GetCmixGroup().GetPBytes())
    	msg := format.NewMessage(primeSize)
    	if len(contents) > msg.ContentsSize() {
    		return format.Message{}, errors.New("Contents to long for cmix")
    	}
    	msg.SetContents(contents)
    	return msg, nil
    }