Documentation
¶
Index ¶
- Constants
- Variables
- func Confirm(p ProtocolHandler, replyValid bool, agreementId string, ...) error
- func ExtractProtocol(msg string) (string, error)
- func NotifyDataReceipt(p ProtocolHandler, agreementId string, messageTarget interface{}, ...) error
- func NotifyDataReceiptAck(p ProtocolHandler, agreementId string, messageTarget interface{}, ...) error
- func NotifyMeterReading(p ProtocolHandler, agreementId string, mn *metering.MeteringNotification, ...) (string, error)
- func RecordAgreement(p ProtocolHandler, newProposal Proposal, consumerPolicy *policy.Policy, ...) error
- func SendProposal(p ProtocolHandler, newProposal Proposal, consumerPolicy *policy.Policy, ...) error
- func SendProtocolMessage(messageTarget interface{}, msg interface{}, ...) error
- func TerminateAgreement(p ProtocolHandler, policies []policy.Policy, agreementId string, org string, ...) error
- type BaseCancel
- type BaseDataReceived
- type BaseDataReceivedAck
- type BaseNotifyMetering
- type BaseProposal
- type BaseProposalReply
- func (bp *BaseProposalReply) AcceptProposal()
- func (bp *BaseProposalReply) DeviceId() string
- func (bp *BaseProposalReply) DoNotAcceptProposal()
- func (bp *BaseProposalReply) IsValid() bool
- func (bp *BaseProposalReply) ProposalAccepted() bool
- func (bp *BaseProposalReply) ShortString() string
- func (bp *BaseProposalReply) String() string
- type BaseProtocolHandler
- type BaseProtocolMessage
- func (pm *BaseProtocolMessage) AgreementId() string
- func (pm *BaseProtocolMessage) IsValid() bool
- func (pm *BaseProtocolMessage) Protocol() string
- func (pm *BaseProtocolMessage) ShortString() string
- func (pm *BaseProtocolMessage) String() string
- func (pm *BaseProtocolMessage) Type() string
- func (pm *BaseProtocolMessage) Version() int
- type BaseReplyAck
- type Cancel
- type DataReceived
- type DataReceivedAck
- type NotifyMetering
- type Proposal
- type ProposalReply
- type ProtocolHandler
- type ProtocolMessage
- type ReplyAck
Constants ¶
const MsgTypeCancel = "cancel"
const MsgTypeDataReceived = "dataverification"
const MsgTypeDataReceivedAck = "dataverificationack"
const MsgTypeNotifyMetering = "meteringnotification"
const MsgTypeProposal = "proposal"
Protocol message types
const MsgTypeReply = "reply"
const MsgTypeReplyAck = "replyack"
Variables ¶
var AAPlogString = func(p string, v interface{}) string { return fmt.Sprintf("AbstractProtocol (%v): %v", p, v) }
Functions ¶
func Confirm ¶
func Confirm(p ProtocolHandler, replyValid bool, agreementId string, messageTarget interface{}, sendMessage func(mt interface{}, pay []byte) error) error
Confirm a reply from a producer.
func ExtractProtocol ¶
Extract the agreement protocol name from stringified message
func NotifyDataReceipt ¶
func NotifyDataReceipt(p ProtocolHandler, agreementId string, messageTarget interface{}, sendMessage func(mt interface{}, pay []byte) error) error
Notify a producer that data was detected by the consumer at the data ingest.
func NotifyDataReceiptAck ¶
func NotifyDataReceiptAck(p ProtocolHandler, agreementId string, messageTarget interface{}, sendMessage func(mt interface{}, pay []byte) error) error
Confirm that a DataReceived message as received.
func NotifyMeterReading ¶
func NotifyMeterReading(p ProtocolHandler, agreementId string, mn *metering.MeteringNotification, messageTarget interface{}, sendMessage func(mt interface{}, pay []byte) error) (string, error)
Send a metering notification to the producer.
func RecordAgreement ¶
func SendProposal ¶
func SendProposal(p ProtocolHandler, newProposal Proposal, consumerPolicy *policy.Policy, org string, messageTarget interface{}, sendMessage func(msgTarget interface{}, pay []byte) error) error
Send the proposal to the other party.
func SendProtocolMessage ¶
func SendProtocolMessage(messageTarget interface{}, msg interface{}, sendMessage func(mt interface{}, pay []byte) error) error
Send a message containing the proposal.
func TerminateAgreement ¶
Types ¶
type BaseCancel ¶
type BaseCancel struct { *BaseProtocolMessage TheReason uint `json:"reason"` }
This struct is the cancel that flows from the consumer to the producer or producer to consumer.
func NewBaseCancel ¶
func NewBaseCancel(name string, version int, id string, reason uint) *BaseCancel
func (*BaseCancel) IsValid ¶
func (bc *BaseCancel) IsValid() bool
func (*BaseCancel) Reason ¶
func (bc *BaseCancel) Reason() uint
func (*BaseCancel) ShortString ¶
func (bc *BaseCancel) ShortString() string
func (*BaseCancel) String ¶
func (bc *BaseCancel) String() string
type BaseDataReceived ¶
type BaseDataReceived struct {
*BaseProtocolMessage
}
This struct is the data received message that flows from the consumer to the producer. It indicates that the consumer has seen data being received from the workloads on the device.
func NewDataReceived ¶
func NewDataReceived(name string, version int, id string) *BaseDataReceived
func (*BaseDataReceived) IsValid ¶
func (dr *BaseDataReceived) IsValid() bool
func (*BaseDataReceived) ShortString ¶
func (dr *BaseDataReceived) ShortString() string
func (*BaseDataReceived) String ¶
func (dr *BaseDataReceived) String() string
type BaseDataReceivedAck ¶
type BaseDataReceivedAck struct {
*BaseProtocolMessage
}
This struct is the data received message that flows from the consumer to the producer. It indicates that the consumer has seen data being received from the workloads on the device.
func NewDataReceivedAck ¶
func NewDataReceivedAck(name string, version int, id string) *BaseDataReceivedAck
func (*BaseDataReceivedAck) IsValid ¶
func (dr *BaseDataReceivedAck) IsValid() bool
func (*BaseDataReceivedAck) ShortString ¶
func (dr *BaseDataReceivedAck) ShortString() string
func (*BaseDataReceivedAck) String ¶
func (dr *BaseDataReceivedAck) String() string
type BaseNotifyMetering ¶
type BaseNotifyMetering struct { *BaseProtocolMessage MeterReading string `json:"meter_reading"` }
This struct is the metering notification that flows from the consumer to the producer. It indicates that the consumer has seen data being received from the workloads on the device and is granting some metering tokens.
func NewNotifyMetering ¶
func NewNotifyMetering(name string, version int, id string, m string) *BaseNotifyMetering
func (*BaseNotifyMetering) IsValid ¶
func (bn *BaseNotifyMetering) IsValid() bool
func (*BaseNotifyMetering) Meter ¶
func (bn *BaseNotifyMetering) Meter() string
func (*BaseNotifyMetering) ShortString ¶
func (bn *BaseNotifyMetering) ShortString() string
func (*BaseNotifyMetering) String ¶
func (bn *BaseNotifyMetering) String() string
type BaseProposal ¶
type BaseProposal struct { *BaseProtocolMessage TsandCs string `json:"tsandcs"` // This is a JSON serialized policy file, merged between consumer and producer. It has 1 workload array element. Producerpolicy string `json:"producerPolicy"` Consumerid string `json:"consumerId"` }
A concrete Proposal object that implements all the functions of a Proposal interface. This represents the base protocol object for a proposal. Other agreement protocols might wish to embed and then extend this object.
func CreateProposal ¶
func CreateProposal(p ProtocolHandler, agreementId string, producerPolicy *policy.Policy, consumerPolicy *policy.Policy, version int, myId string, workload *policy.Workload, defaultPW string, defaultNoData uint64) (*BaseProposal, error)
Create a proposal based on input policies and other configuration information.
func NewProposal ¶
func (*BaseProposal) ConsumerId ¶
func (bp *BaseProposal) ConsumerId() string
func (*BaseProposal) IsValid ¶
func (bp *BaseProposal) IsValid() bool
func (*BaseProposal) ProducerPolicy ¶
func (bp *BaseProposal) ProducerPolicy() string
func (*BaseProposal) ShortString ¶
func (bp *BaseProposal) ShortString() string
func (*BaseProposal) String ¶
func (bp *BaseProposal) String() string
func (*BaseProposal) TsAndCs ¶
func (bp *BaseProposal) TsAndCs() string
type BaseProposalReply ¶
type BaseProposalReply struct { *BaseProtocolMessage Decision bool `json:"decision"` Deviceid string `json:"deviceId"` }
A concrete ProposalReply object that implements all the functions of a ProposalReply interface. This represents the base protocol object for a proposal reply. Other agreement protocols might wish to embed and then extend this object.
func DecideOnProposal ¶
func DecideOnProposal(p ProtocolHandler, proposal Proposal, myId string, myOrg string) (*BaseProposalReply, error)
Decide to accept or reject a proposal based on whether the proposal is acceptable and agreement limits have not been hit.
func NewProposalReply ¶
func NewProposalReply(name string, version int, id string, deviceId string) *BaseProposalReply
func (*BaseProposalReply) AcceptProposal ¶
func (bp *BaseProposalReply) AcceptProposal()
func (*BaseProposalReply) DeviceId ¶
func (bp *BaseProposalReply) DeviceId() string
func (*BaseProposalReply) DoNotAcceptProposal ¶
func (bp *BaseProposalReply) DoNotAcceptProposal()
func (*BaseProposalReply) IsValid ¶
func (bp *BaseProposalReply) IsValid() bool
func (*BaseProposalReply) ProposalAccepted ¶
func (bp *BaseProposalReply) ProposalAccepted() bool
func (*BaseProposalReply) ShortString ¶
func (bp *BaseProposalReply) ShortString() string
func (*BaseProposalReply) String ¶
func (bp *BaseProposalReply) String() string
type BaseProtocolHandler ¶
type BaseProtocolHandler struct {
// contains filtered or unexported fields
}
func NewBaseProtocolHandler ¶
func NewBaseProtocolHandler(n string, v int, h *http.Client, p *policy.PolicyManager) *BaseProtocolHandler
func (*BaseProtocolHandler) HTTPClient ¶
func (bp *BaseProtocolHandler) HTTPClient() *http.Client
func (*BaseProtocolHandler) Name ¶
func (bp *BaseProtocolHandler) Name() string
func (*BaseProtocolHandler) PolicyManager ¶
func (bp *BaseProtocolHandler) PolicyManager() *policy.PolicyManager
func (*BaseProtocolHandler) Version ¶
func (bp *BaseProtocolHandler) Version() int
type BaseProtocolMessage ¶
type BaseProtocolMessage struct { MsgType string `json:"type"` AProtocol string `json:"protocol"` AVersion int `json:"version"` AgreeId string `json:"agreementId"` }
func (*BaseProtocolMessage) AgreementId ¶
func (pm *BaseProtocolMessage) AgreementId() string
func (*BaseProtocolMessage) IsValid ¶
func (pm *BaseProtocolMessage) IsValid() bool
func (*BaseProtocolMessage) Protocol ¶
func (pm *BaseProtocolMessage) Protocol() string
func (*BaseProtocolMessage) ShortString ¶
func (pm *BaseProtocolMessage) ShortString() string
func (*BaseProtocolMessage) String ¶
func (pm *BaseProtocolMessage) String() string
func (*BaseProtocolMessage) Type ¶
func (pm *BaseProtocolMessage) Type() string
func (*BaseProtocolMessage) Version ¶
func (pm *BaseProtocolMessage) Version() int
type BaseReplyAck ¶
type BaseReplyAck struct { *BaseProtocolMessage StillValid bool `json:"decision"` }
This struct is the reply ack that flows from the consumer to the producer. The StillValid field tells the producer whether (true) or not (false) the consumer is still pursuing the agreement.
func NewReplyAck ¶
func NewReplyAck(name string, version int, decision bool, id string) *BaseReplyAck
func (*BaseReplyAck) IsValid ¶
func (br *BaseReplyAck) IsValid() bool
func (*BaseReplyAck) ReplyAgreementStillValid ¶
func (br *BaseReplyAck) ReplyAgreementStillValid() bool
func (*BaseReplyAck) ShortString ¶
func (br *BaseReplyAck) ShortString() string
func (*BaseReplyAck) String ¶
func (br *BaseReplyAck) String() string
type DataReceived ¶
type DataReceived interface { ProtocolMessage }
func ValidateDataReceived ¶
func ValidateDataReceived(dr string) (DataReceived, error)
type DataReceivedAck ¶
type DataReceivedAck interface { }
func ValidateDataReceivedAck ¶
func ValidateDataReceivedAck(dra string) (DataReceivedAck, error)
type NotifyMetering ¶
type NotifyMetering interface { ProtocolMessage Meter() string }
func ValidateMeterNotification ¶
func ValidateMeterNotification(mn string) (NotifyMetering, error)
type Proposal ¶
type Proposal interface { ProtocolMessage TsAndCs() string ProducerPolicy() string ConsumerId() string }
The interface for the base proposal type
func DemarshalProposal ¶
func ValidateProposal ¶
Validate that the input string is a proposal message.
type ProposalReply ¶
type ProposalReply interface { ProtocolMessage ProposalAccepted() bool DeviceId() string AcceptProposal() DoNotAcceptProposal() }
The interface for the base proposal type
func SendResponse ¶
func SendResponse(p ProtocolHandler, proposal Proposal, newReply ProposalReply, myOrg string, replyErr error, messageTarget interface{}, sendMessage func(mt interface{}, pay []byte) error) (ProposalReply, error)
Send a reply to the proposal.
func ValidateReply ¶
func ValidateReply(replyMsg string) (ProposalReply, error)
type ProtocolHandler ¶
type ProtocolHandler interface { // Base protocol handler methods. These are implemented by the abstract interface. Name() string Version() int PolicyManager() *policy.PolicyManager HTTPClient() *http.Client // Protocol methods that the handler has to implement InitiateAgreement(agreementId string, producerPolicy *policy.Policy, consumerPolicy *policy.Policy, org string, myId string, messageTarget interface{}, workload *policy.Workload, defaultPW string, defaultNoData uint64, sendMessage func(msgTarget interface{}, pay []byte) error) (Proposal, error) DemarshalProposal(proposal string) (Proposal, error) DecideOnProposal(proposal Proposal, myId string, myOrg string, runningBlockchains []map[string]string, messageTarget interface{}, sendMessage func(mt interface{}, pay []byte) error) (ProposalReply, error) Confirm(replyValid bool, agreementId string, messageTarget interface{}, sendMessage func(mt interface{}, pay []byte) error) error NotifyDataReceipt(agreementId string, messageTarget interface{}, sendMessage func(mt interface{}, pay []byte) error) error NotifyDataReceiptAck(agreementId string, messageTarget interface{}, sendMessage func(mt interface{}, pay []byte) error) error NotifyMetering(agreementId string, mn *metering.MeteringNotification, messageTarget interface{}, sendMessage func(mt interface{}, pay []byte) error) (string, error) RecordAgreement(newProposal Proposal, reply ProposalReply, addr string, sig string, consumerPolicy *policy.Policy, org string) error TerminateAgreement(policies []policy.Policy, counterParty string, agreementId string, org string, reason uint, messageTarget interface{}, sendMessage func(mt interface{}, pay []byte) error) error VerifyAgreement(agreementId string, counterParty string, expectedSignature string, messageTarget interface{}, sendMessage func(mt interface{}, pay []byte) error) (bool, error) RecordMeter(agreementId string, mn *metering.MeteringNotification) error // Protocol message validators ValidateProposal(proposal string) (Proposal, error) ValidateReply(reply string) (ProposalReply, error) ValidateReplyAck(replyAck string) (ReplyAck, error) ValidateDataReceived(dr string) (DataReceived, error) ValidateDataReceivedAck(dra string) (DataReceivedAck, error) ValidateMeterNotification(mn string) (NotifyMetering, error) ValidateCancel(can string) (Cancel, error) }
======================================================================================================= Protocol Handler - This is the interface that Horizon uses to interact with agreement protocol implementations.
type ProtocolMessage ¶
type ProtocolMessage interface { IsValid() bool String() string ShortString() string Type() string Protocol() string Version() int AgreementId() string }
All protocol message have the following header info.
type ReplyAck ¶
type ReplyAck interface { ProtocolMessage ReplyAgreementStillValid() bool }