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
0727aad4
Commit
0727aad4
authored
2 years ago
by
Benjamin Wenger
Browse files
Options
Downloads
Patches
Plain Diff
finished new bindings
parent
346eddd8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
3 merge requests
!510
Release
,
!226
WIP: Api2.0
,
!207
WIP: Client Restructure
Changes
4
Hide 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 [
...
@@ -28,7 +28,7 @@ func (c *Client) ConnectWithAuthentication(recipientContact []byte, myIdentity [
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
myID
,
rsaPriv
,
salt
,
myDHPriv
,
err
:=
unmarshalIdentity
(
myIdentity
)
myID
,
rsaPriv
,
salt
,
myDHPriv
,
err
:=
c
.
unmarshalIdentity
(
myIdentity
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
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) (
...
@@ -35,7 +35,7 @@ func (c *Client) Connect(recipientContact []byte, myIdentity []byte) (
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
myID
,
_
,
_
,
myDHPriv
,
err
:=
unmarshalIdentity
(
myIdentity
)
myID
,
_
,
_
,
myDHPriv
,
err
:=
c
.
unmarshalIdentity
(
myIdentity
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
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
...
@@ -2,8 +2,10 @@ package bindings
import
(
import
(
"encoding/json"
"encoding/json"
"gitlab.com/elixxir/crypto/contact"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/diffieHellman"
"gitlab.com/elixxir/crypto/diffieHellman"
"gitlab.com/elixxir/primitives/fact"
"gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/crypto/xx"
"gitlab.com/xx_network/crypto/xx"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id"
...
@@ -16,11 +18,6 @@ type Identity struct {
...
@@ -16,11 +18,6 @@ type Identity struct {
DHKeyPrivate
[]
byte
DHKeyPrivate
[]
byte
}
}
type
Fact
struct
{
Fact
string
Type
string
}
// MakeIdentity generates a new cryptographic identity for receving
// MakeIdentity generates a new cryptographic identity for receving
// messages
// messages
func
(
c
*
Client
)
MakeIdentity
()
([]
byte
,
error
)
{
func
(
c
*
Client
)
MakeIdentity
()
([]
byte
,
error
)
{
...
@@ -46,7 +43,11 @@ func (c *Client) MakeIdentity() ([]byte, error) {
...
@@ -46,7 +43,11 @@ func (c *Client) MakeIdentity() ([]byte, error) {
//make the ID
//make the ID
id
,
err
:=
xx
.
NewID
(
rsaKey
.
GetPublic
(),
id
,
err
:=
xx
.
NewID
(
rsaKey
.
GetPublic
(),
salt
,
id
.
User
)
salt
,
id
.
User
)
if
err
!=
nil
{
return
nil
,
err
}
dhPrivJson
,
err
:=
privkey
.
MarshalJSON
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -56,35 +57,125 @@ func (c *Client) MakeIdentity() ([]byte, error) {
...
@@ -56,35 +57,125 @@ func (c *Client) MakeIdentity() ([]byte, error) {
ID
:
id
.
Marshal
(),
ID
:
id
.
Marshal
(),
RSAPrivatePem
:
rsa
.
CreatePrivateKeyPem
(
rsaKey
),
RSAPrivatePem
:
rsa
.
CreatePrivateKeyPem
(
rsaKey
),
Salt
:
salt
,
Salt
:
salt
,
DHKeyPrivate
:
privkey
.
Bytes
()
,
DHKeyPrivate
:
dhPrivJson
,
}
}
return
json
.
Marshal
(
&
I
)
return
json
.
Marshal
(
&
I
)
}
}
func
GetContactFromIdentity
(
identity
string
)
[]
byte
{
func
(
c
*
Client
)
GetContactFromIdentity
(
identity
[]
byte
)
([]
byte
,
error
)
{
I
:=
Identity
{}
uID
,
_
,
_
,
dhKey
,
err
:=
c
.
unmarshalIdentity
(
identity
)
if
err
!=
nil
{
return
nil
,
err
}
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
unmarshalIdentity
(
marshaled
[]
byte
)
(
*
id
.
ID
,
*
rsa
.
PrivateKey
,
[]
byte
,
func
(
c
*
Client
)
unmarshalIdentity
(
marshaled
[]
byte
)
(
*
id
.
ID
,
*
rsa
.
PrivateKey
,
[]
byte
,
*
cyclic
.
Int
,
error
)
{
*
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
}
}
// SetFactsOnContact replaces the facts on the contact with the passed in facts
func
GetIDFromContact
(
marshaled
[]
byte
)
([]
byte
,
error
)
{
// pass in empty facts in order to clear the facts
cnt
,
err
:=
contact
.
Unmarshal
(
marshaled
)
func
SetFactsOnContact
(
contact
[]
byte
,
facts
[]
byte
)
[]
byte
{
if
err
!=
nil
{
I
:=
Identity
{}
return
nil
,
err
}
return
cnt
.
ID
.
Marshal
(),
nil
}
}
func
GetIDFromContact
(
contact
[]
byte
)
[]
byte
{
func
GetPubkeyFromContact
(
marshaled
[]
byte
)
([]
byte
,
error
)
{
cnt
,
err
:=
contact
.
Unmarshal
(
marshaled
)
if
err
!=
nil
{
return
nil
,
err
}
return
cnt
.
ID
.
Marshal
(),
nil
}
}
func
GetPubkeyFromContact
(
contact
[]
byte
)
[]
byte
{
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
(
marshaled
[]
byte
,
facts
[]
byte
)
([]
byte
,
error
)
{
cnt
,
err
:=
contact
.
Unmarshal
(
marshaled
)
if
err
!=
nil
{
return
nil
,
err
}
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
),
})
}
cnt
.
Facts
=
realFactList
return
cnt
.
Marshal
(),
nil
}
}
func
GetFactsFromContact
(
contact
[]
byte
)
[]
byte
{
func
GetFactsFromContact
(
marshaled
[]
byte
)
([]
byte
,
error
)
{
cnt
,
err
:=
contact
.
Unmarshal
(
marshaled
)
if
err
!=
nil
{
return
nil
,
err
}
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
package
bindings
import
(
import
(
"encoding/json"
"fmt"
"fmt"
"github.com/pkg/errors"
jww
"github.com/spf13/jwalterweatherman"
jww
"github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/cmix"
"gitlab.com/elixxir/client/cmix"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id"
"time"
"time"
)
)
type
roundsList
struct
{
type
roundsList
[]
int
rounds
[]
int
func
(
rl
roundsList
)
Marshal
()
([]
byte
,
error
)
{
return
json
.
Marshal
(
&
rl
)
}
}
func
(
rl
roundsList
)
Marshal
()
[]
byte
{
func
unmarshalRoundsList
(
marshaled
[]
byte
)
([]
id
.
Round
,
error
)
{
rl
:=
roundsList
{}
err
:=
json
.
Unmarshal
(
marshaled
,
&
rl
)
if
err
!=
nil
{
return
nil
,
err
}
}
realRl
:=
make
([]
id
.
Round
,
len
(
rl
))
func
unmarshalRoundsList
(
marshaled
[]
byte
)
[]
id
.
Round
{
for
_
,
rid
:=
range
rl
{
realRl
=
append
(
realRl
,
id
.
Round
(
rid
))
}
return
realRl
,
nil
}
}
func
makeRoundsList
(
rounds
[]
id
.
Round
)
roundsList
{
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
// WaitForMessageDelivery allows the caller to get notified if the rounds a
...
@@ -34,39 +57,39 @@ func makeRoundsList(rounds []id.Round) roundsList {
...
@@ -34,39 +57,39 @@ func makeRoundsList(rounds []id.Round) roundsList {
// This function takes the marshaled send report to ensure a memory leak does
// 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
// not occur as a result of both sides of the bindings holding a reference to
// the same pointer.
// the same pointer.
func
(
c
*
Client
)
WaitForMessageDelivery
(
marshaledSendRepor
t
[]
byte
,
func
(
c
*
Client
)
WaitForMessageDelivery
(
roundLis
t
[]
byte
,
mdc
MessageDeliveryCallback
,
timeoutMS
int
)
error
{
mdc
MessageDeliveryCallback
,
timeoutMS
int
)
error
{
jww
.
INFO
.
Printf
(
"WaitForMessageDelivery(%v, _, %v)"
,
jww
.
INFO
.
Printf
(
"WaitForMessageDelivery(%v, _, %v)"
,
marshaledSendRepor
t
,
timeoutMS
)
roundLis
t
,
timeoutMS
)
s
r
,
err
:=
U
nmarshal
SendReport
(
marshaledSendRepor
t
)
r
l
,
err
:=
u
nmarshal
RoundsList
(
roundLis
t
)
if
err
!=
nil
{
if
err
!=
nil
{
return
errors
.
New
(
fmt
.
Sprintf
(
"Failed to "
+
return
errors
.
New
(
fmt
.
Sprintf
(
"Failed to "
+
"WaitForMessageDelivery callback due to bad Send Report: %+v"
,
err
))
"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 "
+
return
errors
.
New
(
fmt
.
Sprintf
(
"Failed to "
+
"WaitForMessageDelivery callback due to invalid Send Report "
+
"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
)
{
f
:=
func
(
allRoundsSucceeded
,
timedOut
bool
,
rounds
map
[
id
.
Round
]
cmix
.
Round
Result
)
{
results
:=
make
([]
byte
,
len
(
sr
.
rl
.
list
))
results
:=
make
([]
byte
,
len
(
rl
))
jww
.
INFO
.
Printf
(
"Processing WaitForMessageDelivery report "
+
jww
.
INFO
.
Printf
(
"Processing WaitForMessageDelivery report "
+
"
for %v,
success: %v, timedout: %v"
,
sr
.
mid
,
allRoundsSucceeded
,
"success: %v, timedout: %v"
,
allRoundsSucceeded
,
timedOut
)
timedOut
)
for
i
,
r
:=
range
sr
.
rl
.
list
{
for
i
,
r
:=
range
rl
{
if
result
,
exists
:=
rounds
[
r
];
exists
{
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
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
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