Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
8900e521
Commit
8900e521
authored
3 years ago
by
Jake Taylor
Browse files
Options
Downloads
Patches
Plain Diff
fix single use integration
parent
8992b2f5
No related branches found
No related tags found
2 merge requests
!510
Release
,
!207
WIP: Client Restructure
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cmd/single.go
+7
-6
7 additions, 6 deletions
cmd/single.go
single/receivedRequest.go
+8
-4
8 additions, 4 deletions
single/receivedRequest.go
with
15 additions
and
10 deletions
cmd/single.go
+
7
−
6
View file @
8900e521
...
@@ -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
.
GetMax
ResponseLength
())
results
.
request
.
GetMax
ContentsSize
())
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
,
maxSize
PerPart
int
)
[]
byte
{
payloads
:=
make
([][]
byte
,
maxParts
)
payloads
:=
make
([][]
byte
,
maxParts
)
payloadPart
:=
makeResponsePayloadPart
(
payload
,
maxSize
)
payloadPart
:=
makeResponsePayloadPart
(
payload
,
maxSize
PerPart
)
for
i
:=
range
payloads
{
for
i
:=
range
payloads
{
payloads
[
i
]
=
make
([]
byte
,
maxSize
)
payloads
[
i
]
=
make
([]
byte
,
maxSize
PerPart
)
copy
(
payloads
[
i
],
payloadPart
)
copy
(
payloads
[
i
],
payloadPart
)
}
}
return
bytes
.
Join
(
payloads
,
[]
byte
{})
return
bytes
.
Join
(
payloads
,
[]
byte
{})
...
...
This diff is collapsed.
Click to expand it.
single/receivedRequest.go
+
8
−
4
View file @
8900e521
...
@@ -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.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment