Documentation
¶
Index ¶
- Constants
- Variables
- type HandlerFunc
- type Herald
- func (h *Herald) Broadcast(ctx context.Context, payload []byte)
- func (h *Herald) Close(ctx context.Context) error
- func (h *Herald) ID() string
- func (h *Herald) OnPeerJoin(hook PeerHook)
- func (h *Herald) OnPeerLeave(hook PeerHook)
- func (h *Herald) Peers() []string
- func (h *Herald) SendToPeer(ctx context.Context, peerID string, payload []byte) error
- func (h *Herald) Start(ctx context.Context) error
- func (h *Herald) Subscribe(ctx context.Context, event MessageType, handler HandlerFunc)
- type Hook
- type Log
- type Message
- type MessageContext
- type MessageType
- type Middleware
- type Option
- type PeerHook
- type Subscription
Constants ¶
Variables ¶
View Source
var ( ErrUnknownPeer = errors.New("unknown peer") ErrInvalidSignature = errors.New("invalid signature") ErrSelfMessage = errors.New("self message") ErrInvalidMessage = errors.New("invalid message") ErrMessageTimeout = errors.New("message timeout") ErrAckTimeout = errors.New("ack timeout") ErrInvalidEventType = errors.New("invalid event type") )
Functions ¶
This section is empty.
Types ¶
type HandlerFunc ¶ added in v1.2.0
type HandlerFunc func(*MessageContext, *Message)
type Herald ¶
type Herald struct {
// contains filtered or unexported fields
}
Herald represents the main P2P engine that handles messaging, heartbeat, peer registry, and hooks for join/leave events.
func New ¶
New creates a new Herald instance, generating a key pair and setting up default handlers.
func (*Herald) OnPeerJoin ¶
OnPeerJoin registers a hook for when a peer joins.
func (*Herald) OnPeerLeave ¶
OnPeerLeave registers a hook for when a peer leaves.
func (*Herald) SendToPeer ¶
SendToPeer sends a message to a specific peer.
func (*Herald) Start ¶
Start runs the Herald engine, subscribes to messages, performs handshake, starts heartbeat, and manages message sending/receiving.
func (*Herald) Subscribe ¶
func (h *Herald) Subscribe(ctx context.Context, event MessageType, handler HandlerFunc)
Subscribe subscribes to a specific message type with a buffered channel.
type Log ¶ added in v1.1.0
type Log interface {
Debug(ctx context.Context, msg string, args ...any)
Info(ctx context.Context, msg string, args ...any)
Error(ctx context.Context, msg string, args ...any)
Warn(ctx context.Context, msg string, args ...any)
}
func NewDiscardLogs ¶ added in v1.1.0
func NewDiscardLogs() Log
func NewLogger ¶ added in v1.1.0
func NewLogger(option *slog.HandlerOptions) Log
type Message ¶
type Message struct {
ID string
From string
To string
Type MessageType
Payload []byte
}
type MessageContext ¶
func NewMessageContext ¶
func NewMessageContext(ctx context.Context) *MessageContext
func (*MessageContext) Abort ¶
func (ctx *MessageContext) Abort()
func (*MessageContext) IsAborted ¶
func (ctx *MessageContext) IsAborted() bool
type MessageType ¶
type MessageType string
const ( MessageTypeAnnounce MessageType = "announce" MessageTypeMessage MessageType = "message" MessageTypeACK MessageType = "ack" MessageTypeOffline MessageType = "offline" )
func (MessageType) GetType ¶
func (mt MessageType) GetType() message.EventType
type Middleware ¶
type Middleware func(ctx *MessageContext, herald *Herald, env *message.Envelope) error
func CheckMessageAccess ¶
func CheckMessageAccess() Middleware
func UpdateLastOnline ¶
func UpdateLastOnline() Middleware
func VerifySignature ¶
func VerifySignature() Middleware
type Subscription ¶
type Subscription struct {
C <-chan Message
// contains filtered or unexported fields
}
Source Files
¶
Click to show internal directories.
Click to hide internal directories.