Documentation ¶
Overview ¶
Package internal provides internal APIs used by the bosh package.
Index ¶
Examples ¶
Constants ¶
const ( // MaxInitialRID is the largest possible starting request ID. MaxInitialRID = uint64(float64(9007199254740991) * 0.75) )
Variables ¶
This section is empty.
Functions ¶
func NewRID ¶
func NewRID() uint64
NewRID returns a new cryptographically secure random ID that is low enough to prevent any reasonable session from rolling over the maximum safe number for a double-precision floating-point value (2⁵³-1). If a proper source of entropy can't be initialized (or generating a random number fails for any other reason), the function panics. RID will not be 0. The range will be (0, MaxInitialRID]
Types ¶
type Body ¶
type Body struct { XMLName xml.Name `xml:"http://jabber.org/protocol/httpbind body"` From string `xml:"from,attr,omitempty"` InnerXML []byte `xml:",innerxml"` Type string `xml:"type,attr,omitempty"` }
body represents a BOSH <body/> element with the correct namespace.
type PayloadQueue ¶
type PayloadQueue []*Payload
Example ¶
This example creates a PayloadQueue with some payloads, adds and manipulates a payload, and then removes the payloads in reverse priority order.
package main import ( "container/heap" "fmt" "mellium.im/bosh/internal" ) func main() { // Some payloads and their priorities. payloads := map[string]uint64{ "banana": 3, "apple": 2, "pear": 4, } // Create a reverse priority queue, put the payloads in it, and establish the // reverse priority queue (heap) invariants. pq := make(internal.PayloadQueue, len(payloads)) i := 0 for value, priority := range payloads { pq[i] = &internal.Payload{ Value: value, RID: priority, } i++ } heap.Init(&pq) heap.Push(&pq, &internal.Payload{ Value: "orange", RID: 5, }) // Take the payloads out; they arrive in increasing priority order. for pq.Len() > 0 { payload := heap.Pop(&pq).(*internal.Payload) fmt.Printf("%.2d:%s ", payload.RID, payload.Value) } }
Output: 02:apple 03:banana 04:pear 05:orange
func (PayloadQueue) Len ¶
func (pq PayloadQueue) Len() int
func (PayloadQueue) Less ¶
func (pq PayloadQueue) Less(i, j int) bool
func (*PayloadQueue) Peek ¶
func (pq *PayloadQueue) Peek() *Payload
Peek returns a copy of the last element on the heap (without removing it).
func (*PayloadQueue) Pop ¶
func (pq *PayloadQueue) Pop() interface{}
func (*PayloadQueue) Push ¶
func (pq *PayloadQueue) Push(x interface{})
func (PayloadQueue) Swap ¶
func (pq PayloadQueue) Swap(i, j int)
type RequestInfo ¶
type RequestInfo struct {
RID uint64 `xml:"rid,attr"`
}
RequestInfo contains metadata about the current request.
type RequestPayload ¶
type RequestPayload struct { Body SessionInfo RequestInfo }
A RequestPayload is any request that is part of an existing session.
type SessionBody ¶
type SessionBody struct { Body Ack uint64 `xml:"ack,attr,omitempty"` Hold int `xml:"hold,attr,omitempty"` To string `xml:"to,attr,omitempty"` Ver string `xml:"ver,attr,omitempty"` Wait int `xml:"wait,attr"` }
SessionBody contains shared attriutes that are used by session start requests and the initial response.
type SessionInfo ¶
type SessionInfo struct {
SID string `xml:"sid,attr"`
}
SessionInfo contains metadata about the current session.
type StartSessionRequest ¶
type StartSessionRequest struct { Body RequestInfo SessionBody Content string `xml:"content,attr,omitempty"` Lang string `xml:"http://www.w3.org/XML/1998/namespace lang,attr"` Route string `xml:"route,attr"` }
A StartSessionRequest is used to unmarshal a new session request without a payload.
type StartSessionResponse ¶
type StartSessionResponse struct { Body SessionInfo SessionBody // Body MUST possess the following attributes: Requests int `xml:"requests,attr"` // Body SHOULD possess the following attributes: Inactivity int `xml:"inactivity,attr,omitempty"` Polling int `xml:"polling,attr,omitempty"` // Body MAY possess the following attributes: Accept string `xml:"accept,attr,omitempty"` MaxPause int `xml:"maxpause,attr,omitempty"` CharSets string `xml:"charsets,attr,omitempty"` }
StartSessionResponse is used to marshal a response to the initial session start request.