aboutsummaryrefslogtreecommitdiff
path: root/internal/node/primary/primary.go
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2022-05-24 23:33:38 +0200
committerRasmus Dahlberg <rasmus@mullvad.net>2022-06-23 11:33:17 +0200
commit559bccccd40d028e412d9f11709ded0250ba6dcd (patch)
tree50f3193dbe70fec21357963c11e5f663013f4b4c /internal/node/primary/primary.go
parent4b20ef0c1732bcef633c0ed7104501898aa84e2c (diff)
implement primary and secondary role, for replicationv0.5.0
Diffstat (limited to 'internal/node/primary/primary.go')
-rw-r--r--internal/node/primary/primary.go74
1 files changed, 74 insertions, 0 deletions
diff --git a/internal/node/primary/primary.go b/internal/node/primary/primary.go
new file mode 100644
index 0000000..6128f49
--- /dev/null
+++ b/internal/node/primary/primary.go
@@ -0,0 +1,74 @@
+package primary
+
+import (
+ "crypto"
+ "net/http"
+ "time"
+
+ "git.sigsum.org/log-go/internal/db"
+ "git.sigsum.org/log-go/internal/node/handler"
+ "git.sigsum.org/log-go/internal/state"
+ "git.sigsum.org/sigsum-go/pkg/client"
+ "git.sigsum.org/sigsum-go/pkg/dns"
+ "git.sigsum.org/sigsum-go/pkg/merkle"
+ "git.sigsum.org/sigsum-go/pkg/types"
+)
+
+// Config is a collection of log parameters
+type Config struct {
+ LogID string // H(public key), then hex-encoded
+ TreeID int64 // Merkle tree identifier used by Trillian
+ Prefix string // The portion between base URL and st/v0 (may be "")
+ MaxRange int64 // Maximum number of leaves per get-leaves request
+ Deadline time.Duration // Deadline used for gRPC requests
+ Interval time.Duration // Cosigning frequency
+ ShardStart uint64 // Shard interval start (num seconds since UNIX epoch)
+
+ // Witnesses map trusted witness identifiers to public keys
+ Witnesses map[merkle.Hash]types.PublicKey
+}
+
+// Primary is an instance of the log's primary node
+type Primary struct {
+ Config
+ PublicHTTPMux *http.ServeMux
+ InternalHTTPMux *http.ServeMux
+ TrillianClient db.Client // provides access to the Trillian backend
+ Signer crypto.Signer // provides access to Ed25519 private key
+ Stateman state.StateManager // coordinates access to (co)signed tree heads
+ DNS dns.Verifier // checks if domain name knows a public key
+ Secondary client.Client
+}
+
+// Implementing handler.Config
+func (p Primary) Prefix() string {
+ return p.Config.Prefix
+}
+func (p Primary) LogID() string {
+ return p.Config.LogID
+}
+func (p Primary) Deadline() time.Duration {
+ return p.Config.Deadline
+}
+
+// PublicHTTPHandlers returns all external handlers
+func (p Primary) PublicHTTPHandlers() []handler.Handler {
+ return []handler.Handler{
+ handler.Handler{p, addLeaf, types.EndpointAddLeaf, http.MethodPost},
+ handler.Handler{p, addCosignature, types.EndpointAddCosignature, http.MethodPost},
+ handler.Handler{p, getTreeHeadToCosign, types.EndpointGetTreeHeadToCosign, http.MethodGet},
+ handler.Handler{p, getTreeHeadCosigned, types.EndpointGetTreeHeadCosigned, http.MethodGet},
+ handler.Handler{p, getConsistencyProof, types.EndpointGetConsistencyProof, http.MethodGet},
+ handler.Handler{p, getInclusionProof, types.EndpointGetInclusionProof, http.MethodGet},
+ handler.Handler{p, getLeavesExternal, types.EndpointGetLeaves, http.MethodGet},
+ }
+}
+
+// InternalHTTPHandlers() returns all internal handlers
+func (p Primary) InternalHTTPHandlers() []handler.Handler {
+ return []handler.Handler{
+ handler.Handler{p, getTreeHeadUnsigned, types.EndpointGetTreeHeadUnsigned, http.MethodGet},
+ handler.Handler{p, getConsistencyProof, types.EndpointGetConsistencyProof, http.MethodGet},
+ handler.Handler{p, getLeavesInternal, types.EndpointGetLeaves, http.MethodGet},
+ }
+}