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
19c02b66
Commit
19c02b66
authored
Oct 5, 2021
by
Jake Taylor
Browse files
Options
Downloads
Patches
Plain Diff
second pass at adding new initialize functionality
parent
bcd7c4bb
No related branches found
No related tags found
2 merge requests
!53
Release
,
!33
Hotfix/ping
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
network/gateway/hostPool.go
+87
-43
87 additions, 43 deletions
network/gateway/hostPool.go
single/transmission.go
+1
-1
1 addition, 1 deletion
single/transmission.go
single/transmitMessage.go
+2
-3
2 additions, 3 deletions
single/transmitMessage.go
with
90 additions
and
47 deletions
network/gateway/hostPool.go
+
87
−
43
View file @
19c02b66
...
@@ -18,6 +18,7 @@ import (
...
@@ -18,6 +18,7 @@ import (
"gitlab.com/elixxir/client/storage"
"gitlab.com/elixxir/client/storage"
"gitlab.com/elixxir/comms/network"
"gitlab.com/elixxir/comms/network"
"gitlab.com/elixxir/crypto/fastRNG"
"gitlab.com/elixxir/crypto/fastRNG"
"gitlab.com/elixxir/crypto/shuffle"
"gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/ndf"
"gitlab.com/xx_network/primitives/ndf"
...
@@ -26,6 +27,7 @@ import (
...
@@ -26,6 +27,7 @@ import (
"google.golang.org/grpc/balancer"
"google.golang.org/grpc/balancer"
"io"
"io"
"math"
"math"
"sort"
"strings"
"strings"
"sync"
"sync"
"time"
"time"
...
@@ -155,69 +157,111 @@ func newHostPool(poolParams PoolParams, rng *fastRNG.StreamGenerator,
...
@@ -155,69 +157,111 @@ func newHostPool(poolParams PoolParams, rng *fastRNG.StreamGenerator,
}
}
// Build the initial HostPool and return
// Build the initial HostPool and return
//for i := numHostsAdded; i < len(result.hostList); i++ {
err
=
result
.
initialize
(
uint32
(
numHostsAdded
))
// err := result.forceReplace(uint32(i))
if
err
!=
nil
{
// if err != nil {
return
nil
,
err
// return nil, err
}
// }
//}
jww
.
INFO
.
Printf
(
"Initialized HostPool with size: %d/%d"
,
poolParams
.
PoolSize
,
len
(
netDef
.
Gateways
))
jww
.
INFO
.
Printf
(
"Initialized HostPool with size: %d/%d"
,
poolParams
.
PoolSize
,
len
(
netDef
.
Gateways
))
return
result
,
nil
return
result
,
nil
}
}
// Initialize the HostPool with a performant set of Hosts
// Initialize the HostPool with a performant set of Hosts
func
(
h
*
HostPool
)
initialize
(
startIdx
uint32
)
{
func
(
h
*
HostPool
)
initialize
(
startIdx
uint32
)
error
{
roundTripDurations
:=
make
(
map
[
id
.
ID
]
time
.
Duration
)
// Randomly shuffle gateways in NDF
numGatewaysToTry
:=
h
.
poolParams
.
PingMultiplier
*
(
h
.
poolParams
.
PoolSize
-
startIdx
)
randomGateways
:=
make
([]
ndf
.
Gateway
,
len
(
h
.
ndf
.
Gateways
))
copy
(
randomGateways
,
h
.
ndf
.
Gateways
)
var
rndBytes
[
32
]
byte
stream
:=
h
.
rng
.
GetStream
()
_
,
err
:=
stream
.
Read
(
rndBytes
[
:
])
stream
.
Close
()
if
err
!=
nil
{
return
errors
.
Errorf
(
"Failed to randomize shuffle for HostPool initialization: %+v"
,
err
)
}
shuffle
.
ShuffleSwap
(
rndBytes
[
:
],
len
(
randomGateways
),
func
(
i
,
j
int
)
{
randomGateways
[
i
],
randomGateways
[
j
]
=
randomGateways
[
j
],
randomGateways
[
i
]
})
// Begin checking roundTripDurations for numGatewaysToTry
// Set constants
for
i
:=
uint32
(
0
);
i
<
numGatewaysToTry
;
i
++
{
type
gatewayDuration
struct
{
// Select a gateway not yet selected
id
*
id
.
ID
gwId
:=
h
.
selectGateway
()
latency
time
.
Duration
if
_
,
ok
:=
roundTripDurations
[
*
gwId
];
ok
{
continue
}
}
gatewaysNeeded
:=
h
.
poolParams
.
PoolSize
-
startIdx
numGatewaysToTry
:=
h
.
poolParams
.
PingMultiplier
*
gatewaysNeeded
resultList
:=
make
([]
gatewayDuration
,
0
,
numGatewaysToTry
)
// Initialize in the durations map
// Begin trying gateways
roundTripDurations
[
*
gwId
]
=
0
c
:=
make
(
chan
gatewayDuration
,
numGatewaysToTry
)
exit
:=
false
i
:=
uint32
(
0
)
for
!
exit
{
for
;
i
<
numGatewaysToTry
;
i
++
{
// Ran out of Hosts to try
if
i
>
uint32
(
len
(
randomGateways
))
{
return
errors
.
Errorf
(
"Unable to initialize enough viable hosts for HostPool"
)
}
// Select a gateway not yet selected
gwId
,
err
:=
randomGateways
[
i
]
.
GetGatewayId
()
if
err
!=
nil
{
jww
.
WARN
.
Printf
(
"ID for gateway %s could not be retrieved"
,
gwId
)
}
go
func
()
{
go
func
()
{
// Obtain that GwId's Host object
// Obtain that GwId's Host object
newHost
,
ok
:=
h
.
manager
.
GetHost
(
gwId
)
newHost
,
ok
:=
h
.
manager
.
GetHost
(
gwId
)
if
!
ok
{
if
!
ok
{
jww
.
WARN
.
Printf
(
"
h
ost for gateway %s could not be "
+
jww
.
WARN
.
Printf
(
"
H
ost for gateway %s could not be "
+
"retrieved"
,
gwId
)
"retrieved"
,
gwId
)
return
return
}
}
pingDuration
,
_
:=
newHost
.
IsOnline
()
// Ping the Host latency and send the result
roundTripDurations
[
*
gwId
]
=
pingDuration
latency
,
_
:=
newHost
.
IsOnline
()
c
<-
gatewayDuration
{
gwId
,
latency
}
}()
}()
}
}
// TODO ?
// Collect ping results
time
.
Sleep
(
2
*
h
.
poolParams
.
HostParams
.
PingTimeout
)
timer
:=
time
.
NewTimer
(
2
*
h
.
poolParams
.
HostParams
.
PingTimeout
)
for
{
select
{
case
gw
:=
<-
c
:
// Only add successful pings
if
gw
.
latency
>
0
{
resultList
=
append
(
resultList
,
gw
)
}
// Add sufficiently fast gateways
// Break if we have all needed slots
for
gwId
,
roundTripDuration
:=
range
roundTripDurations
{
if
uint32
(
len
(
resultList
))
==
numGatewaysToTry
{
// Ignore failed connectivity checks
exit
=
true
if
roundTripDuration
==
0
{
break
continue
}
case
<-
timer
.
C
:
break
}
}
}
}
// Sort the resultList by lowest latency
sort
.
Slice
(
resultList
,
func
(
i
,
j
int
)
bool
{
return
resultList
[
i
]
.
latency
<
resultList
[
j
]
.
latency
})
jww
.
DEBUG
.
Printf
(
"Gateway pool results: %+v"
,
resultList
)
// Attempt to add to HostPool
// Process ping results
err
:=
h
.
replaceHost
(
&
gwId
,
startIdx
)
for
_
,
result
:=
range
resultList
{
err
=
h
.
replaceHost
(
result
.
id
,
startIdx
)
if
err
!=
nil
{
if
err
!=
nil
{
jww
.
WARN
.
Printf
(
"Unable to initialize host in HostPool: %+v"
,
err
)
return
err
}
}
startIdx
++
startIdx
++
// Once HostPool is full, break
if
startIdx
>=
h
.
poolParams
.
PoolSize
{
if
startIdx
>=
h
.
poolParams
.
PoolSize
{
break
break
}
}
}
}
return
nil
}
}
// UpdateNdf Mutates internal ndf to the given ndf
// UpdateNdf Mutates internal ndf to the given ndf
...
...
This diff is collapsed.
Click to expand it.
single/transmission.go
+
1
−
1
View file @
19c02b66
This diff is collapsed.
Click to expand it.
single/transmitMessage.go
+
2
−
3
View file @
19c02b66
...
@@ -248,7 +248,6 @@ func (mp transmitMessagePayload) SetContents(contents []byte) {
...
@@ -248,7 +248,6 @@ func (mp transmitMessagePayload) SetContents(contents []byte) {
copy
(
mp
.
contents
,
contents
)
copy
(
mp
.
contents
,
contents
)
}
}
// String returns the contents for printing adhering to the stringer interface.
// String returns the contents for printing adhering to the stringer interface.
func
(
mp
transmitMessagePayload
)
String
()
string
{
func
(
mp
transmitMessagePayload
)
String
()
string
{
return
fmt
.
Sprintf
(
"Data: %x [tagFP: %x, nonce: %x, "
+
return
fmt
.
Sprintf
(
"Data: %x [tagFP: %x, nonce: %x, "
+
...
...
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