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
13d8b4f0
Commit
13d8b4f0
authored
Jul 6, 2022
by
Richard T. Carback III
Browse files
Options
Downloads
Patches
Plain Diff
Fix name of authenticatedConnection and merge the (internal) tracker code into it.
parent
c2e72b83
No related branches found
No related tags found
2 merge requests
!510
Release
,
!262
Add params options to bindings
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
bindings/authenticatedConnection.go
+52
-0
52 additions, 0 deletions
bindings/authenticatedConnection.go
bindings/authenticatedConnectionTracker.go
+0
-56
0 additions, 56 deletions
bindings/authenticatedConnectionTracker.go
with
52 additions
and
56 deletions
bindings/autheticatedConnection.go
→
bindings/authe
n
ticatedConnection.go
+
52
−
0
View file @
13d8b4f0
package
bindings
import
(
"sync"
"github.com/pkg/errors"
"gitlab.com/elixxir/client/connect"
"gitlab.com/elixxir/crypto/contact"
)
...
...
@@ -46,3 +49,52 @@ func (c *Cmix) ConnectWithAuthentication(e2eId int, recipientContact []byte) (*A
e2eClient
.
api
,
params
)
return
authenticatedConnectionTrackerSingleton
.
make
(
connection
),
err
}
// connectionTracker is a singleton used to keep track of extant clients, allowing
// for race condition free passing over the bindings
type
authenticatedConnectionTracker
struct
{
connections
map
[
int
]
*
AuthenticatedConnection
count
int
mux
sync
.
RWMutex
}
// make makes a client from an API client, assigning it a unique ID
func
(
act
*
authenticatedConnectionTracker
)
make
(
c
connect
.
AuthenticatedConnection
)
*
AuthenticatedConnection
{
act
.
mux
.
Lock
()
defer
act
.
mux
.
Unlock
()
id
:=
act
.
count
act
.
count
++
act
.
connections
[
id
]
=
&
AuthenticatedConnection
{
Connection
:
Connection
{
connection
:
c
,
id
:
id
,
},
}
return
act
.
connections
[
id
]
}
//get returns a client given its ID
func
(
act
*
authenticatedConnectionTracker
)
get
(
id
int
)
(
*
AuthenticatedConnection
,
error
)
{
act
.
mux
.
RLock
()
defer
act
.
mux
.
RUnlock
()
c
,
exist
:=
act
.
connections
[
id
]
if
!
exist
{
return
nil
,
errors
.
Errorf
(
"Cannot get client for id %d, client "
+
"does not exist"
,
id
)
}
return
c
,
nil
}
//deletes a client if it exists
func
(
act
*
authenticatedConnectionTracker
)
delete
(
id
int
)
{
act
.
mux
.
Lock
()
defer
act
.
mux
.
Unlock
()
delete
(
act
.
connections
,
id
)
}
This diff is collapsed.
Click to expand it.
bindings/authenticatedConnectionTracker.go
deleted
100644 → 0
+
0
−
56
View file @
c2e72b83
package
bindings
import
(
"github.com/pkg/errors"
"gitlab.com/elixxir/client/connect"
"sync"
)
// connectionTracker is a singleton used to keep track of extant clients, allowing
// for race condition free passing over the bindings
type
authenticatedConnectionTracker
struct
{
connections
map
[
int
]
*
AuthenticatedConnection
count
int
mux
sync
.
RWMutex
}
// make makes a client from an API client, assigning it a unique ID
func
(
act
*
authenticatedConnectionTracker
)
make
(
c
connect
.
AuthenticatedConnection
)
*
AuthenticatedConnection
{
act
.
mux
.
Lock
()
defer
act
.
mux
.
Unlock
()
id
:=
act
.
count
act
.
count
++
act
.
connections
[
id
]
=
&
AuthenticatedConnection
{
Connection
:
Connection
{
connection
:
c
,
id
:
id
,
},
}
return
act
.
connections
[
id
]
}
//get returns a client given its ID
func
(
act
*
authenticatedConnectionTracker
)
get
(
id
int
)
(
*
AuthenticatedConnection
,
error
)
{
act
.
mux
.
RLock
()
defer
act
.
mux
.
RUnlock
()
c
,
exist
:=
act
.
connections
[
id
]
if
!
exist
{
return
nil
,
errors
.
Errorf
(
"Cannot get client for id %d, client "
+
"does not exist"
,
id
)
}
return
c
,
nil
}
//deletes a client if it exists
func
(
act
*
authenticatedConnectionTracker
)
delete
(
id
int
)
{
act
.
mux
.
Lock
()
defer
act
.
mux
.
Unlock
()
delete
(
act
.
connections
,
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