github.com/xiaqingdoc/fabric@v2.1.1+incompatible/gossip/common/common.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package common
     8  
     9  import (
    10  	"bytes"
    11  	"encoding/hex"
    12  )
    13  
    14  // PKIidType defines the type that holds the PKI-id
    15  // which is the security identifier of a peer
    16  type PKIidType []byte
    17  
    18  func (p PKIidType) String() string {
    19  	if p == nil {
    20  		return "<nil>"
    21  	}
    22  	return hex.EncodeToString(p)
    23  }
    24  
    25  // IsNotSameFilter generate filter function which
    26  // provides a predicate to identify whenever current id
    27  // equals to another one.
    28  func (id PKIidType) IsNotSameFilter(that PKIidType) bool {
    29  	return !bytes.Equal(id, that)
    30  }
    31  
    32  // MessageAcceptor is a predicate that is used to
    33  // determine in which messages the subscriber that created the
    34  // instance of the MessageAcceptor is interested in.
    35  type MessageAcceptor func(interface{}) bool
    36  
    37  // Payload defines an object that contains a ledger block
    38  type Payload struct {
    39  	ChannelID ChannelID // The channel's ID of the block
    40  	Data      []byte    // The content of the message, possibly encrypted or signed
    41  	Hash      string    // The message hash
    42  	SeqNum    uint64    // The message sequence number
    43  }
    44  
    45  // ChannelID defines the identity representation of a chain
    46  type ChannelID []byte
    47  
    48  // MessageReplacingPolicy Returns:
    49  // MESSAGE_INVALIDATES if this message invalidates that
    50  // MESSAGE_INVALIDATED if this message is invalidated by that
    51  // MESSAGE_NO_ACTION otherwise
    52  type MessageReplacingPolicy func(this interface{}, that interface{}) InvalidationResult
    53  
    54  // InvalidationResult determines how a message affects another message
    55  // when it is put into gossip message store
    56  type InvalidationResult int
    57  
    58  const (
    59  	// MessageNoAction means messages have no relation
    60  	MessageNoAction InvalidationResult = iota
    61  	// MessageInvalidates means message invalidates the other message
    62  	MessageInvalidates
    63  	// MessageInvalidated means message is invalidated by the other message
    64  	MessageInvalidated
    65  )