Documentation
¶
Overview ¶
Package protocol owns the cross-node chat contract: strict JSON over the Raminga HTTP-over-libp2p transport. The authenticated stream Peer ID is the only sender identity; payload sender fields are accepted but ignored.
Index ¶
Constants ¶
const ( // HTTPProtocol is the libp2p protocol carrying net/http streams. HTTPProtocol = "/raminga/http/1.0.0" // ChatPath is the chat route on HTTPProtocol. ChatPath = "/chat" // DefaultMaxBodyBytes bounds one JSON request body. It is deliberately // smaller than the generic p2phttp 1 MiB default. DefaultMaxBodyBytes = 64 << 10 // DefaultMaxChatTextBytes bounds UTF-8 chat text. DefaultMaxChatTextBytes = 4096 // DefaultDedupeTTL is how long an accepted message ID is remembered. DefaultDedupeTTL = 10 * time.Minute // DefaultDedupeSize bounds the dedupe cache. DefaultDedupeSize = 4096 // DefaultSendTimeout bounds one HTTP request/response. DefaultSendTimeout = 20 * time.Second // DefaultRatePerSecond is the per-peer inbound chat rate. DefaultRatePerSecond = 5 // DefaultRateBurst is the per-peer inbound chat burst. DefaultRateBurst = 10 // DefaultRateTrackedPeers bounds the per-peer limiter cache. DefaultRateTrackedPeers = 1024 // MaxMessageIDBytes bounds the client-supplied message ID. MaxMessageIDBytes = 128 // MaxResponseBytes bounds an ACK response. MaxResponseBytes = 16 << 10 )
Variables ¶
var ErrTooLarge = errors.New("protocol: request body exceeds configured maximum size")
ErrTooLarge reports a request body larger than the configured limit.
Functions ¶
func NewMessageID ¶
func NewMessageID() string
NewMessageID returns a random 128-bit hex identifier.
func ValidateMessage ¶
Types ¶
type Ack ¶
type Ack struct {
MessageID string `json:"message_id"`
AckID string `json:"ack_id"`
Accepted bool `json:"accepted"`
Error string `json:"error,omitempty"`
AckedAtUnixMs int64 `json:"acked_at_unix_ms"`
}
Ack is the JSON response for a durably stored (or deduplicated) message.
type Handler ¶
Handler processes an inbound message. remote is authenticated by the transport. status is 200 for accepted, or an HTTP error status.
type Message ¶
type Message struct {
MessageID string `json:"message_id"`
SenderPeerID string `json:"sender_peer_id,omitempty"`
SenderNodeID string `json:"sender_node_id,omitempty"`
Text string `json:"text"`
SentAtUnixMs int64 `json:"sent_at_unix_ms"`
}
Message is the JSON request body. SenderPeerID/SenderNodeID are accepted for old-payload compatibility but are never used as identity.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func (*Service) HandleHTTP ¶
type StatusError ¶
StatusError reports a non-200 HTTP chat response. It is never delivered.
func (*StatusError) Error ¶
func (e *StatusError) Error() string
func (*StatusError) Permanent ¶
func (e *StatusError) Permanent() bool
Permanent reports whether retrying this status cannot help.