github.com/koko1123/flow-go-1@v0.29.6/network/message/protocols.go (about)

     1  package message
     2  
     3  type Protocol string
     4  
     5  const (
     6  	ProtocolPublish = Protocol("publish")
     7  	ProtocolUnicast = Protocol("unicast")
     8  )
     9  
    10  func (p Protocol) String() string {
    11  	return string(p)
    12  }
    13  
    14  // NewUnauthorizedProtocolError returns ErrUnauthorizedUnicastOnChannel or ErrUnauthorizedPublishOnChannel depending on the protocol provided.
    15  func NewUnauthorizedProtocolError(p Protocol) error {
    16  	if p == ProtocolUnicast {
    17  		return ErrUnauthorizedUnicastOnChannel
    18  	}
    19  
    20  	return ErrUnauthorizedPublishOnChannel
    21  }
    22  
    23  type Protocols []Protocol
    24  
    25  // Contains returns true if the protocol is in the list of Protocols.
    26  func (pr Protocols) Contains(protocol Protocol) bool {
    27  	for _, p := range pr {
    28  		if p == protocol {
    29  			return true
    30  		}
    31  	}
    32  
    33  	return false
    34  }