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
fd347973
Commit
fd347973
authored
Aug 23, 2021
by
Richard T. Carback III
Browse files
Options
Downloads
Patches
Plain Diff
Initial event API
parent
c42501b1
No related branches found
No related tags found
3 merge requests
!23
Release
,
!13
Hotfix/no host cooldown + return sende2e TS
,
!11
Client Event Reporting API
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/client.go
+10
-1
10 additions, 1 deletion
api/client.go
api/event.go
+15
-11
15 additions, 11 deletions
api/event.go
with
25 additions
and
12 deletions
api/client.go
+
10
−
1
View file @
fd347973
...
@@ -63,6 +63,9 @@ type Client struct {
...
@@ -63,6 +63,9 @@ type Client struct {
followerServices
*
services
followerServices
*
services
clientErrorChannel
chan
interfaces
.
ClientError
clientErrorChannel
chan
interfaces
.
ClientError
// Event reporting in event.go
events
eventManager
}
}
// NewClient creates client storage, generates keys, connects, and registers
// NewClient creates client storage, generates keys, connects, and registers
...
@@ -184,6 +187,7 @@ func OpenClient(storageDir string, password []byte, parameters params.Network) (
...
@@ -184,6 +187,7 @@ func OpenClient(storageDir string, password []byte, parameters params.Network) (
followerServices
:
newServices
(),
followerServices
:
newServices
(),
parameters
:
parameters
,
parameters
:
parameters
,
clientErrorChannel
:
make
(
chan
interfaces
.
ClientError
,
1000
),
clientErrorChannel
:
make
(
chan
interfaces
.
ClientError
,
1000
),
events
:
newEventManager
(),
}
}
return
c
,
nil
return
c
,
nil
...
@@ -370,8 +374,13 @@ func (c *Client) registerFollower() error {
...
@@ -370,8 +374,13 @@ func (c *Client) registerFollower() error {
}
}
}
}
err
:=
c
.
followerServices
.
add
(
c
.
events
.
eventService
)
if
err
!=
nil
{
return
errors
.
WithMessage
(
err
,
"Couldn't start event reporting"
)
}
//register the core follower service
//register the core follower service
err
:
=
c
.
followerServices
.
add
(
func
()
(
stoppable
.
Stoppable
,
error
)
{
return
c
.
network
.
Follow
(
cer
)
})
err
=
c
.
followerServices
.
add
(
func
()
(
stoppable
.
Stoppable
,
error
)
{
return
c
.
network
.
Follow
(
cer
)
})
if
err
!=
nil
{
if
err
!=
nil
{
return
errors
.
WithMessage
(
err
,
"Failed to start following "
+
return
errors
.
WithMessage
(
err
,
"Failed to start following "
+
"the network"
)
"the network"
)
...
...
This diff is collapsed.
Click to expand it.
api/event.go
+
15
−
11
View file @
fd347973
...
@@ -8,11 +8,11 @@
...
@@ -8,11 +8,11 @@
package
api
package
api
import
(
import
(
"fmt"
"github.com/pkg/errors"
jww
"github.com/spf13/jwalterweatherman"
jww
"github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/stoppable"
"gitlab.com/elixxir/client/stoppable"
"sync"
"sync"
"github.com/pkg/errors"
"fmt"
)
)
// EventCallbackFunction defines the callback functions for client event reports
// EventCallbackFunction defines the callback functions for client event reports
...
@@ -25,12 +25,14 @@ type reportableEvent struct {
...
@@ -25,12 +25,14 @@ type reportableEvent struct {
EventType
string
EventType
string
Details
string
Details
string
}
}
// Holds state for the event reporting system
// Holds state for the event reporting system
type
eventManager
struct
{
type
eventManager
struct
{
eventCh
chan
reportableEvent
eventCh
chan
reportableEvent
eventCbs
[]
EventCallbackFunction
eventCbs
[]
EventCallbackFunction
eventLck
sync
.
Mutex
eventLck
sync
.
Mutex
}
}
func
newEventManager
()
eventManager
{
func
newEventManager
()
eventManager
{
return
eventManager
{
return
eventManager
{
eventCh
:
make
(
chan
reportableEvent
,
1000
),
eventCh
:
make
(
chan
reportableEvent
,
1000
),
...
@@ -114,12 +116,14 @@ func (e eventManager) reportEventsHandler(stop *stoppable.Single) {
...
@@ -114,12 +116,14 @@ func (e eventManager) reportEventsHandler(stop *stoppable.Single) {
func
(
c
*
Client
)
ReportEvent
(
priority
int
,
category
,
evtType
,
details
string
)
{
func
(
c
*
Client
)
ReportEvent
(
priority
int
,
category
,
evtType
,
details
string
)
{
c
.
events
.
ReportEvent
(
priority
,
category
,
evtType
,
details
)
c
.
events
.
ReportEvent
(
priority
,
category
,
evtType
,
details
)
}
}
// RegisterEventCallback records the given function to receive
// RegisterEventCallback records the given function to receive
// ReportableEvent objects. It returns the internal index
// ReportableEvent objects. It returns the internal index
// of the callback so that it can be deleted later.
// of the callback so that it can be deleted later.
func
(
c
*
Client
)
RegisterEventCallback
(
myFunc
EventCallbackFunction
)
int
{
func
(
c
*
Client
)
RegisterEventCallback
(
myFunc
EventCallbackFunction
)
int
{
return
c
.
events
.
RegisterEventCallback
(
myFunc
)
return
c
.
events
.
RegisterEventCallback
(
myFunc
)
}
}
// UnregisterEventCallback deletes the callback identified by the
// UnregisterEventCallback deletes the callback identified by the
// index. It returns an error if it fails.
// index. It returns an error if it fails.
func
(
c
*
Client
)
UnregisterEventCallback
(
index
int
)
error
{
func
(
c
*
Client
)
UnregisterEventCallback
(
index
int
)
error
{
...
...
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