-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enchanced checks #2
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ import ( | |
"flag" | ||
"fmt" | ||
"io/ioutil" | ||
"math/rand" | ||
"net" | ||
"os" | ||
"os/signal" | ||
|
@@ -186,10 +187,42 @@ func (hc *hostChecker) DoCheck(hostport string) State { | |
if route.CanConnect(hostport) { | ||
state = Up | ||
} | ||
canaryUser, err := pickUser() | ||
if err == nil && canaryUser != "" && state == Up { | ||
if route.MightAuthenticate(hostport, canaryUser) { | ||
log.Debug("Succefully tried to authenticate to %s as %s", hostport, canaryUser) | ||
} else { | ||
log.Debug("Unable to try to authenticate against %s as %s", hostport, canaryUser) | ||
state = Down | ||
} | ||
} else if err != nil { | ||
log.Debugf("Unable to try to authenticate, found no user to spoof (%s)", err) | ||
} | ||
hc.Update(hostport, state, time.Now()) | ||
return state | ||
} | ||
|
||
func pickUser() (string, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing function doc. |
||
chosenUser := "" | ||
if len(proxiedConnections) > 0 { | ||
chosenItem := rand.Intn(len(proxiedConnections)) | ||
for k := range proxiedConnections { | ||
if chosenItem == 0 { | ||
user, err := getUserFromKey(k) | ||
if err != nil { | ||
return "", err | ||
} | ||
chosenUser = user | ||
break | ||
} | ||
chosenItem-- | ||
} | ||
} else { | ||
return "", errors.New("no proxied connections, unable to pick a random user") | ||
} | ||
return chosenUser, nil | ||
} | ||
|
||
// Update updates (or creates) the state of an host in the internal view. | ||
func (hc *hostChecker) Update(hostport string, state State, ts time.Time) { | ||
if s, ok := hc.States[hostport]; ok { | ||
|
@@ -672,6 +705,8 @@ func main() { | |
} | ||
defer l.Close() | ||
|
||
rand.Seed(time.Now().Unix()) // initialize global pseudo random generator | ||
|
||
log.Info("listening on %s\n", config.Listen) | ||
|
||
queue := make(chan *request) | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
glide
to manage this new dependency.