Skip to content
Snippets Groups Projects
Commit 8900e521 authored by Jake Taylor's avatar Jake Taylor
Browse files

fix single use integration

parent 8992b2f5
No related branches found
No related tags found
2 merge requests!510Release,!207WIP: Client Restructure
...@@ -99,7 +99,7 @@ var singleCmd = &cobra.Command{ ...@@ -99,7 +99,7 @@ var singleCmd = &cobra.Command{
// If the reply flag is set, then start waiting for a // If the reply flag is set, then start waiting for a
// message and reply when it is received // message and reply when it is received
if viper.GetBool("reply") { if viper.GetBool("reply") {
replySingleUse(client, timeout, receiver) replySingleUse(timeout, receiver)
} }
listener.Stop() listener.Stop()
}, },
...@@ -172,6 +172,7 @@ func sendSingleUse(m *api.Client, partner contact.Contact, payload []byte, ...@@ -172,6 +172,7 @@ func sendSingleUse(m *api.Client, partner contact.Contact, payload []byte,
jww.DEBUG.Printf("Sending single-use transmission to %s: %s", jww.DEBUG.Printf("Sending single-use transmission to %s: %s",
partner.ID, payload) partner.ID, payload)
params := single.GetDefaultRequestParams() params := single.GetDefaultRequestParams()
params.MaxResponseMessages = maxMessages
rng := m.GetRng().GetStream() rng := m.GetRng().GetStream()
defer rng.Close() defer rng.Close()
...@@ -202,7 +203,7 @@ func sendSingleUse(m *api.Client, partner contact.Contact, payload []byte, ...@@ -202,7 +203,7 @@ func sendSingleUse(m *api.Client, partner contact.Contact, payload []byte,
// replySingleUse responds to any single-use message it receives by replying\ // replySingleUse responds to any single-use message it receives by replying\
// with the same payload. // with the same payload.
func replySingleUse(m *api.Client, timeout time.Duration, receiver *Receiver) { func replySingleUse(timeout time.Duration, receiver *Receiver) {
// Wait to receive a message or stop after timeout occurs // Wait to receive a message or stop after timeout occurs
fmt.Println("Waiting for single-use message.") fmt.Println("Waiting for single-use message.")
timer := time.NewTimer(timeout) timer := time.NewTimer(timeout)
...@@ -220,7 +221,7 @@ func replySingleUse(m *api.Client, timeout time.Duration, receiver *Receiver) { ...@@ -220,7 +221,7 @@ func replySingleUse(m *api.Client, timeout time.Duration, receiver *Receiver) {
// Create new payload from repeated received payloads so that each // Create new payload from repeated received payloads so that each
// message part contains the same payload // message part contains the same payload
resPayload := makeResponsePayload(payload, results.request.GetMaxParts(), resPayload := makeResponsePayload(payload, results.request.GetMaxParts(),
results.request.GetMaxResponseLength()) results.request.GetMaxContentsSize())
fmt.Printf("Sending single-use response message: %s\n", payload) fmt.Printf("Sending single-use response message: %s\n", payload)
jww.DEBUG.Printf("Sending single-use response to %s: %s", jww.DEBUG.Printf("Sending single-use response to %s: %s",
...@@ -264,11 +265,11 @@ func (r *Receiver) Callback(req *single.Request, ephID receptionID.EphemeralIden ...@@ -264,11 +265,11 @@ func (r *Receiver) Callback(req *single.Request, ephID receptionID.EphemeralIden
// makeResponsePayload generates a new payload that will span the max number of // makeResponsePayload generates a new payload that will span the max number of
// message parts in the contact. Each resulting message payload will contain a // message parts in the contact. Each resulting message payload will contain a
// copy of the supplied payload with spaces taking up any remaining data. // copy of the supplied payload with spaces taking up any remaining data.
func makeResponsePayload(payload []byte, maxParts uint8, maxSize int) []byte { func makeResponsePayload(payload []byte, maxParts uint8, maxSizePerPart int) []byte {
payloads := make([][]byte, maxParts) payloads := make([][]byte, maxParts)
payloadPart := makeResponsePayloadPart(payload, maxSize) payloadPart := makeResponsePayloadPart(payload, maxSizePerPart)
for i := range payloads { for i := range payloads {
payloads[i] = make([]byte, maxSize) payloads[i] = make([]byte, maxSizePerPart)
copy(payloads[i], payloadPart) copy(payloads[i], payloadPart)
} }
return bytes.Join(payloads, []byte{}) return bytes.Join(payloads, []byte{})
......
...@@ -47,12 +47,16 @@ func (r Request) GetMaxParts() uint8 { ...@@ -47,12 +47,16 @@ func (r Request) GetMaxParts() uint8 {
return r.maxParts return r.maxParts
} }
// GetMaxResponseLength returns the maximum total payload size, which is the
// maximum size of each individual part multiplied by the maximum number of parts
func (r Request) GetMaxResponseLength() int { func (r Request) GetMaxResponseLength() int {
responseMsg := message.NewResponsePart(r.net.GetMaxMessageLength()) return r.GetMaxContentsSize() * int(r.GetMaxParts())
}
// Maximum payload size is the maximum amount of room in each message // GetMaxContentsSize returns maximum payload size for an individual part
// multiplied by the number of messages func (r Request) GetMaxContentsSize() int {
return responseMsg.GetMaxContentsSize() * int(r.GetMaxParts()) responseMsg := message.NewResponsePart(r.net.GetMaxMessageLength())
return responseMsg.GetMaxContentsSize()
} }
// GetPartner returns a copy of the sender ID. // GetPartner returns a copy of the sender ID.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment