diff options
author | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2020-10-20 17:36:49 +0200 |
---|---|---|
committer | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2020-10-20 17:36:49 +0200 |
commit | 2fd1c7efe81d843b8828916ff692364cca2cc1c1 (patch) | |
tree | 3e15095e7fb36926061eaa2da3fd5271e3ee00bb /instance.go | |
parent | b9b3551d79ae14c89088c233e655017724d59a08 (diff) |
added basic structure
An STFE server instance that dials the Trillian gRPC back-end, and which
listens on six different HTTP endpoints but without any actual processing.
Diffstat (limited to 'instance.go')
-rw-r--r-- | instance.go | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/instance.go b/instance.go new file mode 100644 index 0000000..5fa1b6c --- /dev/null +++ b/instance.go @@ -0,0 +1,50 @@ +package stfe + +import ( + "time" + + "net/http" + + "github.com/golang/glog" + "github.com/google/trillian" + + ctutil "github.com/google/certificate-transparency-go/trillian/util" +) + +// instance groups information about a specific STFE instance. +type instance struct { + prefix string + logID int64 + client trillian.TrillianLogClient + deadline time.Duration + timesource ctutil.TimeSource +} + +// NewInstance returns a new STFE instance +func NewInstance(prefix string, id int64, client trillian.TrillianLogClient, deadline time.Duration, timesource ctutil.TimeSource) *instance { + return &instance{ + prefix: prefix, + logID: id, + client: client, + deadline: deadline, + timesource: timesource, + } +} + +// addEndpoints registers STFE handler functions for the respective HTTP paths +func (i *instance) AddEndpoints(mux *http.ServeMux) { + for _, endpoint := range []struct { + path string + handler appHandler + }{ + {i.prefix + "/add-entry", appHandler{instance: i, handler: addEntry, endpoint: "add-entry", method: http.MethodPost}}, + {i.prefix + "/get-entries", appHandler{instance: i, handler: getEntries, endpoint: "get-entries", method: http.MethodGet}}, + {i.prefix + "/get-anchors", appHandler{instance: i, handler: getAnchors, endpoint: "get-anchors", method: http.MethodGet}}, + {i.prefix + "/get-proof-by-hash", appHandler{instance: i, handler: getProofByHash, endpoint: "get-proof-by-hash", method: http.MethodGet}}, + {i.prefix + "/get-consistency-proof", appHandler{instance: i, handler: getConsistencyProof, endpoint: "get-consistency-proof", method: http.MethodGet}}, + {i.prefix + "/get-sth", appHandler{instance: i, handler: getSth, endpoint: "get-sth", method: http.MethodGet}}, + } { + glog.Infof("adding handler for %v", endpoint.path) + mux.Handle(endpoint.path, endpoint.handler) + } +} |