Skip to content

Commit

Permalink
Change leader endpoint to info.
Browse files Browse the repository at this point in the history
Fix typo errors.
  • Loading branch information
Jose Luis Lucas authored and iknite committed Feb 21, 2019
1 parent ef23483 commit 31dc27f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
11 changes: 6 additions & 5 deletions api/apihttp/apihttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import (
"net/http"
"time"

"github.com/prometheus/client_golang/prometheus"

"github.com/bbva/qed/log"
"github.com/bbva/qed/metrics"
"github.com/bbva/qed/protocol"
"github.com/bbva/qed/raftwal"

"github.com/prometheus/client_golang/prometheus"
)

// HealthCheckResponse contains the response from HealthCheckHandler.
Expand Down Expand Up @@ -316,13 +316,14 @@ func AuthHandlerMiddleware(handler http.HandlerFunc) http.HandlerFunc {
// /events -> Add
// /proofs/membership -> Membership
func NewApiHttp(balloon raftwal.RaftBalloonApi) *http.ServeMux {

api := http.NewServeMux()
api.HandleFunc("/health-check", AuthHandlerMiddleware(HealthCheckHandler))
api.HandleFunc("/events", AuthHandlerMiddleware(Add(balloon)))
api.HandleFunc("/proofs/membership", AuthHandlerMiddleware(Membership(balloon)))
api.HandleFunc("/proofs/digest-membership", AuthHandlerMiddleware(DigestMembership(balloon)))
api.HandleFunc("/proofs/incremental", AuthHandlerMiddleware(Incremental(balloon)))
api.HandleFunc("/leader", AuthHandlerMiddleware(LeaderHandle(balloon)))
api.HandleFunc("/info", AuthHandlerMiddleware(InfoHandle(balloon)))

return api
}
Expand Down Expand Up @@ -362,15 +363,15 @@ func LogHandler(handle http.Handler) http.HandlerFunc {
}
}

func LeaderHandle(balloon raftwal.RaftBalloonApi) http.HandlerFunc {
func InfoHandle(balloon raftwal.RaftBalloonApi) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if r.Method != "GET" {
w.Header().Set("Allow", "GET")
w.WriteHeader(http.StatusMethodNotAllowed)
return
}

out, err := json.Marshal(balloon.LeaderAddr())
out, err := json.Marshal(balloon.Info())
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
Expand Down
7 changes: 5 additions & 2 deletions api/apihttp/apihttp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,11 @@ func (b fakeRaftBalloon) QueryConsistency(start, end uint64) (*balloon.Increment
return &ip, nil
}

func (b fakeRaftBalloon) LeaderAddr() string {
return b.raftBindAddr
func (b fakeRaftBalloon) Info() map[string]interface{} {
m := make(map[string]interface{})
m["Type"] = "fakeRaftBalloon"
m["LeaderAddr"] = b.raftBindAddr
return m
}

func TestHealthCheckHandler(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion balloon/history/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ func (p IncrementalProof) Verify(startDigest, endDigest hashing.Digest) (correct
// visit the pruned trees
startRecomputed := startPruned.PostOrder(computeHash).(hashing.Digest)
endRecomputed := endPruned.PostOrder(computeHash).(hashing.Digest)

return bytes.Equal(startRecomputed, startDigest) && bytes.Equal(endRecomputed, endDigest)

}
5 changes: 2 additions & 3 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,11 @@ func (c HTTPClient) VerifyIncremental(
Version: startSnapshot.Version,
}
end := &balloon.Snapshot{
HistoryDigest: endSnapshot.EventDigest,
EventDigest: endSnapshot.HistoryDigest,
EventDigest: endSnapshot.EventDigest,
HistoryDigest: endSnapshot.HistoryDigest,
HyperDigest: endSnapshot.HyperDigest,
Version: endSnapshot.Version,
}

return proof.Verify(start, end)

}
10 changes: 9 additions & 1 deletion raftwal/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type RaftBalloonApi interface {
QueryConsistency(start, end uint64) (*balloon.IncrementalProof, error)
// Join joins the node, identified by nodeID and reachable at addr, to the cluster
Join(nodeID, addr string) error
LeaderAddr() string
Info() map[string]interface{}
}

// RaftBalloon is a replicated verifiable key-value store, where changes are made via Raft consensus.
Expand Down Expand Up @@ -319,6 +319,14 @@ func (b *RaftBalloon) ID() string {
return b.id
}

// TODO Improve info structure.
// Info returns the Raft leader address.
func (b *RaftBalloon) Info() map[string]interface{} {
m := make(map[string]interface{})
m["LeaderAddr"] = b.LeaderAddr()
return m
}

// LeaderID returns the node ID of the Raft leader. Returns a
// blank string if there is no leader, or an error.
func (b *RaftBalloon) LeaderID() (string, error) {
Expand Down

0 comments on commit 31dc27f

Please sign in to comment.