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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
0727aad4
Commit
0727aad4
authored
May 25, 2022
by
Benjamin Wenger
Browse files
Options
Downloads
Patches
Plain Diff
finished new bindings
parent
346eddd8
Branches
Branches containing commit
Tags
Tags containing commit
3 merge requests
!510
Release
,
!226
WIP: Api2.0
,
!207
WIP: Client Restructure
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
bindings/autheticatedConnection.go
+1
-1
1 addition, 1 deletion
bindings/autheticatedConnection.go
bindings/connect.go
+1
-1
1 addition, 1 deletion
bindings/connect.go
bindings/contact.go
+108
-17
108 additions, 17 deletions
bindings/contact.go
bindings/delivery.go
+40
-17
40 additions, 17 deletions
bindings/delivery.go
with
150 additions
and
36 deletions
bindings/autheticatedConnection.go
+
1
−
1
View file @
0727aad4
...
...
@@ -28,7 +28,7 @@ func (c *Client) ConnectWithAuthentication(recipientContact []byte, myIdentity [
if
err
!=
nil
{
return
nil
,
err
}
myID
,
rsaPriv
,
salt
,
myDHPriv
,
err
:=
unmarshalIdentity
(
myIdentity
)
myID
,
rsaPriv
,
salt
,
myDHPriv
,
err
:=
c
.
unmarshalIdentity
(
myIdentity
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
This diff is collapsed.
Click to expand it.
bindings/connect.go
+
1
−
1
View file @
0727aad4
...
...
@@ -35,7 +35,7 @@ func (c *Client) Connect(recipientContact []byte, myIdentity []byte) (
if
err
!=
nil
{
return
nil
,
err
}
myID
,
_
,
_
,
myDHPriv
,
err
:=
unmarshalIdentity
(
myIdentity
)
myID
,
_
,
_
,
myDHPriv
,
err
:=
c
.
unmarshalIdentity
(
myIdentity
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
This diff is collapsed.
Click to expand it.
bindings/contact.go
+
108
−
17
View file @
0727aad4
...
...
@@ -2,8 +2,10 @@ package bindings
import
(
"encoding/json"
"gitlab.com/elixxir/crypto/contact"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/diffieHellman"
"gitlab.com/elixxir/primitives/fact"
"gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/crypto/xx"
"gitlab.com/xx_network/primitives/id"
...
...
@@ -16,11 +18,6 @@ type Identity struct {
DHKeyPrivate
[]
byte
}
type
Fact
struct
{
Fact
string
Type
string
}
// MakeIdentity generates a new cryptographic identity for receving
// messages
func
(
c
*
Client
)
MakeIdentity
()
([]
byte
,
error
)
{
...
...
@@ -46,7 +43,11 @@ func (c *Client) MakeIdentity() ([]byte, error) {
//make the ID
id
,
err
:=
xx
.
NewID
(
rsaKey
.
GetPublic
(),
salt
,
id
.
User
)
if
err
!=
nil
{
return
nil
,
err
}
dhPrivJson
,
err
:=
privkey
.
MarshalJSON
()
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -56,35 +57,125 @@ func (c *Client) MakeIdentity() ([]byte, error) {
ID
:
id
.
Marshal
(),
RSAPrivatePem
:
rsa
.
CreatePrivateKeyPem
(
rsaKey
),
Salt
:
salt
,
DHKeyPrivate
:
privkey
.
Bytes
()
,
DHKeyPrivate
:
dhPrivJson
,
}
return
json
.
Marshal
(
&
I
)
}
func
GetContactFromIdentity
(
identity
string
)
[]
byte
{
I
:=
Identity
{}
func
(
c
*
Client
)
GetContactFromIdentity
(
identity
[]
byte
)
([]
byte
,
error
)
{
uID
,
_
,
_
,
dhKey
,
err
:=
c
.
unmarshalIdentity
(
identity
)
if
err
!=
nil
{
return
nil
,
err
}
func
unmarshalIdentity
(
marshaled
[]
byte
)
(
*
id
.
ID
,
*
rsa
.
PrivateKey
,
[]
byte
,
grp
:=
c
.
api
.
GetStorage
()
.
GetE2EGroup
()
dhPub
:=
grp
.
ExpG
(
dhKey
,
grp
.
NewInt
(
1
))
ct
:=
contact
.
Contact
{
ID
:
uID
,
DhPubKey
:
dhPub
,
OwnershipProof
:
nil
,
Facts
:
nil
,
}
return
ct
.
Marshal
(),
nil
}
func
(
c
*
Client
)
unmarshalIdentity
(
marshaled
[]
byte
)
(
*
id
.
ID
,
*
rsa
.
PrivateKey
,
[]
byte
,
*
cyclic
.
Int
,
error
)
{
return
nil
,
nil
,
nil
,
nil
,
nil
I
:=
Identity
{}
err
:=
json
.
Unmarshal
(
marshaled
,
&
I
)
if
err
!=
nil
{
return
nil
,
nil
,
nil
,
nil
,
err
}
uID
,
err
:=
id
.
Unmarshal
(
I
.
ID
)
if
err
!=
nil
{
return
nil
,
nil
,
nil
,
nil
,
err
}
dhkey
:=
c
.
api
.
GetStorage
()
.
GetE2EGroup
()
.
NewInt
(
1
)
err
=
dhkey
.
UnmarshalJSON
(
I
.
DHKeyPrivate
)
if
err
!=
nil
{
return
nil
,
nil
,
nil
,
nil
,
err
}
rsaPriv
,
err
:=
rsa
.
LoadPrivateKeyFromPem
(
I
.
RSAPrivatePem
)
if
err
!=
nil
{
return
nil
,
nil
,
nil
,
nil
,
err
}
return
uID
,
rsaPriv
,
I
.
Salt
,
dhkey
,
nil
}
func
GetIDFromContact
(
marshaled
[]
byte
)
([]
byte
,
error
)
{
cnt
,
err
:=
contact
.
Unmarshal
(
marshaled
)
if
err
!=
nil
{
return
nil
,
err
}
return
cnt
.
ID
.
Marshal
(),
nil
}
func
GetPubkeyFromContact
(
marshaled
[]
byte
)
([]
byte
,
error
)
{
cnt
,
err
:=
contact
.
Unmarshal
(
marshaled
)
if
err
!=
nil
{
return
nil
,
err
}
return
cnt
.
ID
.
Marshal
(),
nil
}
type
Fact
struct
{
Fact
string
Type
int
}
// SetFactsOnContact replaces the facts on the contact with the passed in facts
// pass in empty facts in order to clear the facts
func
SetFactsOnContact
(
contact
[]
byte
,
facts
[]
byte
)
[]
byte
{
I
:=
Identity
{}
func
SetFactsOnContact
(
marshaled
[]
byte
,
facts
[]
byte
)
([]
byte
,
error
)
{
cnt
,
err
:=
contact
.
Unmarshal
(
marshaled
)
if
err
!=
nil
{
return
nil
,
err
}
func
GetIDFromContact
(
contact
[]
byte
)
[]
byte
{
factsList
:=
make
([]
Fact
,
0
)
err
=
json
.
Unmarshal
(
facts
,
&
factsList
)
if
err
!=
nil
{
return
nil
,
err
}
realFactList
:=
make
(
fact
.
FactList
,
0
,
len
(
factsList
))
for
i
:=
range
factsList
{
realFactList
=
append
(
realFactList
,
fact
.
Fact
{
Fact
:
factsList
[
i
]
.
Fact
,
T
:
fact
.
FactType
(
factsList
[
i
]
.
Type
),
})
}
func
GetPubkeyFromContact
(
contact
[]
byte
)
[]
byte
{
cnt
.
Facts
=
realFactList
return
cnt
.
Marshal
(),
nil
}
func
GetFactsFromContact
(
marshaled
[]
byte
)
([]
byte
,
error
)
{
cnt
,
err
:=
contact
.
Unmarshal
(
marshaled
)
if
err
!=
nil
{
return
nil
,
err
}
func
GetFactsFromContact
(
contact
[]
byte
)
[]
byte
{
factsList
:=
make
([]
Fact
,
len
(
cnt
.
Facts
))
for
i
:=
range
cnt
.
Facts
{
factsList
=
append
(
factsList
,
Fact
{
Fact
:
cnt
.
Facts
[
i
]
.
Fact
,
Type
:
int
(
cnt
.
Facts
[
i
]
.
T
),
})
}
factsListMarshaled
,
err
:=
json
.
Marshal
(
&
factsList
)
if
err
!=
nil
{
return
nil
,
err
}
return
factsListMarshaled
,
nil
}
This diff is collapsed.
Click to expand it.
bindings/delivery.go
+
40
−
17
View file @
0727aad4
package
bindings
import
(
"encoding/json"
"fmt"
"github.com/pkg/errors"
jww
"github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/cmix"
"gitlab.com/xx_network/primitives/id"
"time"
)
type
roundsList
struct
{
rounds
[]
int
type
roundsList
[]
int
func
(
rl
roundsList
)
Marshal
()
([]
byte
,
error
)
{
return
json
.
Marshal
(
&
rl
)
}
func
unmarshalRoundsList
(
marshaled
[]
byte
)
([]
id
.
Round
,
error
)
{
rl
:=
roundsList
{}
err
:=
json
.
Unmarshal
(
marshaled
,
&
rl
)
if
err
!=
nil
{
return
nil
,
err
}
func
(
rl
roundsList
)
Marshal
()
[]
byte
{
realRl
:=
make
([]
id
.
Round
,
len
(
rl
))
for
_
,
rid
:=
range
rl
{
realRl
=
append
(
realRl
,
id
.
Round
(
rid
))
}
func
unmarshalRoundsList
(
marshaled
[]
byte
)
[]
id
.
Round
{
return
realRl
,
nil
}
func
makeRoundsList
(
rounds
[]
id
.
Round
)
roundsList
{
rl
:=
make
(
roundsList
,
0
,
len
(
rounds
))
for
_
,
rid
:=
range
rounds
{
rl
=
append
(
rl
,
int
(
rid
))
}
return
rl
}
// MessageDeliveryCallback gets called on the determination if all events
// related to a message send were successful.
type
MessageDeliveryCallback
interface
{
EventCallback
(
delivered
,
timedOut
bool
,
roundResults
[]
byte
)
}
// WaitForMessageDelivery allows the caller to get notified if the rounds a
...
...
@@ -34,39 +57,39 @@ func makeRoundsList(rounds []id.Round) roundsList {
// This function takes the marshaled send report to ensure a memory leak does
// not occur as a result of both sides of the bindings holding a reference to
// the same pointer.
func
(
c
*
Client
)
WaitForMessageDelivery
(
marshaledSendRepor
t
[]
byte
,
func
(
c
*
Client
)
WaitForMessageDelivery
(
roundLis
t
[]
byte
,
mdc
MessageDeliveryCallback
,
timeoutMS
int
)
error
{
jww
.
INFO
.
Printf
(
"WaitForMessageDelivery(%v, _, %v)"
,
marshaledSendRepor
t
,
timeoutMS
)
s
r
,
err
:=
U
nmarshal
SendReport
(
marshaledSendRepor
t
)
roundLis
t
,
timeoutMS
)
r
l
,
err
:=
u
nmarshal
RoundsList
(
roundLis
t
)
if
err
!=
nil
{
return
errors
.
New
(
fmt
.
Sprintf
(
"Failed to "
+
"WaitForMessageDelivery callback due to bad Send Report: %+v"
,
err
))
}
if
sr
==
nil
||
sr
.
rl
==
nil
||
len
(
sr
.
rl
.
list
)
==
0
{
if
rl
==
nil
||
len
(
rl
)
==
0
{
return
errors
.
New
(
fmt
.
Sprintf
(
"Failed to "
+
"WaitForMessageDelivery callback due to invalid Send Report "
+
"unmarshal: %s"
,
string
(
marshaledSendRepor
t
)))
"unmarshal: %s"
,
string
(
roundLis
t
)))
}
f
:=
func
(
allRoundsSucceeded
,
timedOut
bool
,
rounds
map
[
id
.
Round
]
cmix
.
Round
LookupStatus
)
{
results
:=
make
([]
byte
,
len
(
sr
.
rl
.
list
))
f
:=
func
(
allRoundsSucceeded
,
timedOut
bool
,
rounds
map
[
id
.
Round
]
cmix
.
Round
Result
)
{
results
:=
make
([]
byte
,
len
(
rl
))
jww
.
INFO
.
Printf
(
"Processing WaitForMessageDelivery report "
+
"
for %v,
success: %v, timedout: %v"
,
sr
.
mid
,
allRoundsSucceeded
,
"success: %v, timedout: %v"
,
allRoundsSucceeded
,
timedOut
)
for
i
,
r
:=
range
sr
.
rl
.
list
{
for
i
,
r
:=
range
rl
{
if
result
,
exists
:=
rounds
[
r
];
exists
{
results
[
i
]
=
byte
(
result
)
results
[
i
]
=
byte
(
result
.
Status
)
}
}
mdc
.
EventCallback
(
sr
.
mid
.
Marshal
(),
allRoundsSucceeded
,
timedOut
,
results
)
mdc
.
EventCallback
(
allRoundsSucceeded
,
timedOut
,
results
)
}
timeout
:=
time
.
Duration
(
timeoutMS
)
*
time
.
Millisecond
err
=
c
.
api
.
GetRoundResults
(
sr
.
rl
.
list
,
timeout
,
f
)
err
=
c
.
api
.
GetCmix
()
.
GetRoundResults
(
timeout
,
f
,
rl
...
)
return
err
}
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