blob: 900ec24bad9651693df18255d5c0dab7d1e61f78 [file] [log] [blame]
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"v.io/v23/context"
"v.io/v23/rpc"
"v.io/v23/security"
"v.io/x/ref/examples/rps"
"v.io/x/ref/examples/rps/internal"
"v.io/x/ref/lib/stats"
"v.io/x/ref/lib/stats/counter"
)
type ScoreKeeper struct {
numRecords *counter.Counter
}
func NewScoreKeeper() *ScoreKeeper {
return &ScoreKeeper{
numRecords: stats.NewCounter("scorekeeper/num-records"),
}
}
func (k *ScoreKeeper) Stats() int64 {
return k.numRecords.Value()
}
func (k *ScoreKeeper) Record(ctx *context.T, call rpc.ServerCall, score rps.ScoreCard) error {
b, _ := security.RemoteBlessingNames(ctx, call.Security())
ctx.VI(1).Infof("Received ScoreCard from %v:", b)
ctx.VI(1).Info(internal.FormatScoreCard(score))
k.numRecords.Incr(1)
return nil
}