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
aa44f972
Commit
aa44f972
authored
4 years ago
by
Jake Taylor
Browse files
Options
Downloads
Plain Diff
Merge branch 'release' into XX-3134/GwHostPool
# Conflicts: # go.mod # go.sum
parents
5214c9fe
2f658496
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
bindings/callback.go
+14
-0
14 additions, 0 deletions
bindings/callback.go
bindings/client.go
+18
-0
18 additions, 0 deletions
bindings/client.go
storage/rounds/earliestRound.go
+12
-12
12 additions, 12 deletions
storage/rounds/earliestRound.go
with
44 additions
and
12 deletions
bindings/callback.go
+
14
−
0
View file @
aa44f972
...
@@ -96,3 +96,17 @@ func newRoundListUnregister(rounds []id.Round, ec []*dataStructures.EventCallbac
...
@@ -96,3 +96,17 @@ func newRoundListUnregister(rounds []id.Round, ec []*dataStructures.EventCallbac
type
ClientError
interface
{
type
ClientError
interface
{
Report
(
source
,
message
,
trace
string
)
Report
(
source
,
message
,
trace
string
)
}
}
type
LogWriter
interface
{
Log
(
string
)
}
type
writerAdapter
struct
{
lw
LogWriter
}
func
(
wa
*
writerAdapter
)
Write
(
p
[]
byte
)
(
n
int
,
err
error
){
wa
.
lw
.
Log
(
string
(
p
))
return
len
(
p
),
nil
}
This diff is collapsed.
Click to expand it.
bindings/client.go
+
18
−
0
View file @
aa44f972
...
@@ -19,9 +19,13 @@ import (
...
@@ -19,9 +19,13 @@ import (
"gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/elixxir/primitives/states"
"gitlab.com/elixxir/primitives/states"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id"
"sync"
"time"
"time"
)
)
var
extantClient
bool
var
loginMux
sync
.
Mutex
// sets the log level
// sets the log level
func
init
()
{
func
init
()
{
jww
.
SetLogThreshold
(
jww
.
LevelInfo
)
jww
.
SetLogThreshold
(
jww
.
LevelInfo
)
...
@@ -76,6 +80,14 @@ func NewPrecannedClient(precannedID int, network, storageDir string, password []
...
@@ -76,6 +80,14 @@ func NewPrecannedClient(precannedID int, network, storageDir string, password []
// Login does not block on network connection, and instead loads and
// Login does not block on network connection, and instead loads and
// starts subprocesses to perform network operations.
// starts subprocesses to perform network operations.
func
Login
(
storageDir
string
,
password
[]
byte
,
parameters
string
)
(
*
Client
,
error
)
{
func
Login
(
storageDir
string
,
password
[]
byte
,
parameters
string
)
(
*
Client
,
error
)
{
loginMux
.
Lock
()
defer
loginMux
.
Unlock
()
if
extantClient
{
return
nil
,
errors
.
New
(
"cannot login when another session "
+
"already exists"
)
}
// check if a client is already logged in, refuse to login if one is
p
,
err
:=
params
.
GetNetworkParameters
(
parameters
)
p
,
err
:=
params
.
GetNetworkParameters
(
parameters
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
errors
.
New
(
fmt
.
Sprintf
(
"Failed to login: %+v"
,
err
))
return
nil
,
errors
.
New
(
fmt
.
Sprintf
(
"Failed to login: %+v"
,
err
))
...
@@ -85,6 +97,7 @@ func Login(storageDir string, password []byte, parameters string) (*Client, erro
...
@@ -85,6 +97,7 @@ func Login(storageDir string, password []byte, parameters string) (*Client, erro
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
errors
.
New
(
fmt
.
Sprintf
(
"Failed to login: %+v"
,
err
))
return
nil
,
errors
.
New
(
fmt
.
Sprintf
(
"Failed to login: %+v"
,
err
))
}
}
extantClient
=
true
return
&
Client
{
api
:
*
client
},
nil
return
&
Client
{
api
:
*
client
},
nil
}
}
...
@@ -127,6 +140,11 @@ func LogLevel(level int) error {
...
@@ -127,6 +140,11 @@ func LogLevel(level int) error {
return
nil
return
nil
}
}
//RegisterLogWriter registers a callback on which logs are written.
func
RegisterLogWriter
(
writer
LogWriter
){
jww
.
SetLogOutput
(
&
writerAdapter
{
lw
:
writer
})
}
//Unmarshals a marshaled contact object, returns an error if it fails
//Unmarshals a marshaled contact object, returns an error if it fails
func
UnmarshalContact
(
b
[]
byte
)
(
*
Contact
,
error
)
{
func
UnmarshalContact
(
b
[]
byte
)
(
*
Contact
,
error
)
{
c
,
err
:=
contact
.
Unmarshal
(
b
)
c
,
err
:=
contact
.
Unmarshal
(
b
)
...
...
This diff is collapsed.
Click to expand it.
storage/rounds/earliestRound.go
+
12
−
12
View file @
aa44f972
...
@@ -9,8 +9,8 @@ import (
...
@@ -9,8 +9,8 @@ import (
"sync"
"sync"
)
)
const
unknown
RoundStorageKey
=
"unknownRoundStorage"
const
earliest
RoundStorageKey
=
"unknownRoundStorage"
const
unknown
RoundStorageVersion
=
0
const
earliest
RoundStorageVersion
=
0
type
EarliestRound
struct
{
type
EarliestRound
struct
{
stored
bool
stored
bool
...
@@ -36,14 +36,14 @@ func LoadEarliestRound(kv *versioned.KV) *EarliestRound {
...
@@ -36,14 +36,14 @@ func LoadEarliestRound(kv *versioned.KV) *EarliestRound {
rid
:
0
,
rid
:
0
,
}
}
obj
,
err
:=
kv
.
Get
(
unknown
RoundStorageKey
,
unknown
RoundStorageVersion
)
obj
,
err
:=
kv
.
Get
(
earliest
RoundStorageKey
,
earliest
RoundStorageVersion
)
if
err
!=
nil
{
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
"Failed to get the
unknown
round: %+v"
,
err
)
jww
.
FATAL
.
Panicf
(
"Failed to get the
earlest
round: %+v"
,
err
)
}
}
err
=
json
.
Unmarshal
(
obj
.
Data
,
&
ur
.
rid
)
err
=
json
.
Unmarshal
(
obj
.
Data
,
&
ur
.
rid
)
if
err
!=
nil
{
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
"Failed to unmarshal the
unknown
round: %+v"
,
err
)
jww
.
FATAL
.
Panicf
(
"Failed to unmarshal the
earliest
round: %+v"
,
err
)
}
}
return
ur
return
ur
}
}
...
@@ -52,20 +52,20 @@ func (ur *EarliestRound) save() {
...
@@ -52,20 +52,20 @@ func (ur *EarliestRound) save() {
if
ur
.
stored
{
if
ur
.
stored
{
urStr
,
err
:=
json
.
Marshal
(
&
ur
.
rid
)
urStr
,
err
:=
json
.
Marshal
(
&
ur
.
rid
)
if
err
!=
nil
{
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
"Failed to marshal the
unknown
round: %+v"
,
err
)
jww
.
FATAL
.
Panicf
(
"Failed to marshal the
earliest
round: %+v"
,
err
)
}
}
// Create versioned object with data
// Create versioned object with data
obj
:=
&
versioned
.
Object
{
obj
:=
&
versioned
.
Object
{
Version
:
unknown
RoundStorageVersion
,
Version
:
earliest
RoundStorageVersion
,
Timestamp
:
netTime
.
Now
(),
Timestamp
:
netTime
.
Now
(),
Data
:
urStr
,
Data
:
urStr
,
}
}
err
=
ur
.
kv
.
Set
(
unknown
RoundStorageKey
,
err
=
ur
.
kv
.
Set
(
earliest
RoundStorageKey
,
unknown
RoundStorageVersion
,
obj
)
earliest
RoundStorageVersion
,
obj
)
if
err
!=
nil
{
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
"Failed to store the
unknown
round: %+v"
,
err
)
jww
.
FATAL
.
Panicf
(
"Failed to store the
earliest
round: %+v"
,
err
)
}
}
}
}
...
@@ -92,8 +92,8 @@ func (ur *EarliestRound) Get() id.Round {
...
@@ -92,8 +92,8 @@ func (ur *EarliestRound) Get() id.Round {
func
(
ur
*
EarliestRound
)
delete
()
{
func
(
ur
*
EarliestRound
)
delete
()
{
ur
.
mux
.
Lock
()
ur
.
mux
.
Lock
()
defer
ur
.
mux
.
Unlock
()
defer
ur
.
mux
.
Unlock
()
err
:=
ur
.
kv
.
Delete
(
unknown
RoundStorageKey
,
unknown
RoundStorageVersion
)
err
:=
ur
.
kv
.
Delete
(
earliest
RoundStorageKey
,
earliest
RoundStorageVersion
)
if
err
!=
nil
{
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
"Failed to delete
unknownRound
storage: %+v"
,
err
)
jww
.
FATAL
.
Panicf
(
"Failed to delete
earliest
storage: %+v"
,
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