net

package
v0.0.0-...-5e9b8e2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2020 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CONNECT = uint8(iota + 1)
	CONNACK
	PUBLISH
	PUBACK
	PUBREC
	PUBREL
	PUBCOMP
	SUBSCRIBE
	SUBACK
	UNSUBSCRIBE
	UNSUBACK
	PINGREQ
	PINGRESP
	DISCONNECT
)
View Source
const (
	MaxMessageSize = 1 << 19
)

Variables

View Source
var ErrServerClosed = errors.New("Server closed")

ErrServerClosed occurs when a tcp server is closed.

Functions

func Encode

func Encode(adp ProtoAdapter, pkt Packet) (bytes.Buffer, error)

func StreamConn

func StreamConn(
	stream grpc.Stream,
) *plugins.Conn

Types

type Connack

type Connack struct {
	ReturnCode uint8
	ConnID     uint32
	Packet
}

Connack represents an connack packet. 0x00 connection accepted 0x01 refused: unacceptable proto version 0x02 refused: identifier rejected 0x03 refused server unavailiable 0x04 bad user or password 0x05 not authorized

func (*Connack) Info

func (c *Connack) Info() Info

Info returns Qos and MessageID of this packet.

func (*Connack) Type

func (c *Connack) Type() uint8

Type returns the Connack packet type.

type Connect

type Connect struct {
	ProtoName      []byte
	Version        uint8
	InsecureFlag   bool
	UsernameFlag   bool
	PasswordFlag   bool
	WillRetainFlag bool
	WillQOS        uint8
	WillFlag       bool
	CleanSessFlag  bool
	KeepAlive      uint16
	ClientID       []byte
	WillTopic      []byte
	WillMessage    []byte
	Username       []byte
	Password       []byte

	Packet
}

Connect represents a connect packet.

func (*Connect) Info

func (c *Connect) Info() Info

Info returns Qos and MessageID of this packet.

func (*Connect) Type

func (c *Connect) Type() uint8

Type returns the Connect packet type.

type Disconnect

type Disconnect struct {
	Packet
}

Disconnect is to signal you want to cease communications with the server

func (*Disconnect) Info

func (d *Disconnect) Info() Info

Info returns Qos and MessageID of this packet.

func (*Disconnect) Type

func (d *Disconnect) Type() uint8

Type returns the Disconnect packet type.

type FixedHeader

type FixedHeader struct {
	MessageType     byte
	Dup             bool
	Retain          bool
	Qos             uint8
	RemainingLength int
}

FixedHeader

type GrpcServer

type GrpcServer server

func NewGrpcServer

func NewGrpcServer(opts ...Options) *GrpcServer

func (*GrpcServer) Serve

func (s *GrpcServer) Serve(list net.Listener) error

func (*GrpcServer) Start

func (s *GrpcServer) Start(ctx context.Context, info *pbx.ConnInfo) (*pbx.ConnInfo, error)

Start implements unite.Connect

func (*GrpcServer) Stop

func (s *GrpcServer) Stop(context.Context, *pbx.Empty) (*pbx.Empty, error)

Disconnect implements unite.Disconnect

func (*GrpcServer) Stream

func (s *GrpcServer) Stream(stream pbx.Unite_StreamServer) error

Stream implements duplex unite.Stream

type Handler

type Handler func(c net.Conn, proto Proto)

Handler is a callback which get called when a tcp, websocket connection is established or a grpc stream is established

type HttpServer

type HttpServer server

func NewHttpServer

func NewHttpServer(opts ...Options) *HttpServer

func (*HttpServer) HandleFunc

func (s *HttpServer) HandleFunc(w http.ResponseWriter, r *http.Request)

func (*HttpServer) Serve

func (s *HttpServer) Serve(list net.Listener) error

type Info

type Info struct {
	Qos       uint8
	MessageID uint16
}

Info returns Qos and MessageID by the Info() function called on the Packet

type Options

type Options interface {
	// contains filtered or unexported methods
}

Options it contains configurable options for client

func WithDefaultOptions

func WithDefaultOptions() Options

WithDefaultOptions will create client connection with some default values.

KeepAlive: true
TlsConfig: nil

func WithTLSConfig

func WithTLSConfig(t *tls.Config) Options

WithTLSConfig will set an SSL/TLS configuration to be used when connecting to server.

type Packet

type Packet interface {
	Type() uint8
	Info() Info
}

Packet is the interface all our packets in the line protocol will be implementing

func ReadPacket

func ReadPacket(adp ProtoAdapter, r io.Reader) (Packet, error)

type Pingreq

type Pingreq struct {
	Packet
}

Pingreq is a keepalive

func (*Pingreq) Info

func (p *Pingreq) Info() Info

Info returns Qos and MessageID of this packet.

func (*Pingreq) Type

func (p *Pingreq) Type() uint8

Type returns the Pingreq packet type.

type Pingresp

type Pingresp struct {
	Packet
}

Pingresp is for saying "hey, the server is alive"

func (*Pingresp) Info

func (p *Pingresp) Info() Info

Info returns Qos and MessageID of this packet.

func (*Pingresp) Type

func (p *Pingresp) Type() uint8

Type returns the Pingresp packet type.

type Proto

type Proto int

Proto represents the type of connection

const (
	NONE Proto = iota
	GRPC
	GRPC_WEB
)

type ProtoAdapter

type ProtoAdapter interface {
	ReadPacket(r io.Reader) (Packet, error)
	Encode(pkt Packet) (bytes.Buffer, error)
}

type Puback

type Puback struct {
	MessageID uint16

	Packet
}

Puback is sent for QOS level one to verify the receipt of a publish Qoth the spec: "A PUBACK Packet is sent by a server in response to a PUBLISH Packet from a publishing client, and by a subscriber in response to a PUBLISH Packet from the server."

func (*Puback) Info

func (p *Puback) Info() Info

Info returns Qos and MessageID of this packet.

func (*Puback) Type

func (p *Puback) Type() uint8

Type returns the Puback Packet type.

type Pubcomp

type Pubcomp struct {
	MessageID uint16

	Packet
}

Pubcomp is for saying is in response to a pubrel sent by the publisher the final member of the QOS2 flow. both sides have said "hey, we did it!"

func (*Pubcomp) Info

func (p *Pubcomp) Info() Info

Info returns Qos and MessageID of this packet.

func (*Pubcomp) Type

func (p *Pubcomp) Type() uint8

Type returns the Pubcomp Packet type.

type Publish

type Publish struct {
	FixedHeader
	Topic       []byte
	MessageID   uint16
	IsForwarded bool
	Payload     []byte

	Packet
}

Publish represents a publish packet.

func (*Publish) Info

func (p *Publish) Info() Info

Info returns Qos and MessageID of this packet.

func (*Publish) Type

func (p *Publish) Type() uint8

Type returns the Publish Packet type.

type Pubrec

type Pubrec struct {
	FixedHeader
	MessageID uint16

	Packet
}

Pubrec is for verifying the receipt of a publish Qoth the spec:"It is the second Packet of the QoS level 2 protocol flow. A PUBREC Packet is sent by the server in response to a PUBLISH Packet from a publishing client, or by a subscriber in response to a PUBLISH Packet from the server."

func (*Pubrec) Info

func (p *Pubrec) Info() Info

Info returns Qos and MessageID of this packet.

func (*Pubrec) Type

func (p *Pubrec) Type() uint8

Type returns the Pubrec Packet type.

type Pubrel

type Pubrel struct {
	FixedHeader
	MessageID uint16

	Packet
}

Pubrel is a response to pubrec from either the client or server.

func (*Pubrel) Info

func (p *Pubrel) Info() Info

Info returns Qos and MessageID of this packet.

func (*Pubrel) Type

func (p *Pubrel) Type() uint8

Type returns the Pubrel Packet type.

type Server

type Server interface {
	// Serve serve the requests if type tcp, websocket or grpc stream
	Serve(net.Listener) error
}

type Suback

type Suback struct {
	MessageID uint16
	Qos       []uint8

	Packet
}

Suback is to say "hey, you got it buddy. I will send you messages that fit this pattern"

func (*Suback) Info

func (s *Suback) Info() Info

Info returns Qos and MessageID of this packet.

func (*Suback) Type

func (s *Suback) Type() uint8

Type returns the Suback Packet type.

type Subscribe

type Subscribe struct {
	FixedHeader
	MessageID     uint16
	IsForwarded   bool
	Subscriptions []TopicQOSTuple

	Packet
}

Subscribe tells the server which topics the client would like to subscribe to

func (*Subscribe) Info

func (s *Subscribe) Info() Info

Info returns Qos and MessageID of this packet.

func (*Subscribe) Type

func (s *Subscribe) Type() uint8

Type returns the Subscribe Packet type.

type TcpServer

type TcpServer server

func NewTcpServer

func NewTcpServer(opts ...Options) *TcpServer

func (*TcpServer) Serve

func (s *TcpServer) Serve(list net.Listener) error

type TopicQOSTuple

type TopicQOSTuple struct {
	Qos   uint8
	Topic []byte
}

TopicQOSTuple is a struct for pairing the Qos and topic together for the QOS' pairs in unsubscribe and subscribe

type Unsuback

type Unsuback struct {
	MessageID uint16

	Packet
}

Unsuback is to unsubscribe as suback is to subscribe

func (*Unsuback) Info

func (u *Unsuback) Info() Info

Info returns Qos and MessageID of this packet.

func (*Unsuback) Type

func (u *Unsuback) Type() uint8

Type returns the Unsuback Packet type.

type Unsubscribe

type Unsubscribe struct {
	FixedHeader
	MessageID     uint16
	IsForwarded   bool
	Subscriptions []TopicQOSTuple

	Packet
}

Unsubscribe is the Packet to send if you don't want to subscribe to a topic anymore

func (*Unsubscribe) Info

func (u *Unsubscribe) Info() Info

Info returns Qos and MessageID of this packet.

func (*Unsubscribe) Type

func (u *Unsubscribe) Type() uint8

Type returns the Unsubscribe Packet type.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL