util

package
Version: v2.1.1+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2020 License: Apache-2.0 Imports: 28 Imported by: 1,061

Documentation

Index

Constants

View Source
const (
	ChannelLogger     = "gossip.channel"
	CommLogger        = "gossip.comm"
	DiscoveryLogger   = "gossip.discovery"
	ElectionLogger    = "gossip.election"
	GossipLogger      = "gossip.gossip"
	CommMockLogger    = "gossip.comm.mock"
	PullLogger        = "gossip.pull"
	ServiceLogger     = "gossip.service"
	StateLogger       = "gossip.state"
	PrivateDataLogger = "gossip.privdata"
)

Logger names for logger initialization.

Variables

This section is empty.

Functions

func BytesToStrings added in v1.3.0

func BytesToStrings(bytes [][]byte) []string

func Contains added in v1.1.0

func Contains(s string, a []string) bool

Contains returns whether a given slice a contains a string s

func CreateGRPCLayer added in v1.4.1

func CreateGRPCLayer() (port int, gRPCServer *comm.GRPCServer, certs *common.TLSCertificates,
	secureDialOpts api.PeerSecureDialOpts, dialOpts []grpc.DialOption)

CreateGRPCLayer returns a new gRPC server with associated port, TLS certificates, SecureDialOpts and DialOption

func GetDurationOrDefault

func GetDurationOrDefault(key string, defVal time.Duration) time.Duration

GetDurationOrDefault returns the Duration value from config if present otherwise default value

func GetFloat64OrDefault added in v1.2.0

func GetFloat64OrDefault(key string, defVal float64) float64

GetFloat64OrDefault returns the float64 value from config if present otherwise default value

func GetIntOrDefault

func GetIntOrDefault(key string, defVal int) int

GetIntOrDefault returns the int value from config if present otherwise default value

func GetRandomIndices

func GetRandomIndices(indiceCount, highestIndex int) []int

GetRandomIndices returns indiceCount random indices from 0 to highestIndex.

func IndexInSlice

func IndexInSlice(array interface{}, o interface{}, equals Equals) int

IndexInSlice returns the index of given object o in array, and -1 if it is not in array.

func PrintStackTrace

func PrintStackTrace()

PrintStackTrace prints to stdout all goroutines

func PrivateRWSets added in v1.1.0

func PrivateRWSets(rwsets ...PrivateRWSet) [][]byte

PrivateRWSets creates an aggregated slice of RWSets

func RandomInt

func RandomInt(n int) int

RandomInt returns, as an int, a non-negative pseudo-random integer in [0,n) It panics if n <= 0

func RandomUInt64

func RandomUInt64() uint64

RandomUInt64 returns a random uint64

If we want a rand that's non-global and specific to gossip, we can establish one. Otherwise this uses the process-global locking RNG.

func SetVal added in v1.4.0

func SetVal(key string, val interface{})

SetVal stores key value to viper

func SetupTestLogging

func SetupTestLogging()

SetupTestLogging sets the default log levels for gossip unit tests to defaultTestSpec

func SetupTestLoggingWithLevel

func SetupTestLoggingWithLevel(level string)

SetupTestLoggingWithLevel sets the default log levels for gossip unit tests to level

func StringsToBytes added in v1.3.0

func StringsToBytes(strings []string) [][]byte

Types

type Equals

type Equals func(a interface{}, b interface{}) bool

Equals returns whether a and b are the same

type Logger added in v1.3.0

type Logger interface {
	Debug(args ...interface{})
	Debugf(format string, args ...interface{})
	Error(args ...interface{})
	Errorf(format string, args ...interface{})
	Fatal(args ...interface{})
	Fatalf(format string, args ...interface{})
	Info(args ...interface{})
	Infof(format string, args ...interface{})
	Panic(args ...interface{})
	Panicf(format string, args ...interface{})
	Warning(args ...interface{})
	Warningf(format string, args ...interface{})
	IsEnabledFor(l zapcore.Level) bool
	With(args ...interface{}) *flogging.FabricLogger
}

func GetLogger

func GetLogger(name string, peerID string) Logger

GetLogger returns a logger for given gossip logger name and peerID

type MembershipStore

type MembershipStore struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

MembershipStore struct which encapsulates membership message store abstraction

func NewMembershipStore

func NewMembershipStore() *MembershipStore

NewMembershipStore creates new membership store instance

func (*MembershipStore) MsgByID

MsgByID returns a message stored by a certain ID, or nil if such an ID isn't found

func (*MembershipStore) Put

Put associates msg with the given pkiID

func (*MembershipStore) Remove

func (m *MembershipStore) Remove(pkiID common.PKIidType)

Remove removes a message with a given pkiID

func (*MembershipStore) Size

func (m *MembershipStore) Size() int

Size of the membership store

func (*MembershipStore) ToSlice

ToSlice returns a slice backed by the elements of the MembershipStore

type PrivateRWSet added in v1.1.0

type PrivateRWSet []byte

PrivateRWSet contains the bytes of CollectionPvtReadWriteSet

func (PrivateRWSet) Digest added in v1.1.0

func (rws PrivateRWSet) Digest() string

Digest returns a deterministic and collision-free representation of the PrivateRWSet

type PrivateRWSetWithConfig added in v1.2.0

type PrivateRWSetWithConfig struct {
	RWSet            []PrivateRWSet
	CollectionConfig *peer.CollectionConfig
}

PrivateRWSetWithConfig encapsulates private read-write set among with relevant to collections config information

type PubSub

type PubSub struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

PubSub defines a struct that one can use to: - publish items to a topic to multiple subscribers - and subscribe to items from a topic The subscriptions have a TTL and are cleaned when it passes.

func NewPubSub

func NewPubSub() *PubSub

NewPubSub creates a new PubSub with an empty set of subscriptions

func (*PubSub) Publish

func (ps *PubSub) Publish(topic string, item interface{}) error

Publish publishes an item to all subscribers on the topic

func (*PubSub) Subscribe

func (ps *PubSub) Subscribe(topic string, ttl time.Duration) Subscription

Subscribe returns a subscription to a topic that expires when given TTL passes

type PvtDataCollections added in v1.1.0

type PvtDataCollections []*ledger.TxPvtData

PvtDataCollections data type to encapsulate collections of private data

func (*PvtDataCollections) Marshal added in v1.1.0

func (pvt *PvtDataCollections) Marshal() ([][]byte, error)

Marshal encodes private collection into bytes array

func (*PvtDataCollections) Unmarshal added in v1.1.0

func (pvt *PvtDataCollections) Unmarshal(data [][]byte) error

Unmarshal read and unmarshal collection of private data from given bytes array

type Set

type Set struct {
	// contains filtered or unexported fields
}

Set is a generic and thread-safe set container

func NewSet

func NewSet() *Set

NewSet returns a new set

func (*Set) Add

func (s *Set) Add(item interface{})

Add adds given item to the set

func (*Set) Clear

func (s *Set) Clear()

Clear removes all elements from set

func (*Set) Exists

func (s *Set) Exists(item interface{}) bool

Exists returns true whether given item is in the set

func (*Set) Remove

func (s *Set) Remove(item interface{})

Remove removes a given item from the set

func (*Set) Size

func (s *Set) Size() int

Size returns the size of the set

func (*Set) ToArray

func (s *Set) ToArray() []interface{}

ToArray returns a slice with items at the point in time the method was invoked

type Subscription

type Subscription interface {
	// Listen blocks until a publish was made
	// to the subscription, or an error if the
	// subscription's TTL passed
	Listen() (interface{}, error)
}

Subscription defines a subscription to a topic that can be used to receive publishes on

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL