Documentation ¶
Overview ¶
Diameter Base Protocol for the Go programming language. See RFC 6733.
Index ¶
- Constants
- Variables
- func ErrorReports() chan ErrorReport
- func Handle(cmd string, handler Handler)
- func HandleFunc(cmd string, handler func(Conn, *Message))
- func ListenAndServe(addr string, handler Handler, dict *dict.Parser) error
- func ListenAndServeTLS(addr string, certFile string, keyFile string, handler Handler, ...) error
- func Serve(l net.Listener, handler Handler) error
- type AVP
- type CloseNotifier
- type Conn
- type ErrorReport
- type Grouped
- type Handler
- type HandlerFunc
- type Header
- type Message
- func (m *Message) AddAVP(a *AVP)
- func (m *Message) Answer(resultCode uint32) *Message
- func (m *Message) FindAVP(code interface{}) (*AVP, error)
- func (m *Message) Len() int
- func (m *Message) NewAVP(code interface{}, flags uint8, vendor uint32, data datatypes.DataType) (*AVP, error)
- func (m *Message) Serialize() []byte
- func (m *Message) SerializeTo(b []byte)
- func (m *Message) String() string
- func (m *Message) WriteTo(writer io.Writer) (int64, error)
- type ServeMux
- type Server
Constants ¶
const GroupedType = 50 // Must not conflict with other datatypes.DataTypeId.
const HeaderLength = 20 // Diameter header length.
Variables ¶
var DefaultServeMux = NewServeMux()
DefaultServeMux is the default ServeMux used by Serve.
Functions ¶
func ErrorReports ¶
func ErrorReports() chan ErrorReport
ErrorReport returns the ErrorReport channel of the DefaultServeMux.
func HandleFunc ¶
HandleFunc registers the handler function for the given command in the DefaultServeMux.
func ListenAndServe ¶
ListenAndServe listens on the TCP network address addr and then calls Serve with handler to handle requests on incoming connections.
If handler is nil, diam.DefaultServeMux is used.
If dict is nil, dict.Default is used.
func ListenAndServeTLS ¶
func ListenAndServeTLS(addr string, certFile string, keyFile string, handler Handler, dict *dict.Parser) error
ListenAndServeTLS acts identically to ListenAndServe, except that it expects SSL connections. Additionally, files containing a certificate and matching private key for the server must be provided. If the certificate is signed by a certificate authority, the certFile should be the concatenation of the server's certificate followed by the CA's certificate.
One can use generate_cert.go in crypto/tls to generate cert.pem and key.pem.
Types ¶
type AVP ¶
type AVP struct { Code uint32 // Code of this AVP Flags uint8 // Flags of this AVP Length int // Length of this AVP's payload VendorId uint32 // VendorId of this AVP Data datatypes.DataType // Data of this AVP (payload) }
Diameter AVP.
func (*AVP) DecodeFromBytes ¶
DecodeFromBytes decodes the bytes of a Diameter AVP. It requires a parent Header to be able to decode the AVP data by consulting the ApplicationId and Dictionary of the Header.
func (*AVP) Serialize ¶
Serialize returns the byte sequence that represents this AVP. It requires at least the Code, Flags and Data fields set.
func (*AVP) SerializeTo ¶
type CloseNotifier ¶
type CloseNotifier interface { // CloseNotify returns a channel that receives a single value // when the client connection has gone away. CloseNotify() <-chan bool }
The CloseNotifier interface is implemented by Conns which allow detecting when the underlying connection has gone away.
This mechanism can be used to detect if the client has disconnected.
type Conn ¶
type Conn interface { Write(b []byte) (int, error) // Writes a msg to the connection Close() // Close the connection LocalAddr() net.Addr // Local IP RemoteAddr() net.Addr // Remote IP TLS() *tls.ConnectionState // or nil when not using TLS }
Conn interface is used by a handler to send diameter messages.
type ErrorReport ¶
ErrorReport is sent out of the server in case it fails to read messages because of a bad dictionary or network errors.
type Grouped ¶
type Grouped struct {
AVP []*AVP
}
Grouped AVP. This is different from the dummy datatypes.Grouped.
func DecodeGrouped ¶
func (*Grouped) Type ¶
func (g *Grouped) Type() datatypes.DataTypeId
type Handler ¶
type Handler interface { ServeDiam(Conn, *Message) ErrorReports() chan ErrorReport }
Objects implementing the Handler interface can be registered to serve particular messages like CER, DWR.
ServeDiam should write messages to the Conn and then return. Returning signals that the request is finished and that the server can move on to the next request on the connection.
type HandlerFunc ¶
The HandlerFunc type is an adapter to allow the use of ordinary functions as diameter handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler object that calls f.
func (HandlerFunc) ErrorReports ¶
func (f HandlerFunc) ErrorReports() chan ErrorReport
ErrorReports calls f.ErrorReports()
func (HandlerFunc) ServeDiam ¶
func (f HandlerFunc) ServeDiam(c Conn, m *Message)
ServeDiam calls f(c, m).
type Header ¶
type Header struct { Version uint8 MessageLength uint32 CommandFlags uint8 CommandCode uint32 ApplicationId uint32 HopByHopId uint32 EndToEndId uint32 }
Diameter Header.
func (*Header) DecodeFromBytes ¶
DecodeFromBytes decodes the bytes of a Diameter Header. It requires a dictionary Parser to be able to decode the Header by consulting the
func (*Header) SerializeTo ¶
type Message ¶
type Message struct { Header *Header AVP []*AVP Dictionary *dict.Parser // Used to encode and decode AVPs. }
Diameter message.
func NewMessage ¶
func NewMessage(cmd uint32, flags uint8, appid, hopbyhop, endtoend uint32, dictionary *dict.Parser) *Message
NewMessage creates and initializes Message.
func NewRequest ¶
NewRequest is an alias to NewMessage.
func ReadMessage ¶
ReadMessage returns a Message. It uses the dictionary to parse the binary stream from the reader.
func (*Message) Answer ¶
Answer creates an answer for the current Message with an embedded Result-Code AVP.
func (*Message) FindAVP ¶
FindAVP searches the Message for a specific AVP. @code can be either the AVP code (int, uint32) or name (string).
Example:
avp, err := m.FindAVP(264) avp, err := m.FindAVP("Origin-Host")
func (*Message) NewAVP ¶
func (m *Message) NewAVP(code interface{}, flags uint8, vendor uint32, data datatypes.DataType) (*AVP, error)
NewAVP creates and initializes a new AVP and adds it to the Message. @code can be int, uint32 or string (e.g. 268 or Result-Code)
func (*Message) SerializeTo ¶
type ServeMux ¶
type ServeMux struct {
// contains filtered or unexported fields
}
ServeMux is a diameter message multiplexer. It matches the command from the incoming message against a list of registered commands and calls the handler.
func (*ServeMux) ErrorReports ¶
func (mux *ServeMux) ErrorReports() chan ErrorReport
ErrorReports returns the ErrorReport channel of the handler.
func (*ServeMux) Handle ¶
Handle registers the handler for the given code. If a handler already exists for code, Handle panics.
func (*ServeMux) HandleFunc ¶
HandleFunc registers the handler function for the given command. Special cmd "ALL" may be used as a catch all.
type Server ¶
type Server struct { Addr string // TCP address to listen on, ":3868" if empty Handler Handler // handler to invoke, diam.DefaultServeMux if nil Dict *dict.Parser // diameter dictionaries for this server ReadTimeout time.Duration // maximum duration before timing out read of the request WriteTimeout time.Duration // maximum duration before timing out write of the response TLSConfig *tls.Config // optional TLS config, used by ListenAndServeTLS }
A Server defines parameters for running a diameter server.
func (*Server) ListenAndServe ¶
ListenAndServe listens on the TCP network address srv.Addr and then calls Serve to handle requests on incoming connections. If srv.Addr is blank, ":3868" is used.
func (*Server) ListenAndServeTLS ¶
ListenAndServeTLS listens on the TCP network address srv.Addr and then calls Serve to handle requests on incoming TLS connections.
Filenames containing a certificate and matching private key for the server must be provided. If the certificate is signed by a certificate authority, the certFile should be the concatenation of the server's certificate followed by the CA's certificate.
If srv.Addr is blank, ":3868" is used.