Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ale
autoradio
Commits
0a8e1bce
Commit
0a8e1bce
authored
Oct 16, 2015
by
ale
Browse files
fix ip protocol detection: RemoteAddr is host:port
parent
009d7c75
Changes
1
Hide whitespace changes
Inline
Side-by-side
fe/http.go
View file @
0a8e1bce
...
...
@@ -122,8 +122,11 @@ func NewHTTPRedirector(client *autoradio.Client, domain, lbspec, staticDir, temp
// Pick a random IP with a protocol appropriate to the request (based
// on the remote address).
func
randomIPForRequest
(
ips
[]
net
.
IP
,
r
*
http
.
Request
)
net
.
IP
{
remoteAddr
:=
net
.
ParseIP
(
r
.
RemoteAddr
)
isV6
:=
(
remoteAddr
!=
nil
&&
(
remoteAddr
.
To4
()
==
nil
))
isV6
:=
false
if
host
,
_
,
err
:=
net
.
SplitHostPort
(
r
.
RemoteAddr
);
err
==
nil
{
remoteAddr
:=
net
.
ParseIP
(
host
)
isV6
=
(
remoteAddr
!=
nil
&&
(
remoteAddr
.
To4
()
==
nil
))
}
return
randomIPByProto
(
ips
,
isV6
)
}
...
...
@@ -145,6 +148,8 @@ func (h *HTTPRedirector) pickActiveNode(r *http.Request) net.IP {
return
randomIPForRequest
(
result
.
IP
,
r
)
}
// Periodically update the active nodes information in the load
// balancer. Requests will then use the cached data.
func
(
h
*
HTTPRedirector
)
lbUpdater
()
{
for
range
time
.
NewTicker
(
2
*
time
.
Second
)
.
C
{
nodes
,
err
:=
h
.
client
.
GetNodes
()
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment