Skip to content

Commit

Permalink
Doc: Add godoc to protocol package.
Browse files Browse the repository at this point in the history
Refers to #40
  • Loading branch information
Jose Luis Lucas committed Jun 17, 2019
1 parent db255a3 commit d30ba51
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
43 changes: 26 additions & 17 deletions protocol/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
limitations under the License.
*/

// Package protocol defines the information types required and expected when
// interacting with QED.
package protocol

import (
"encoding/json"
"net"

"github.com/bbva/qed/balloon"
"github.com/bbva/qed/balloon/history"
Expand All @@ -33,6 +34,8 @@ type Event struct {
Event []byte
}

// EventBulk is the public struct that AddBulk handler function uses to
// parse the post params.
type EventsBulk struct {
Events [][]byte
}
Expand All @@ -59,6 +62,17 @@ type Snapshot struct {
Version uint64
}

func (b *Snapshot) Encode() ([]byte, error) {
return json.Marshal(b)
}

func (b *Snapshot) Decode(msg []byte) error {
err := json.Unmarshal(msg, b)
return err
}

// SignedSnapshot is the public struct that apihttp.Add Handler call returns.
// It is comprised of a Snapshot and a signature.
type SignedSnapshot struct {
Snapshot *Snapshot
Signature []byte
Expand All @@ -73,25 +87,13 @@ func (b *SignedSnapshot) Decode(msg []byte) error {
return err
}

// BatchSnapshots is information structure that QED sends to Agents, and
// Agents to alerts/snapshot store.
// It is comprised of an array of Signed Snapshots.
type BatchSnapshots struct {
Snapshots []*SignedSnapshot
}

type Source struct {
Addr net.IP
Port uint16
Role string
}

func (b *Snapshot) Encode() ([]byte, error) {
return json.Marshal(b)
}

func (b *Snapshot) Decode(msg []byte) error {
err := json.Unmarshal(msg, b)
return err
}

func (b *BatchSnapshots) Encode() ([]byte, error) {
return json.Marshal(b)
}
Expand All @@ -101,6 +103,7 @@ func (b *BatchSnapshots) Decode(msg []byte) error {
return err
}

// MembershipResult is the information structure needed or a Membership proof.
type MembershipResult struct {
Exists bool
Hyper map[string]hashing.Digest
Expand All @@ -112,11 +115,13 @@ type MembershipResult struct {
Key []byte
}

// IncrementalRequest is the information structure needed to ask for an incremental request.
type IncrementalRequest struct {
Start uint64
End uint64
}

// IncrementalResponse is the information structure expected from an incremental proof request.
type IncrementalResponse struct {
Start uint64
End uint64
Expand Down Expand Up @@ -145,7 +150,7 @@ func ToMembershipResult(key []byte, mp *balloon.MembershipProof) *MembershipResu
}

// ToBaloonProof translate public protocol.MembershipResult to internal
// balloon.Proof.
// balloon.MembershipProof.
func ToBalloonProof(mr *MembershipResult, hasherF func() hashing.Hasher) *balloon.MembershipProof {

historyProof := history.NewMembershipProof(
Expand Down Expand Up @@ -176,6 +181,8 @@ func ToBalloonProof(mr *MembershipResult, hasherF func() hashing.Hasher) *balloo

}

// ToIncrementalResponse translates internal api balloon.IncrementalProof to the
// public struct protocol.IncrementalResponse.
func ToIncrementalResponse(proof *balloon.IncrementalProof) *IncrementalResponse {
return &IncrementalResponse{
proof.Start,
Expand All @@ -184,6 +191,8 @@ func ToIncrementalResponse(proof *balloon.IncrementalProof) *IncrementalResponse
}
}

// ToIncrementalProof translate public protocol.IncrementalResponse to internal
// balloon.IncrementalProof.
func ToIncrementalProof(ir *IncrementalResponse, hasherF func() hashing.Hasher) *balloon.IncrementalProof {
return balloon.NewIncrementalProof(ir.Start, ir.End, history.ParseAuditPath(ir.AuditPath), hasherF())
}
2 changes: 2 additions & 0 deletions protocol/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ const (
Https Scheme = "https"
)

// ShardDetail is the information required to define a Shard.
type ShardDetail struct {
NodeId string `json:"nodeId"`
HTTPAddr string `json:"httpAddr"`
}

// Shards is the public struct that apihttp.InfoShardsHandler call returns.
type Shards struct {
NodeId string `json:"nodeId"`
LeaderId string `json:"leaderId"`
Expand Down

0 comments on commit d30ba51

Please sign in to comment.