single

package
v5.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2022 License: BSD-2-Clause, BSD-2-Clause Imports: 29 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetMaxRequestSize

func GetMaxRequestSize(net Cmix, e2eGrp *cyclic.Group) int

GetMaxRequestSize returns the maximum size of a request payload.

func TransmitRequest

func TransmitRequest(recipient contact.Contact, tag string, payload []byte,
	responseCB Response, params RequestParams, net Cmix, rng csprng.Source,
	e2eGrp *cyclic.Group) ([]id.Round, receptionID.EphemeralIdentity, error)

TransmitRequest sends a request to the recipient with the given tag containing the given payload. The request is identified as coming from a new user ID and the recipient of the request responds to that address. As a result, this request does not reveal the identity of the sender.

The current implementation allows for up to maxNumRequestParts cMix request payloads. GetMaxRequestSize can be used to get the max size.

The network follower must be running and healthy to transmit.

Types

type Cmix

type Cmix interface {
	IsHealthy() bool
	GetAddressSpace() uint8
	GetMaxMessageLength() int
	DeleteClientFingerprints(identity *id.ID)
	AddFingerprint(identity *id.ID, fingerprint format.Fingerprint,
		mp message.Processor) error
	AddIdentity(id *id.ID, validUntil time.Time, persistent bool)
	Send(recipient *id.ID, fingerprint format.Fingerprint,
		service message.Service, payload, mac []byte, cmixParams cmix.CMIXParams) (
		rounds.Round, ephemeral.Id, error)
	AddService(clientID *id.ID, newService message.Service,
		response message.Processor)
	DeleteService(clientID *id.ID, toDelete message.Service,
		processor message.Processor)
	GetInstance() *network.Instance
	CheckInProgressMessages()
}

Cmix is a sub-interface of the cmix.Client. It contains the methods relevant to what is used in this package.

type ListenCmix

type ListenCmix interface {
	RequestCmix
	AddFingerprint(identity *id.ID, fingerprint format.Fingerprint,
		mp cMixMsg.Processor) error
	AddService(
		clientID *id.ID, newService cMixMsg.Service, response cMixMsg.Processor)
	DeleteService(
		clientID *id.ID, toDelete cMixMsg.Service, processor cMixMsg.Processor)
	CheckInProgressMessages()
}

ListenCmix interface matches a subset of cmix.Client methods used for Listen.

type Listener

type Listener interface {
	// Stop unregisters the listener
	Stop()
}

func Listen

func Listen(tag string, myID *id.ID, privKey *cyclic.Int, net ListenCmix,
	e2eGrp *cyclic.Group, cb Receiver) Listener

Listen allows a server to listen for single use requests. It will register a service relative to the tag and myID as the identifier. Only a single listener can be active for a tag-myID pair, and an error will be returned if that is violated. When requests are received, they will be called on the Receiver interface.

type Receiver

type Receiver interface {
	Callback(*Request, receptionID.EphemeralIdentity, []rounds.Round)
}

Receiver contains the callback interface for any handler which will process the reception of a single request. Used in Listen.

type Request

type Request struct {
	// contains filtered or unexported fields
}

Request contains the information contained in a single-use request message.

func BuildTestRequest

func BuildTestRequest(payload []byte, _ testing.TB) *Request

BuildTestRequest can be used for mocking a Request. Should only be used for tests.

func (*Request) GetMaxParts

func (r *Request) GetMaxParts() uint8

GetMaxParts returns the maximum number of messages allowed to send in the reply.

func (*Request) GetMaxResponseLength

func (r *Request) GetMaxResponseLength() int

GetMaxResponseLength returns the maximum size of the entire response message.

func (*Request) GetMaxResponsePartSize

func (r *Request) GetMaxResponsePartSize() int

GetMaxResponsePartSize returns maximum payload size for an individual part of the response message.

func (*Request) GetPartner

func (r *Request) GetPartner() *id.ID

GetPartner returns a copy of the sender ID.

func (*Request) GetPayload

func (r *Request) GetPayload() []byte

GetPayload returns the payload that came in the request

func (*Request) GetTag

func (r *Request) GetTag() string

GetTag returns the tag for the request.

func (*Request) GoString

func (r *Request) GoString() string

GoString returns string showing the values of all the fields of Request. Adheres to the fmt.GoStringer interface.

func (*Request) Respond

func (r *Request) Respond(payload []byte, cMixParams cmix.CMIXParams,
	timeout time.Duration) ([]id.Round, error)

Respond is used to respond to the request. It sends a payload up to Request.GetMaxResponseLength. It will chunk the message into multiple cMix messages if it is too long for a single message. It will fail if a single cMix message cannot be sent.

type RequestCmix

type RequestCmix interface {
	GetMaxMessageLength() int
	Send(recipient *id.ID, fingerprint format.Fingerprint,
		service cMixMsg.Service, payload, mac []byte,
		cmixParams cmix.CMIXParams) (rounds.Round, ephemeral.Id, error)
	GetInstance() *network.Instance
}

RequestCmix interface matches a subset of the cmix.Client methods used by the Request for easier testing.

type RequestParams

type RequestParams struct {
	// Timeout is the duration to wait before timing out while sending a request
	Timeout time.Duration

	// MaxResponseMessages is the maximum number of messages allowed in the
	// response to the request
	MaxResponseMessages uint8

	// CmixParams is the parameters used in sending a cMix message
	CmixParams cmix.CMIXParams
}

RequestParams contains configurable parameters for sending a single-use request message.

func GetDefaultRequestParams

func GetDefaultRequestParams() RequestParams

GetDefaultRequestParams returns a RequestParams with the default configuration.

func GetParameters

func GetParameters(params string) (RequestParams, error)

GetParameters returns the default network parameters, or override with given parameters, if set.

func (RequestParams) MarshalJSON

func (rp RequestParams) MarshalJSON() ([]byte, error)

MarshalJSON adheres to the json.Marshaler interface.

func (*RequestParams) UnmarshalJSON

func (rp *RequestParams) UnmarshalJSON(data []byte) error

UnmarshalJSON adheres to the json.Unmarshaler interface.

type Response

type Response interface {
	Callback(payload []byte, receptionID receptionID.EphemeralIdentity,
		rounds []rounds.Round, err error)
}

Response contains the callback interface for any handler which will process the response of a single request. Used in TransmitRequest.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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