Select Git revision
request.go 12.38 KiB
package single
import (
"bytes"
"github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/cmix"
"gitlab.com/elixxir/client/cmix/identity/receptionID"
cmixMsg "gitlab.com/elixxir/client/cmix/message"
"gitlab.com/elixxir/client/cmix/rounds"
"gitlab.com/elixxir/client/single/message"
"gitlab.com/elixxir/crypto/contact"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/e2e/auth"
"gitlab.com/elixxir/crypto/e2e/singleUse"
"gitlab.com/xx_network/crypto/csprng"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id/ephemeral"
"gitlab.com/xx_network/primitives/netTime"
"io"
"sync"
"sync/atomic"
"time"
)
// Error messages.
const (
// TransmitRequest
errPayloadSize = "size of payload %d exceeds the maximum size of %d (%s for %s)"
errNetworkHealth = "cannot send singe-use request when the network is not healthy"
errMakeDhKeys = "failed to generate DH keys (%s for %s): %+v"
errMakeIDs = "failed to generate IDs (%s for %s): %+v"
errAddFingerprint = "failed to add fingerprint %d of %d: %+v (%s for %s)"
errSendRequest = "failed to send %s request to %s: %+v"
errSendRequestPart = "%d requests failed to send, the request will be handleable and will time out"
// generateDhKeys
errGenerateInGroup = "failed to generate private key in group: %+v"
// makeIDs
errMakeNonce = "failed to generate nonce: %+v"
errNewEphemeralID = "failed to generate address ID from newly generated ID: %+v"
// waitForTimeout
errResponseTimeout = "waiting for response to single-use request timed out after %s"
)
// Maximum number of request part cMix messages.
const maxNumRequestParts = 255
// GetMaxRequestSize returns the maximum size of a request payload.
func GetMaxRequestSize(net Cmix, e2eGrp *cyclic.Group) int {
payloadSize := message.GetRequestPayloadSize(
net.GetMaxMessageLength(), e2eGrp.GetP().ByteLen())
requestSize := message.GetRequestContentsSize(payloadSize)
requestPartSize := message.GetRequestPartContentsSize(
net.GetMaxMessageLength())
return requestSize + (maxNumRequestParts * requestPartSize)
}
/* Single is a system which allows for an end-to-end encrypted anonymous request
to be sent to another cMix client, and for them to respond. The system allows
for communication over the mixnet without an interactive key negotiation
because the payload inherently carries the negotiation with it. When sending
a new request, a client create a new discreet log DH keypair as well as a new
ID. As a result of the fact that the client never identifies itself, the
system allows the client to stay anonymous while contacting the remote.
*/
// TransmitRequest sends a request to the recipient with the given tag