Documentation ¶
Index ¶
- Constants
- Variables
- func Equal(a []byte, b []byte) bool
- func FromUint32(v uint32) []byte
- func NewQlcMessage(data []byte, currentVersion byte, messagetype string) []byte
- func Ping(ctx context.Context, h host.Host, p peer.ID) (<-chan time.Duration, error)
- func Uint32(data []byte) uint32
- type BaseMessage
- type DiscoveryOption
- type Dispatcher
- type Event
- func (e *Event) Notify(eventtype EventType, value interface{}) (err error)
- func (e *Event) NotifyAll() (errs []error)
- func (e *Event) NotifySubscriber(eventfunc EventFunc, value interface{})
- func (e *Event) Subscribe(eventtype EventType, eventfunc EventFunc) EventSubscriber
- func (e *Event) UnSubscribe(eventtype EventType, subscriber EventSubscriber) (err error)
- type EventFunc
- type EventQueue
- type EventSubscriber
- type EventType
- type Message
- type MessageService
- type MessageType
- type PeersSlice
- type PingService
- type QlcMessage
- func (message *QlcMessage) DataCheckSum() uint32
- func (message *QlcMessage) DataLength() uint32
- func (message *QlcMessage) HeaderCheckSum() uint32
- func (message *QlcMessage) HeaderData() []byte
- func (message *QlcMessage) MagicNumber() []byte
- func (message *QlcMessage) MessageData() []byte
- func (message *QlcMessage) MessageType() MessageType
- func (message *QlcMessage) ParseMessageData(data []byte) error
- func (message *QlcMessage) Reserved() []byte
- func (message *QlcMessage) VerifyData() error
- func (message *QlcMessage) VerifyHeader() error
- func (message *QlcMessage) Version() byte
- type QlcNode
- func (node *QlcNode) BroadcastMessage(messageName string, data []byte)
- func (node *QlcNode) GetID() string
- func (node *QlcNode) HandlePeerFound(p pstore.PeerInfo)
- func (node *QlcNode) SendMessageToPeer(messageName string, data []byte, peerID string) error
- func (node *QlcNode) SetQlcService(ns *QlcService)
- func (node *QlcNode) StartServices() error
- func (node *QlcNode) Stop()
- func (node *QlcNode) StreamManager() *StreamManager
- type QlcService
- func (ns *QlcService) Broadcast(name string, msg []byte)
- func (ns *QlcService) Deregister(subscribers ...*Subscriber)
- func (ns *QlcService) Init() error
- func (ns *QlcService) MessageEvent() *EventQueue
- func (ns *QlcService) Node() *QlcNode
- func (ns *QlcService) PutMessage(msg Message)
- func (ns *QlcService) Register(subscribers ...*Subscriber)
- func (ns *QlcService) SendMessageToPeer(messageName string, data []byte, peerID string) error
- func (ns *QlcService) Start() error
- func (ns *QlcService) Status() int32
- func (ns *QlcService) Stop() error
- type Service
- type ServiceSync
- type Stream
- type StreamManager
- func (sm *StreamManager) Add(s libnet.Stream)
- func (sm *StreamManager) AddStream(stream *Stream)
- func (sm *StreamManager) BroadcastMessage(messageName string, messageContent []byte)
- func (sm *StreamManager) CloseStream(peerID string)
- func (sm *StreamManager) CreateStreamWithPeer(pid peer.ID)
- func (sm *StreamManager) Find(pid peer.ID) *Stream
- func (sm *StreamManager) FindByPeerID(peerID string) *Stream
- func (sm *StreamManager) PeerCounts() int
- func (sm *StreamManager) RandomPeer() (string, error)
- func (sm *StreamManager) RemoveStream(s *Stream)
- func (sm *StreamManager) SetQlcNode(node *QlcNode)
- func (sm *StreamManager) Start()
- func (sm *StreamManager) Stop()
- type Subscriber
Constants ¶
const ( QlcProtocolID = "qlc/1.0.0" QlcProtocolFOUND = "/qlc/discovery/1.0.0" EachTimeFoundPeersLimit = 20 )
const ( QlcMessageHeaderLength = 22 QlcMessageMagicNumberEndIdx = 3 QlcMessageVersionEndIdx = 4 QlcMessageTypeEndIdx = 6 QlcMessageDataLengthEndIdx = 10 QlcMessageReservedEndIdx = 14 QlcMessageHeaderCheckSumEndIdx = 18 QlcMessageDataCheckSumEndIdx = 22 )
const ( PublishReq = "0" //PublishReq ConfirmReq = "1" //ConfirmReq ConfirmAck = "2" //ConfirmAck FrontierRequest = "3" //frontierreq FrontierRsp = "4" //frontierrsp BulkPullRequest = "5" //bulkpull BulkPullRsp = "6" //bulkpullrsp BulkPushBlock = "7" //bulkpushblock )
Message Type
const ( PingSize = 32 ID = "/qlc/ping/1.0.0" )
const (
FindPeerInterval = time.Second * 30
)
const
const (
SyncInterval = time.Minute * 2
)
Variables ¶
var ( ErrInvalidMessageHeaderLength = errors.New("invalid message header length") ErrInvalidMessageDataLength = errors.New("invalid message data length") ErrInvalidMagicNumber = errors.New("invalid magic number") ErrInvalidHeaderCheckSum = errors.New("invalid header checksum") ErrInvalidDataCheckSum = errors.New("invalid data checksum") )
Error types
var ( ErrShouldCloseConnectionAndExitLoop = errors.New("should close connection and exit loop") ErrStreamIsNotConnected = errors.New("stream is not connected") ErrNoStream = errors.New("no stream") )
Stream Errors
var (
ErrPeerIsNotConnected = errors.New("peer is not connected")
)
Error types
var (
MagicNumber = []byte{0x51, 0x4C, 0x43} //QLC
)
Functions ¶
func NewQlcMessage ¶
NewQlcMessage new qlc message
Types ¶
type BaseMessage ¶
type BaseMessage struct {
// contains filtered or unexported fields
}
BaseMessage base message
func (*BaseMessage) MessageFrom ¶
func (msg *BaseMessage) MessageFrom() string
MessageFrom get message who send
func (*BaseMessage) MessageType ¶
func (msg *BaseMessage) MessageType() MessageType
MessageType get message type
func (*BaseMessage) String ¶
func (msg *BaseMessage) String() string
String get the message to string
type DiscoveryOption ¶
type DiscoveryOption func(context.Context, host.Host) (localdiscovery.Service, error)
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher a message dispatcher service.
func (*Dispatcher) Deregister ¶
func (dp *Dispatcher) Deregister(subscribers ...*Subscriber)
Deregister deregister subscribers.
func (*Dispatcher) PutMessage ¶
func (dp *Dispatcher) PutMessage(msg Message)
PutMessage put new message to chan, then subscribers will be notified to process.
func (*Dispatcher) Register ¶
func (dp *Dispatcher) Register(subscribers ...*Subscriber)
Register register subscribers.
type Event ¶
type Event struct {
// contains filtered or unexported fields
}
func (*Event) NotifySubscriber ¶
func (*Event) Subscribe ¶
func (e *Event) Subscribe(eventtype EventType, eventfunc EventFunc) EventSubscriber
adds a new subscriber to Event.
func (*Event) UnSubscribe ¶
func (e *Event) UnSubscribe(eventtype EventType, subscriber EventSubscriber) (err error)
UnSubscribe removes the specified subscriber
type EventQueue ¶
type EventQueue struct {
Consensus *Event
}
func NeweventQueue ¶
func NeweventQueue() *EventQueue
func (*EventQueue) GetEvent ¶
func (eq *EventQueue) GetEvent(eventName string) *Event
type EventSubscriber ¶
type EventSubscriber chan interface{}
type Message ¶
type Message interface { MessageType() MessageType MessageFrom() string Data() []byte Hash() string }
Message interface for message.
func NewBaseMessage ¶
func NewBaseMessage(messageType MessageType, from string, data []byte) Message
NewBaseMessage new base message
type MessageService ¶
type MessageService struct {
// contains filtered or unexported fields
}
func NewMessageService ¶
func NewMessageService(netService *QlcService, ledger *ledger.Ledger) *MessageService
NewService return new Service.
func (*MessageService) Stop ¶
func (ms *MessageService) Stop()
type PingService ¶
type PingService struct { Host host.Host // contains filtered or unexported fields }
func NewPingService ¶
func NewPingService(h host.Host) *PingService
func (*PingService) PingHandler ¶
func (p *PingService) PingHandler(s inet.Stream)
type QlcMessage ¶
type QlcMessage struct {
// contains filtered or unexported fields
}
func ParseQlcMessage ¶
func ParseQlcMessage(data []byte) (*QlcMessage, error)
ParseqlcMessage parse qlc message
func (*QlcMessage) DataCheckSum ¶
func (message *QlcMessage) DataCheckSum() uint32
DataCheckSum return data checkSum
func (*QlcMessage) DataLength ¶
func (message *QlcMessage) DataLength() uint32
DataLength return dataLength
func (*QlcMessage) HeaderCheckSum ¶
func (message *QlcMessage) HeaderCheckSum() uint32
HeaderCheckSum return header checkSum
func (*QlcMessage) HeaderData ¶
func (message *QlcMessage) HeaderData() []byte
HeaderData return HeaderData
func (*QlcMessage) MagicNumber ¶
func (message *QlcMessage) MagicNumber() []byte
MagicNumber return magicNumber
func (*QlcMessage) MessageData ¶
func (message *QlcMessage) MessageData() []byte
func (*QlcMessage) MessageType ¶
func (message *QlcMessage) MessageType() MessageType
func (*QlcMessage) ParseMessageData ¶
func (message *QlcMessage) ParseMessageData(data []byte) error
ParseMessageData parse qlc message data
func (*QlcMessage) VerifyData ¶
func (message *QlcMessage) VerifyData() error
VerifyData verify qlc message data
func (*QlcMessage) VerifyHeader ¶
func (message *QlcMessage) VerifyHeader() error
VerifyHeader verify qlc message header
func (*QlcMessage) Version ¶
func (message *QlcMessage) Version() byte
type QlcNode ¶
type QlcNode struct { ID peer.ID // contains filtered or unexported fields }
func (*QlcNode) BroadcastMessage ¶
BroadcastMessage broadcast message.
func (*QlcNode) HandlePeerFound ¶
HandlePeerFound attempts to connect to peer from `PeerInfo`.
func (*QlcNode) SendMessageToPeer ¶
SendMessageToPeer send message to a peer.
func (*QlcNode) SetQlcService ¶
func (node *QlcNode) SetQlcService(ns *QlcService)
SetQlcService set netService
func (*QlcNode) StartServices ¶
func (*QlcNode) StreamManager ¶
func (node *QlcNode) StreamManager() *StreamManager
ID return node ID.
type QlcService ¶
type QlcService struct { common.ServiceLifecycle // contains filtered or unexported fields }
QlcService service for qlc p2p network
func NewQlcService ¶
func NewQlcService(cfg *config.Config) (*QlcService, error)
NewQlcService create netService
func (*QlcService) Broadcast ¶
func (ns *QlcService) Broadcast(name string, msg []byte)
Broadcast message.
func (*QlcService) Deregister ¶
func (ns *QlcService) Deregister(subscribers ...*Subscriber)
Deregister Deregister the subscribers.
func (*QlcService) Init ¶
func (ns *QlcService) Init() error
func (*QlcService) MessageEvent ¶
func (ns *QlcService) MessageEvent() *EventQueue
EventQueue return EventQueue
func (*QlcService) PutMessage ¶
func (ns *QlcService) PutMessage(msg Message)
PutMessage put message to dispatcher.
func (*QlcService) Register ¶
func (ns *QlcService) Register(subscribers ...*Subscriber)
Register register the subscribers.
func (*QlcService) SendMessageToPeer ¶
func (ns *QlcService) SendMessageToPeer(messageName string, data []byte, peerID string) error
SendMessageToPeer send message to a peer.
func (*QlcService) Status ¶
func (ns *QlcService) Status() int32
type Service ¶
type Service interface { common.Service Node() *QlcNode MessageEvent() *EventQueue Broadcast(string, []byte) SendMessageToPeer(messageName string, data []byte, peerID string) error }
Service net Service interface
type ServiceSync ¶
type ServiceSync struct {
// contains filtered or unexported fields
}
Service manage sync tasks
func NewSyncService ¶
func NewSyncService(netService *QlcService, ledger *ledger.Ledger) *ServiceSync
NewService return new Service.
func (*ServiceSync) Start ¶
func (ss *ServiceSync) Start()
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
Stream define the structure of a stream in p2p network
func NewStreamFromPID ¶
NewStreamFromPID return a new Stream based on the pid
func (*Stream) IsConnected ¶
IsConnected return if the stream is connected
func (*Stream) SendMessage ¶
SendMessage send msg to buffer
func (*Stream) WriteQlcMessage ¶
WriteQlcMessage write qlc msg in the stream
type StreamManager ¶
type StreamManager struct {
// contains filtered or unexported fields
}
StreamManager manages all streams
func NewStreamManager ¶
func NewStreamManager() *StreamManager
NewStreamManager return a new stream manager
func (*StreamManager) Add ¶
func (sm *StreamManager) Add(s libnet.Stream)
Add a new stream into the stream manager
func (*StreamManager) AddStream ¶
func (sm *StreamManager) AddStream(stream *Stream)
AddStream into the stream manager
func (*StreamManager) BroadcastMessage ¶
func (sm *StreamManager) BroadcastMessage(messageName string, messageContent []byte)
BroadcastMessage broadcast the message
func (*StreamManager) CloseStream ¶
func (sm *StreamManager) CloseStream(peerID string)
CloseStream with the given pid and reason
func (*StreamManager) CreateStreamWithPeer ¶
func (sm *StreamManager) CreateStreamWithPeer(pid peer.ID)
CreateStreamWithPeer create stream with a peer.
func (*StreamManager) Find ¶
func (sm *StreamManager) Find(pid peer.ID) *Stream
Find the stream with the given pid
func (*StreamManager) FindByPeerID ¶
func (sm *StreamManager) FindByPeerID(peerID string) *Stream
FindByPeerID find the stream with the given peerID
func (*StreamManager) PeerCounts ¶ added in v0.0.4
func (sm *StreamManager) PeerCounts() int
func (*StreamManager) RandomPeer ¶
func (sm *StreamManager) RandomPeer() (string, error)
func (*StreamManager) RemoveStream ¶
func (sm *StreamManager) RemoveStream(s *Stream)
RemoveStream from the stream manager
func (*StreamManager) SetQlcNode ¶
func (sm *StreamManager) SetQlcNode(node *QlcNode)
SetQlcService set netService
type Subscriber ¶
type Subscriber struct {
// contains filtered or unexported fields
}
Subscriber subscriber.
func NewSubscriber ¶
func NewSubscriber(id interface{}, msgChan chan Message, doFilter bool, msgType MessageType) *Subscriber
NewSubscriber return new Subscriber instance.
func (*Subscriber) MessageChan ¶
func (s *Subscriber) MessageChan() chan Message
MessageChan return msgChan.
func (*Subscriber) MessageType ¶
func (s *Subscriber) MessageType() MessageType
MessageType return msgTypes.