Skip to content
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

tweak timing information #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions pollen.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ var (
size = flag.Int("bytes", 64, "The size in bytes to transmit and receive each time")
cert = flag.String("cert", "/etc/pollen/cert.pem", "The full path to cert.pem")
key = flag.String("key", "/etc/pollen/key.pem", "The full path to key.pem")
log *syslog.Writer
dev *os.File
log *syslog.Writer
dev *os.File
)

func handler(w http.ResponseWriter, r *http.Request) {
startTime := time.Now()
challenge := r.FormValue("challenge")
if challenge == "" {
http.Error(w, "Please use the pollinate client. 'sudo apt-get install pollinate' or download from: https://bazaar.launchpad.net/~pollinate/pollinate/trunk/view/head:/pollinate", http.StatusBadRequest)
Expand Down Expand Up @@ -70,14 +71,15 @@ func handler(w http.ResponseWriter, r *http.Request) {
/* The checksum of the bytes from /dev/urandom is simply for print-ability, when debugging */
seed := checksum.Sum(nil)
fmt.Fprintf(w, "%x\n%x\n", challengeResponse, seed)
log.Info(fmt.Sprintf("Server sent response to [%s, %s] at [%v]", r.RemoteAddr, r.UserAgent(), time.Now().UnixNano()))
log.Info(fmt.Sprintf("Server sent response to [%s, %s] at [%v] in %.6fs",
r.RemoteAddr, r.UserAgent(), time.Now().UnixNano(), time.Since(startTime).Seconds()))
}

func init() {
var err error
log, err = syslog.New(syslog.LOG_ERR, "pollen")
if err != nil {
fatalf("Cannot open syslog:", err)
fatalf("Cannot open syslog: %s\n", err)
}
dev, err = os.OpenFile(*device, os.O_RDWR, 0)
if err != nil {
Expand All @@ -87,6 +89,7 @@ func init() {

func main() {
flag.Parse()
log.Info(fmt.Sprintf("pollen starting at [%v]", time.Now().UnixNano()))
defer dev.Close()
if *httpPort == "" && *httpsPort == "" {
fatal("Nothing to do if http and https are both disabled")
Expand All @@ -102,6 +105,7 @@ func main() {

func fatal(args ...interface{}) {
log.Crit(fmt.Sprint(args...))
args = append(args, "\n")
fmt.Fprint(os.Stderr, args...)
os.Exit(1)
}
Expand Down