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
83c7c554
Commit
83c7c554
authored
May 5, 2021
by
Jake Taylor
Browse files
Options
Downloads
Patches
Plain Diff
send to preferred now will try more proxies than before
parent
b6f474ae
No related branches found
No related tags found
1 merge request
!23
Release
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
network/gateway/hostPool.go
+7
-7
7 additions, 7 deletions
network/gateway/hostPool.go
network/gateway/hostpool_test.go
+8
-2
8 additions, 2 deletions
network/gateway/hostpool_test.go
network/gateway/sender.go
+39
-15
39 additions, 15 deletions
network/gateway/sender.go
with
54 additions
and
24 deletions
network/gateway/hostPool.go
+
7
−
7
View file @
83c7c554
...
@@ -223,7 +223,9 @@ func (h *HostPool) getPreferred(targets []*id.ID) []*connect.Host {
...
@@ -223,7 +223,9 @@ func (h *HostPool) getPreferred(targets []*id.ID) []*connect.Host {
}
}
// Replaces the given hostId in the HostPool if the given hostErr is in errorList
// Replaces the given hostId in the HostPool if the given hostErr is in errorList
func
(
h
*
HostPool
)
checkReplace
(
hostId
*
id
.
ID
,
hostErr
error
)
error
{
// Returns whether the host was replaced
func
(
h
*
HostPool
)
checkReplace
(
hostId
*
id
.
ID
,
hostErr
error
)
(
bool
,
error
)
{
var
err
error
// Check if Host should be replaced
// Check if Host should be replaced
doReplace
:=
false
doReplace
:=
false
if
hostErr
!=
nil
{
if
hostErr
!=
nil
{
...
@@ -237,19 +239,17 @@ func (h *HostPool) checkReplace(hostId *id.ID, hostErr error) error {
...
@@ -237,19 +239,17 @@ func (h *HostPool) checkReplace(hostId *id.ID, hostErr error) error {
}
}
if
doReplace
{
if
doReplace
{
h
.
hostMux
.
Lock
()
defer
h
.
hostMux
.
Unlock
()
// If the Host is still in the pool
// If the Host is still in the pool
h
.
hostMux
.
Lock
()
if
oldPoolIndex
,
ok
:=
h
.
hostMap
[
*
hostId
];
ok
{
if
oldPoolIndex
,
ok
:=
h
.
hostMap
[
*
hostId
];
ok
{
// Replace it
// Replace it
h
.
ndfMux
.
RLock
()
h
.
ndfMux
.
RLock
()
err
:
=
h
.
forceReplace
(
oldPoolIndex
)
err
=
h
.
forceReplace
(
oldPoolIndex
)
h
.
ndfMux
.
RUnlock
()
h
.
ndfMux
.
RUnlock
()
return
err
}
}
h
.
hostMux
.
Unlock
()
}
}
return
nil
return
doReplace
,
err
}
}
// Replace given Host index with a new, randomly-selected Host from the NDF
// Replace given Host index with a new, randomly-selected Host from the NDF
...
...
This diff is collapsed.
Click to expand it.
network/gateway/hostpool_test.go
+
8
−
2
View file @
83c7c554
...
@@ -359,10 +359,13 @@ func TestHostPool_CheckReplace(t *testing.T) {
...
@@ -359,10 +359,13 @@ func TestHostPool_CheckReplace(t *testing.T) {
oldGatewayIndex
:=
0
oldGatewayIndex
:=
0
oldHost
:=
testPool
.
hostList
[
oldGatewayIndex
]
oldHost
:=
testPool
.
hostList
[
oldGatewayIndex
]
expectedError
:=
fmt
.
Errorf
(
errorsList
[
0
])
expectedError
:=
fmt
.
Errorf
(
errorsList
[
0
])
err
=
testPool
.
checkReplace
(
oldHost
.
GetId
(),
expectedError
)
wasReplaced
,
err
:
=
testPool
.
checkReplace
(
oldHost
.
GetId
(),
expectedError
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Failed to check replace: %v"
,
err
)
t
.
Errorf
(
"Failed to check replace: %v"
,
err
)
}
}
if
!
wasReplaced
{
t
.
Errorf
(
"Expected to replace"
)
}
// Ensure that old gateway has been removed from the map
// Ensure that old gateway has been removed from the map
if
_
,
ok
:=
testPool
.
hostMap
[
*
oldHost
.
GetId
()];
ok
{
if
_
,
ok
:=
testPool
.
hostMap
[
*
oldHost
.
GetId
()];
ok
{
...
@@ -378,10 +381,13 @@ func TestHostPool_CheckReplace(t *testing.T) {
...
@@ -378,10 +381,13 @@ func TestHostPool_CheckReplace(t *testing.T) {
goodGatewayIndex
:=
0
goodGatewayIndex
:=
0
goodGateway
:=
testPool
.
hostList
[
goodGatewayIndex
]
goodGateway
:=
testPool
.
hostList
[
goodGatewayIndex
]
unexpectedErr
:=
fmt
.
Errorf
(
"not in global error list"
)
unexpectedErr
:=
fmt
.
Errorf
(
"not in global error list"
)
err
=
testPool
.
checkReplace
(
oldHost
.
GetId
(),
unexpectedErr
)
wasReplaced
,
err
=
testPool
.
checkReplace
(
oldHost
.
GetId
(),
unexpectedErr
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Failed to check replace: %v"
,
err
)
t
.
Errorf
(
"Failed to check replace: %v"
,
err
)
}
}
if
wasReplaced
{
t
.
Errorf
(
"Expected not to replace"
)
}
// Ensure that gateway with an unexpected error was not modified
// Ensure that gateway with an unexpected error was not modified
if
_
,
ok
:=
testPool
.
hostMap
[
*
goodGateway
.
GetId
()];
!
ok
{
if
_
,
ok
:=
testPool
.
hostMap
[
*
goodGateway
.
GetId
()];
!
ok
{
...
...
This diff is collapsed.
Click to expand it.
network/gateway/sender.go
+
39
−
15
View file @
83c7c554
...
@@ -63,7 +63,7 @@ func (s *Sender) SendToSpecific(target *id.ID,
...
@@ -63,7 +63,7 @@ func (s *Sender) SendToSpecific(target *id.ID,
host
.
GetId
()
.
String
())
host
.
GetId
()
.
String
())
}
}
jww
.
WARN
.
Printf
(
"Unable to SendToSpecific proxy %s: %s"
,
proxies
[
i
]
.
GetId
()
.
String
(),
err
)
jww
.
WARN
.
Printf
(
"Unable to SendToSpecific proxy %s: %s"
,
proxies
[
i
]
.
GetId
()
.
String
(),
err
)
err
=
s
.
checkReplace
(
proxies
[
i
]
.
GetId
(),
err
)
_
,
err
=
s
.
checkReplace
(
proxies
[
i
]
.
GetId
(),
err
)
if
err
!=
nil
{
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"Unable to checkReplace: %+v"
,
err
)
jww
.
ERROR
.
Printf
(
"Unable to checkReplace: %+v"
,
err
)
}
}
...
@@ -83,7 +83,7 @@ func (s *Sender) SendToAny(sendFunc func(host *connect.Host) (interface{}, error
...
@@ -83,7 +83,7 @@ func (s *Sender) SendToAny(sendFunc func(host *connect.Host) (interface{}, error
return
result
,
nil
return
result
,
nil
}
else
{
}
else
{
jww
.
WARN
.
Printf
(
"Unable to SendToAny %s: %s"
,
proxies
[
i
]
.
GetId
()
.
String
(),
err
)
jww
.
WARN
.
Printf
(
"Unable to SendToAny %s: %s"
,
proxies
[
i
]
.
GetId
()
.
String
(),
err
)
err
=
s
.
checkReplace
(
proxies
[
i
]
.
GetId
(),
err
)
_
,
err
=
s
.
checkReplace
(
proxies
[
i
]
.
GetId
(),
err
)
if
err
!=
nil
{
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"Unable to checkReplace: %+v"
,
err
)
jww
.
ERROR
.
Printf
(
"Unable to checkReplace: %+v"
,
err
)
}
}
...
@@ -97,6 +97,7 @@ func (s *Sender) SendToAny(sendFunc func(host *connect.Host) (interface{}, error
...
@@ -97,6 +97,7 @@ func (s *Sender) SendToAny(sendFunc func(host *connect.Host) (interface{}, error
func
(
s
*
Sender
)
SendToPreferred
(
targets
[]
*
id
.
ID
,
func
(
s
*
Sender
)
SendToPreferred
(
targets
[]
*
id
.
ID
,
sendFunc
func
(
host
*
connect
.
Host
,
target
*
id
.
ID
)
(
interface
{},
error
))
(
interface
{},
error
)
{
sendFunc
func
(
host
*
connect
.
Host
,
target
*
id
.
ID
)
(
interface
{},
error
))
(
interface
{},
error
)
{
// Attempt to send directly to targets if they are in the HostPool
targetHosts
:=
s
.
getPreferred
(
targets
)
targetHosts
:=
s
.
getPreferred
(
targets
)
for
i
:=
range
targetHosts
{
for
i
:=
range
targetHosts
{
result
,
err
:=
sendFunc
(
targetHosts
[
i
],
targets
[
i
])
result
,
err
:=
sendFunc
(
targetHosts
[
i
],
targets
[
i
])
...
@@ -105,26 +106,49 @@ func (s *Sender) SendToPreferred(targets []*id.ID,
...
@@ -105,26 +106,49 @@ func (s *Sender) SendToPreferred(targets []*id.ID,
}
else
{
}
else
{
jww
.
WARN
.
Printf
(
"Unable to SendToPreferred %s via %s: %s"
,
jww
.
WARN
.
Printf
(
"Unable to SendToPreferred %s via %s: %s"
,
targets
[
i
],
targetHosts
[
i
]
.
GetId
(),
err
)
targets
[
i
],
targetHosts
[
i
]
.
GetId
(),
err
)
err
=
s
.
checkReplace
(
targetHosts
[
i
]
.
GetId
(),
err
)
_
,
err
=
s
.
checkReplace
(
targetHosts
[
i
]
.
GetId
(),
err
)
if
err
!=
nil
{
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"Unable to checkReplace: %+v"
,
err
)
jww
.
ERROR
.
Printf
(
"Unable to checkReplace: %+v"
,
err
)
}
}
}
}
}
}
proxies
:=
s
.
getAny
(
s
.
poolParams
.
ProxyAttempts
,
targets
)
// Build a list of proxies for every target
for
i
:=
range
proxies
{
proxies
:=
make
([][]
*
connect
.
Host
,
len
(
targets
))
target
:=
targets
[
i
%
len
(
targets
)]
.
DeepCopy
()
for
i
:=
0
;
i
<
len
(
targets
);
i
++
{
result
,
err
:=
sendFunc
(
proxies
[
i
],
target
)
proxies
[
i
]
=
s
.
getAny
(
s
.
poolParams
.
ProxyAttempts
,
targets
)
}
// Build a map of bad proxies
badProxies
:=
make
(
map
[
string
]
interface
{})
// Iterate between each target's list of proxies, using the next target for each proxy
for
proxyIdx
:=
uint32
(
0
);
proxyIdx
<
s
.
poolParams
.
ProxyAttempts
;
proxyIdx
++
{
for
targetIdx
:=
range
proxies
{
target
:=
targets
[
targetIdx
]
targetProxies
:=
proxies
[
targetIdx
]
proxy
:=
targetProxies
[
proxyIdx
]
// Skip bad proxies
if
_
,
ok
:=
badProxies
[
proxy
.
String
()];
ok
{
continue
}
result
,
err
:=
sendFunc
(
targetProxies
[
proxyIdx
],
target
)
if
err
==
nil
{
if
err
==
nil
{
return
result
,
nil
return
result
,
nil
}
else
{
}
else
{
jww
.
WARN
.
Printf
(
"Unable to SendToPreferred %s via proxy "
+
jww
.
WARN
.
Printf
(
"Unable to SendToPreferred %s via proxy "
+
"%s: %s"
,
target
,
prox
ies
[
i
]
.
GetId
(),
err
)
"%s: %s"
,
target
,
prox
y
.
GetId
(),
err
)
err
=
s
.
checkReplace
(
prox
ies
[
i
]
.
GetId
(),
err
)
wasReplaced
,
err
:
=
s
.
checkReplace
(
prox
y
.
GetId
(),
err
)
if
err
!=
nil
{
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"Unable to checkReplace: %+v"
,
err
)
jww
.
ERROR
.
Printf
(
"Unable to checkReplace: %+v"
,
err
)
}
}
// If the proxy was replaced, add as a bad proxy
if
wasReplaced
{
badProxies
[
proxy
.
String
()]
=
nil
}
}
}
}
}
}
...
...
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