Documentation ¶
Index ¶
- Constants
- Variables
- func BytesArrToString(bbarray [][]byte) string
- func CalculateFieldDescSize(varSize int) int
- func CheckAdddress(urlStr string) (string, error)
- func ComparePeerID(pid1, pid2 types.PeerID) int
- func DebugLogReceiveMsg(logger *log.Logger, protocol p2pcommon.SubProtocol, msgID string, ...)
- func DebugLogReceiveResponseMsg(logger *log.Logger, protocol p2pcommon.SubProtocol, msgID string, reqID string, ...)
- func ExternalIP() (net.IP, error)
- func ExtractBlockFromRequest(rawResponse interface{}, err error) (*types.Block, error)
- func FromMultiAddr(targetAddr multiaddr.Multiaddr) (p2pcommon.PeerMeta, error)
- func GenerateKeyFile(dir, prefix string) (crypto.PrivKey, crypto.PubKey, error)
- func GetSingleIPAddress(addrStr string) (net.IP, error)
- func InvokeWithTimer(m Callable, timer *time.Timer) (interface{}, error)
- func IsExternalAddr(addrStr string) bool
- func LoadKeyFile(keyFile string) (crypto.PrivKey, crypto.PubKey, error)
- func MarshalMessageBody(message p2pcommon.MessageBody) ([]byte, error)
- func ParseMultiAddrString(str string) (p2pcommon.PeerMeta, error)
- func ParseMultiaddrWithResolve(str string) (multiaddr.Multiaddr, error)
- func PeerMetaToMultiAddr(m p2pcommon.PeerMeta) (multiaddr.Multiaddr, error)
- func PrintHashList(blocks []*types.Block) string
- func ProtocolIDsToString(sli []core.ProtocolID) string
- func RandomUUID() string
- func ReadToLen(rd io.Reader, bf []byte) (int, error)
- func ResolveHostDomain(domainName string) ([]net.IP, error)
- func ShortForm(pid types.PeerID) string
- func ShortMetaForm(m p2pcommon.PeerMeta) string
- func ToMultiAddr(ipAddr net.IP, port uint32) (multiaddr.Multiaddr, error)
- func UnmarshalAndReturn(data []byte, msgData p2pcommon.MessageBody) (p2pcommon.MessageBody, error)
- func UnmarshalMessageBody(data []byte, msgData p2pcommon.MessageBody) error
- type AddressType
- type Callable
- type ChannelPipe
- type LogB58EncMarshaler
- type LogPeerMetasMarshaler
- type LogStringersMarshaler
- type MultiListener
- type PipeEventListener
- type PressableQueue
- func (q *PressableQueue) Empty() bool
- func (q *PressableQueue) Full() bool
- func (q *PressableQueue) Offer(e interface{}) bool
- func (q *PressableQueue) Peek() interface{}
- func (q *PressableQueue) Poll() interface{}
- func (q *PressableQueue) Press(e interface{}) interface{}
- func (q *PressableQueue) Size() int
- type StatListener
Constants ¶
const ( DN = `^([a-zA-Z0-9_]{1}[a-zA-Z0-9_-]{0,62}){1}(\.[a-zA-Z0-9_]{1}[a-zA-Z0-9_-]{0,62})*[\._]?$` IPv4 = `^((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])` IPv6 = `` /* 659-byte string literal not displayed */ )
const ( LogPeerID = "peer_id" LogFullID = "full_id" // LogFullID is Full qualified peer id LogPeerName = "peer_nm" LogProtoID = "protocol_id" LogMsgID = "msg_id" LogOrgReqID = "req_id" // LogOrgReqID is msgid of request from remote peer LogBlkHash = "blk_hash" LogBlkCount = "blk_cnt" LogTxHash = "tx_hash" LogTxCount = "tx_cnt" LogRespStatus = "resp_st" )
frequently used constants for indicating p2p log category
Variables ¶
var ( DNPattern = regexp.MustCompile(DN) InvalidAddresss = fmt.Errorf("invalid address") )
var InvalidArgument = fmt.Errorf("invalid argument")
var (
UseFullID bool
)
Functions ¶
func BytesArrToString ¶ added in v0.9.0
bytesArrToString converts array of byte array to json array of b58 encoded string.
func CalculateFieldDescSize ¶ added in v0.9.0
func CheckAdddress ¶ added in v0.9.0
func ComparePeerID ¶ added in v0.9.0
ComparePeerID do byte-wise compare of two peerIDs,
func DebugLogReceiveMsg ¶ added in v0.9.0
func DebugLogReceiveMsg(logger *log.Logger, protocol p2pcommon.SubProtocol, msgID string, peer p2pcommon.RemotePeer, additional interface{})
func DebugLogReceiveResponseMsg ¶ added in v0.9.0
func DebugLogReceiveResponseMsg(logger *log.Logger, protocol p2pcommon.SubProtocol, msgID string, reqID string, peer p2pcommon.RemotePeer, additional interface{})
func ExternalIP ¶ added in v0.9.0
func ExtractBlockFromRequest ¶ added in v0.9.0
func FromMultiAddr ¶ added in v0.9.0
func GenerateKeyFile ¶ added in v0.9.0
func GetSingleIPAddress ¶ added in v0.9.0
IGetSingleIPAddress find and get ip address of given address string. It return first ip if DNS or /etc/hosts has multiple IPs
func InvokeWithTimer ¶
InvokeWithTimer call DoCall method of m and return if m is finished or return error if timer fires.
func IsExternalAddr ¶ added in v0.9.0
func LoadKeyFile ¶ added in v0.9.0
func MarshalMessageBody ¶ added in v0.9.0
func MarshalMessageBody(message p2pcommon.MessageBody) ([]byte, error)
func ParseMultiAddrString ¶ added in v0.9.0
func ParseMultiaddrWithResolve ¶ added in v0.9.0
ParseMultiaddrWithResolve parse string to multiaddr, additionally accept domain name with protocol /dns NOTE: this function is temporarilly use until go-multiaddr start to support dns.
func PeerMetaToMultiAddr ¶ added in v0.9.0
PeerMetaToMultiAddr make libp2p compatible Multiaddr object from peermeta
func PrintHashList ¶ added in v0.9.0
func ProtocolIDsToString ¶ added in v0.9.0
func ProtocolIDsToString(sli []core.ProtocolID) string
func RandomUUID ¶ added in v0.9.0
func RandomUUID() string
RandomUUID generate random UUID and return in form of string
func ResolveHostDomain ¶ added in v0.9.0
func ShortMetaForm ¶ added in v0.9.0
func ToMultiAddr ¶ added in v0.9.0
ToMultiAddr make libp2p compatible Multiaddr object
func UnmarshalAndReturn ¶ added in v0.9.0
func UnmarshalAndReturn(data []byte, msgData p2pcommon.MessageBody) (p2pcommon.MessageBody, error)
func UnmarshalMessageBody ¶ added in v0.9.0
func UnmarshalMessageBody(data []byte, msgData p2pcommon.MessageBody) error
Types ¶
type AddressType ¶ added in v0.9.0
type AddressType int
const ( AddressTypeError AddressType = iota AddressTypeIP AddressTypeFQDN )
AddressType
func CheckAdddressType ¶ added in v0.9.0
func CheckAdddressType(urlStr string) AddressType
type Callable ¶
type Callable interface { // DoCall run function. it should put result anything if call is over. It also stop function if Cancel was called as soon as possible DoCall(done chan<- interface{}) // Cancel should return instanly Cancel() }
Callable
type ChannelPipe ¶
type ChannelPipe interface { // Put item to pipe. it should be used after Open() method is called. // It always returns true and gurranty that item is queued. Put(item interface{}) bool Out() <-chan interface{} // Done should be called after get item from out channel Done() Open() Close() }
ChannelPipe serve non blocking limited size channel. It preserve input ordering, and not block caller unless it is Closed() Tt must be called Open before using it, and Close for dispose resource.
func NewDefaultChannelPipe ¶
func NewDefaultChannelPipe(bufsize int, listener PipeEventListener) ChannelPipe
NewDefaultChannelPipe create pipe to output channel out
type LogB58EncMarshaler ¶ added in v0.9.0
type LogB58EncMarshaler struct {
// contains filtered or unexported fields
}
LogB58EncMarshaler is zerolog array marshaler which print bytes array to baase58 encoded string.
func NewLogB58EncMarshaler ¶ added in v0.9.0
func NewLogB58EncMarshaler(arr [][]byte, limit int) *LogB58EncMarshaler
func (*LogB58EncMarshaler) MarshalZerologArray ¶ added in v0.9.0
func (m *LogB58EncMarshaler) MarshalZerologArray(a *zerolog.Array)
type LogPeerMetasMarshaler ¶ added in v0.9.0
type LogPeerMetasMarshaler struct {
// contains filtered or unexported fields
}
func NewLogPeerMetasMarshaler ¶ added in v0.9.0
func NewLogPeerMetasMarshaler(metas []p2pcommon.PeerMeta, limit int) *LogPeerMetasMarshaler
func (*LogPeerMetasMarshaler) MarshalZerologArray ¶ added in v0.9.0
func (m *LogPeerMetasMarshaler) MarshalZerologArray(a *zerolog.Array)
type LogStringersMarshaler ¶ added in v0.9.0
type LogStringersMarshaler struct {
// contains filtered or unexported fields
}
func NewLogStringersMarshaler ¶ added in v0.9.0
func NewLogStringersMarshaler(arr []fmt.Stringer, limit int) *LogStringersMarshaler
func (*LogStringersMarshaler) MarshalZerologArray ¶ added in v0.9.0
func (m *LogStringersMarshaler) MarshalZerologArray(a *zerolog.Array)
type MultiListener ¶
type MultiListener struct {
// contains filtered or unexported fields
}
MultiListener can contain multiple unit listeners and toss events
func NewMultiListener ¶
func NewMultiListener(ls ...PipeEventListener) *MultiListener
func (*MultiListener) AppendListener ¶
func (ml *MultiListener) AppendListener(l PipeEventListener)
func (*MultiListener) OnDrop ¶
func (ml *MultiListener) OnDrop(element interface{})
func (*MultiListener) OnIn ¶
func (ml *MultiListener) OnIn(element interface{})
func (*MultiListener) OnOut ¶
func (ml *MultiListener) OnOut(element interface{})
type PipeEventListener ¶
type PipeEventListener interface { // OnIn is called when item is queued OnIn(element interface{}) // OnDrop is called when queued item is dropped and not out to channel receiver OnDrop(element interface{}) // OnOut is called when queued item went to out channel (and will be sent to receiver) OnOut(element interface{}) }
PipeEventListener listen event of ChannelPipe
type PressableQueue ¶
type PressableQueue struct {
// contains filtered or unexported fields
}
PressableQueue non-threadsafe fixed size queue, implemented like circular queue
func NewPressableQueue ¶
func NewPressableQueue(capacity int) *PressableQueue
NewPressableQueue create a new queue
func (*PressableQueue) Empty ¶
func (q *PressableQueue) Empty() bool
Empty returns true if queue has no element, or false if not
func (*PressableQueue) Full ¶
func (q *PressableQueue) Full() bool
Full returns true if queue has maximum number of elements, or false if not
func (*PressableQueue) Offer ¶
func (q *PressableQueue) Offer(e interface{}) bool
Offer is adding element to queue, it returns true if add success, or false if queue if add fail.
func (*PressableQueue) Peek ¶
func (q *PressableQueue) Peek() interface{}
Peek return first element but not delete in queue. It returns nil if queue is empty
func (*PressableQueue) Poll ¶
func (q *PressableQueue) Poll() interface{}
Poll return first element and remove it in queue. It returns nil if queue is empty
func (*PressableQueue) Press ¶
func (q *PressableQueue) Press(e interface{}) interface{}
Press is adding element to queue and return nil fi queue is not full, or drop first element and return dropped element if queue is full.
func (*PressableQueue) Size ¶
func (q *PressableQueue) Size() int
Size return the number of element queue has
type StatListener ¶
type StatListener struct {
// contains filtered or unexported fields
}
StatListener make summation
func NewStatLister ¶
func NewStatLister() *StatListener
func (*StatListener) OnDrop ¶
func (l *StatListener) OnDrop(element interface{})
func (*StatListener) OnIn ¶
func (l *StatListener) OnIn(element interface{})
func (*StatListener) OnOut ¶
func (l *StatListener) OnOut(element interface{})