Documentation ¶
Index ¶
- Constants
- func GeoStatsHandler(w http.ResponseWriter, r *http.Request)
- type AllDeviceStats
- type AuthorizedServer
- type AuthorizedServers
- type AuthorizedServersResponse
- type BalancingAuthorityResponse
- type DeviceStats
- type EquipmentMigration
- type EquipmentResponse
- type GCARegistration
- type GCARegistrationResponse
- type GCAServer
- func NewGCAServer(baseDir string) (*GCAServer, error)
- func SetupTestEnvironment(testName string) (gcas *GCAServer, dir string, gcaPubKey glow.PublicKey, ...)
- func SetupTestEnvironmentKnownGCA(testName string, gcaPublicKey glow.PublicKey, gcaPrivateKey glow.PrivateKey) (gcas *GCAServer, dir string, err error)
- func (s *GCAServer) AllDeviceStatsHandler(w http.ResponseWriter, r *http.Request)
- func (gcas *GCAServer) AuthorizeEquipment(ea glow.EquipmentAuthorization, gcaPrivKey glow.PrivateKey) error
- func (gca *GCAServer) AuthorizeEquipmentHandler(w http.ResponseWriter, r *http.Request)
- func (gcas *GCAServer) AuthorizedServers() []AuthorizedServer
- func (s *GCAServer) AuthorizedServersHandler(w http.ResponseWriter, r *http.Request)
- func (s *GCAServer) AuthorizedServersHandlerPOST(w http.ResponseWriter, r *http.Request)
- func (gcas *GCAServer) BaseDir() string
- func (gcas *GCAServer) CheckInvariants()
- func (server *GCAServer) Close() error
- func (gcas *GCAServer) EquipmentHandler(w http.ResponseWriter, r *http.Request)
- func (gca *GCAServer) EquipmentMigrateHandler(w http.ResponseWriter, r *http.Request)
- func (gcas *GCAServer) Ports() (httpPort uint16, tcpPort uint16, udpPort uint16)
- func (gcas *GCAServer) PublicKey() glow.PublicKey
- func (s *GCAServer) RecentReportsHandler(w http.ResponseWriter, r *http.Request)
- func (s *GCAServer) RegisterGCAHandler(w http.ResponseWriter, r *http.Request)
- type GeoStatsResponse
- type LogLevel
- type Logger
- func (l *Logger) Close() error
- func (l *Logger) Debug(args ...interface{})
- func (l *Logger) Debugf(format string, args ...interface{})
- func (l *Logger) Error(args ...interface{})
- func (l *Logger) Errorf(format string, args ...interface{})
- func (l *Logger) Fatal(args ...interface{})
- func (l *Logger) Fatalf(format string, args ...interface{})
- func (l *Logger) Info(args ...interface{})
- func (l *Logger) Infof(format string, args ...interface{})
- func (l *Logger) Warn(args ...interface{})
- func (l *Logger) Warnf(format string, args ...interface{})
- type MOERData
- type RecentReportsResponse
- type WattTimeTokenResponse
Constants ¶
const ( // The name of the file that will contain the history of AllDeviceStats // objects. AllDeviceStatsHistoryFile = "allDeviceStats.dat" // MaxCapacityBuffer determines how much a solar farm is allowed to // exceed its capacity by in a 5 minute period without the report being // banned. There's in implied division by 100, so 135 implies 135%. MaxCapacityBuffer = 135 )
const ( ReportMigrationFrequency = 1 * time.Hour WattTimeWeekDataUpdateFrequency = 24 * time.Hour )
Variables ¶
This section is empty.
Functions ¶
func GeoStatsHandler ¶
func GeoStatsHandler(w http.ResponseWriter, r *http.Request)
GeoStatsHandler will respond to a call to the /geo-stats api endpoint.
Types ¶
type AllDeviceStats ¶
type AllDeviceStats struct { Devices []DeviceStats // A set of data for each device TimeslotOffset uint32 // Establish what week is covered by the data Signature glow.Signature }
AllDeviceStats contains aggregate weekly statistics
func DeserializeStreamAllDeviceStats ¶
func DeserializeStreamAllDeviceStats(b []byte) (AllDeviceStats, int, error)
DeserializeStreamAllDeviceStats will reverse a call to AllDeviceStats.Serialize(). This call is unique because it will count the number of bytes that it deserializes from the input array. The assumption is that the input array contains multiple AllDeviceStats objects listed one after another, and returning the size of each one allows them to be decoded consecutively more easily.
func (AllDeviceStats) Serialize ¶
func (ads AllDeviceStats) Serialize() []byte
Serialize will convert an AllDeviceStats to a byte slice.
func (AllDeviceStats) SigningBytes ¶
func (ads AllDeviceStats) SigningBytes() []byte
SigningBytes returns the set of bytes that should be signed by the GCA server to authenticate the response.
type AuthorizedServer ¶
type AuthorizedServer struct { PublicKey glow.PublicKey Banned bool Location string HttpPort uint16 TcpPort uint16 UdpPort uint16 GCAAuthorization glow.Signature }
AuthorizedServer tracks an authorized GCA server, complete with a signature from the GCA.
func (*AuthorizedServer) Serialize ¶
func (as *AuthorizedServer) Serialize() []byte
Create the serialization for the AuthorizedServer.
func (*AuthorizedServer) SigningBytes ¶
func (as *AuthorizedServer) SigningBytes() []byte
SigningBytes generates the byte slice for signing an AuthorizedServer.
type AuthorizedServers ¶
type AuthorizedServers struct {
// contains filtered or unexported fields
}
OtherServers contains a mutex-protected list of servers that are known to be in use by the GCA.
type AuthorizedServersResponse ¶
type AuthorizedServersResponse struct {
AuthorizedServers []AuthorizedServer `json:"AuthorizedServers"`
}
This struct is used for the GET request. It doesn't need to be authenticated because the servers are all already signed by the GCA.
type BalancingAuthorityResponse ¶
type BalancingAuthorityResponse struct {
Abbrev string `json:"abbrev"`
}
Define a struct to receive the information from a call to get the balancing authority from WattTime
type DeviceStats ¶
type DeviceStats struct { PublicKey glow.PublicKey PowerOutputs [2016]uint64 ImpactRates [2016]float64 }
DeviceStats contains the statistics for one device.
func (DeviceStats) MarshalJSON ¶
func (ds DeviceStats) MarshalJSON() ([]byte, error)
MarshalJSON will encode underflowed uint64 values as negative values when it reports in JSON.
NOTE: Code was written by GPT 4, but it appears to function correctly.
type EquipmentMigration ¶
type EquipmentMigration struct { Equipment glow.PublicKey // Which equipment is being migrated NewGCA glow.PublicKey // What GCA it's being migrated to NewShortID uint32 // What the new ShortID is for the equipment NewServers []AuthorizedServer // A list of servers for the new GCA (signed by the new GCA) Signature glow.Signature // A signature from the current GCA }
EquipmentMigrationRequest contains the fields that have an order from the GCA to migrate equipment.
Note: the authorized servers need to be individually validated by the new gca, but the struct as a whole needs to be validated by the current GCA.
func (EquipmentMigration) Serialize ¶
func (em EquipmentMigration) Serialize() []byte
Serialize will return a set of bytes that can be sent over the wire.
func (EquipmentMigration) SigningBytes ¶
func (em EquipmentMigration) SigningBytes() []byte
SigningBytes returns the data that should be signed by the EquipmentMigration.
type EquipmentResponse ¶
type EquipmentResponse struct {
EquipmentDetails map[uint32]glow.EquipmentAuthorization
}
type GCARegistration ¶
GCARegistration defines a request from the GCA to register itself on a server. The GCAKey is the GCA's real public key. The signature is signed by the GCA temp key which was installed on the machine before the GCA received their lockbook.
func (*GCARegistration) SigningBytes ¶
func (gr *GCARegistration) SigningBytes() []byte
SigningBytes generates the byte slice used for signing or verifying the GCAKey.
This method excludes the Signature field from the byte slice and adds a "GCAKey" prefix. The returned byte slice is intended for the signing operation.
type GCARegistrationResponse ¶
type GCARegistrationResponse struct { PublicKey glow.PublicKey HttpPort uint16 TcpPort uint16 UdpPort uint16 }
GCARegistrationResponse defines the response that the server writes after a successful GCA registration.
type GCAServer ¶
type GCAServer struct {
// contains filtered or unexported fields
}
GCAServer defines the structure for our Glow Certification Agent Server.
func NewGCAServer ¶
NewGCAServer initializes a new instance of GCAServer and returns either the GCAServer or an error.
baseDir specifies the directory where all server files will be stored. The function will create this directory if it does not exist.
func SetupTestEnvironment ¶
func SetupTestEnvironment(testName string) (gcas *GCAServer, dir string, gcaPubKey glow.PublicKey, gcaPrivKey glow.PrivateKey, err error)
SetupTestEnvironment will return a fully initialized gca server that is ready to be used.
func SetupTestEnvironmentKnownGCA ¶
func SetupTestEnvironmentKnownGCA(testName string, gcaPublicKey glow.PublicKey, gcaPrivateKey glow.PrivateKey) (gcas *GCAServer, dir string, err error)
Same as SetupTestEnvironment except that the GCA keys are already known.
func (*GCAServer) AllDeviceStatsHandler ¶
func (s *GCAServer) AllDeviceStatsHandler(w http.ResponseWriter, r *http.Request)
AllDeviceStatsHandler will return the statistics on all of the devices for the requested week.
func (*GCAServer) AuthorizeEquipment ¶
func (gcas *GCAServer) AuthorizeEquipment(ea glow.EquipmentAuthorization, gcaPrivKey glow.PrivateKey) error
AuthorizeEquipment will submit an equipment authorization to the GCA server for the provided equipment.
func (*GCAServer) AuthorizeEquipmentHandler ¶
func (gca *GCAServer) AuthorizeEquipmentHandler(w http.ResponseWriter, r *http.Request)
AuthorizeEquipmentHandler handles the authorization requests for equipment. This function serves as the HTTP handler for equipment authorization.
func (*GCAServer) AuthorizedServers ¶
func (gcas *GCAServer) AuthorizedServers() []AuthorizedServer
Returns the list of servers that have been authorized and/or banned by the GCA. Makes a copy to avoid race condition issues.
func (*GCAServer) AuthorizedServersHandler ¶
func (s *GCAServer) AuthorizedServersHandler(w http.ResponseWriter, r *http.Request)
The GET server just returns the set of authorized servers, including banned ones.
func (*GCAServer) AuthorizedServersHandlerPOST ¶
func (s *GCAServer) AuthorizedServersHandlerPOST(w http.ResponseWriter, r *http.Request)
The POST handler receives a single server to be added to the server collection. After the new server information is received, it will send details of that server to all of the other servers.
func (*GCAServer) CheckInvariants ¶
func (gcas *GCAServer) CheckInvariants()
CheckInvariants is a function which will ensure that the data on the server is self-consistent. If something is broken, it means the struct has corrupted and a panic is necessary to prevent grey goo from infecting the system.
This function is primarily used during testing, but doesn't hurt to run occasionally in prod.
func (*GCAServer) EquipmentHandler ¶
func (gcas *GCAServer) EquipmentHandler(w http.ResponseWriter, r *http.Request)
EquipmentHandler returns a list of all equipment, the corresponding ShortIDs, and the stats for each piece.
TODO: API endpoint is currently unsigned, and therefore unofficial. The signing step was skipped because we needed info in prod, we'll come back to it shortly.
func (*GCAServer) EquipmentMigrateHandler ¶
func (gca *GCAServer) EquipmentMigrateHandler(w http.ResponseWriter, r *http.Request)
EquipmentMigrateHandler handles an API request from the GCA to move a piece of equipment to a new GCA. Typically all equipment will be moved at once, but the requests need to be made one at a time.
func (*GCAServer) Ports ¶
Ports returns the ports that each of the listeners for this server are listening on.
func (*GCAServer) RecentReportsHandler ¶
func (s *GCAServer) RecentReportsHandler(w http.ResponseWriter, r *http.Request)
RecentReportsHandler handles requests for fetching the most recent equipment reports.
func (*GCAServer) RegisterGCAHandler ¶
func (s *GCAServer) RegisterGCAHandler(w http.ResponseWriter, r *http.Request)
RegisterGCAHandler handles the GCA registration requests. This function serves as the HTTP handler for GCA registration.
type GeoStatsResponse ¶
type GeoStatsResponse struct { AverageSunlight float64 `json:"average_sunlight"` AverageCarbonCertificates float64 `json:"average_carbon_certificates"` }
Define a struct that contains the response data for the call to the GeoStatsHandler.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger holds the configuration for a logger.
func NewLogger ¶
NewLogger initializes a new logger. logLevel: Level of log messages to display. logFile: File name to which logs will be written. Returns a pointer to a Logger or an error if any.
func (*Logger) Debug ¶
func (l *Logger) Debug(args ...interface{})
Debug logs debug messages using string concatenation.
func (*Logger) Error ¶
func (l *Logger) Error(args ...interface{})
Error logs error messages using string concatenation.
func (*Logger) Fatal ¶
func (l *Logger) Fatal(args ...interface{})
Fatal logs fatal messages using string concatenation and then panics.
func (*Logger) Info ¶
func (l *Logger) Info(args ...interface{})
Info logs informational messages using string concatenation.
type RecentReportsResponse ¶
type RecentReportsResponse struct { Reports [4032]glow.EquipmentReport `json:"Reports"` // Array of equipment reports TimeslotOffset uint32 `json:"TimeslotOffset"` // The timeslot offset of the first report Signature glow.Signature `json:"Signature"` // Signature of the GCA server }
RecentReportsResponse defines the output containing the equipment reports and a signature.
type WattTimeTokenResponse ¶
type WattTimeTokenResponse struct {
Token string `json:"token"`
}
Define a struct to receive the information from the call to get a token from WattTime.
Source Files ¶
- api.go
- api_authorized_servers.go
- api_device_stats.go
- api_equipment.go
- api_equipment_auth.go
- api_equipment_migrate.go
- api_geo_stats.go
- api_recent_reports.go
- api_server_gca_auth.go
- authorized_servers.go
- consts.go
- consts_p.go
- equipment.go
- logger.go
- report_listener_udp.go
- report_persist.go
- server.go
- sync_listener_tcp.go
- testing.go
- watttime.go