network

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2021 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package network provides functionality to work with the underlying QUIC protocol

Index

Constants

View Source
const (
	ConnectionTimeout          = 5 * time.Second
	ConnectionHandshakeTimeout = 5 * time.Second
	RequestTimeout             = 10 * time.Second
)

Variables

View Source
var (
	ErrorPanic         = errors.New("panic")
	ErrorTimeout       = errors.New("timeout")
	ErrorChannelClosed = errors.New("channel closed")
)
View Source
var (
	ErrorGenRes = errors.New("message does not need a response")
)

Functions

func GenerateQuicConfig

func GenerateQuicConfig(c Config) *quic.Config

Generate QUIC Config with defaults

func GenerateTLSConfig

func GenerateTLSConfig() *tls.Config

Generate TLS Config with defaults

Types

type Channel

type Channel struct {
	// contains filtered or unexported fields
}

Channel

func NewChannel

func NewChannel(log *logrus.Logger, stream quic.Stream, unmarshalers []ChannelUnmarshaler) *Channel

Create a new channel

func (*Channel) Close

func (c *Channel) Close()

Closes the channel

func (*Channel) Read

func (c *Channel) Read(multiple bool) (msg *Message, err error)

Read single or multiple messages from the channel stream

func (*Channel) Send

func (c *Channel) Send(msg *Message) (rmsg *Message, err error)

Send a message through the channel stream

func (*Channel) SendAndRead

func (c *Channel) SendAndRead(msg *Message) (rmsg *Message, err error)

If the channel is not actively read, this function sends and reads a single message This method SHOULD NOT BE USED if the channel is actively being read. Just use the Send function.

func (*Channel) Stream

func (c *Channel) Stream() quic.Stream

Returns the channel's stream

type ChannelUnmarshaler

type ChannelUnmarshaler func(mtype MessageType) (msg proto.Message, err error)

Unmarshals protobuf encoded data depending on the MessageType

type Config

type Config interface {
	// Maximum number of concurrent streams open on connection
	MaxStreams() int16
	// Use QUIC Datagram
	// This model does not guarantee a packet will be delivered
	UseDatagram() bool
}

Config Interface

type Message

type Message struct {
	// Message Context
	Ctx MessageContext
	// Message Options
	Opt MessageOptions
	// Message Body
	Body proto.Message
}

Message

func NewMessage

func NewMessage(mtype MessageType, mbody proto.Message) (msg *Message)

New Message with default options

func NewMessageWithAck

func NewMessageWithAck(mtype MessageType, mbody proto.Message, timeout time.Duration) (msg *Message)

New Message which requires an ACK

func NewMessageWithOptions

func NewMessageWithOptions(mtype MessageType, mbody proto.Message, nopt NewMessageOptions) (msg *Message)

New Message with custom options

func (*Message) GenReply

func (m *Message) GenReply(mtype MessageType, mbody proto.Message) (msg *Message, err error)

Generate message reply

func (*Message) String

func (m *Message) String() string

Stringify

type MessageContext

type MessageContext struct {
	// Message ID
	Id string
	// Message needs an Acknowledgement
	Ack bool
	// Message is Acknowledgement Reply
	Ackr bool
	// Message Type
	Type MessageType
}

Stores the context of a message

type MessageOptions

type MessageOptions struct {
	// Duration after which the Message Request Timesout
	Timeout time.Duration
}

Message Options

type MessageType

type MessageType string

Message Type

type NewMessageOptions

type NewMessageOptions struct {
	// Message requires an ACK
	Ack bool
	// Message Timeout Duration
	Timeout time.Duration
}

New Message Options

type PingResult

type PingResult struct {
	// Ping Status
	Status bool
	// Ping Status Message
	Message string
	// Ping Address
	Addr string
	// Average time taken
	AvgTime time.Duration
}

Stores the result of a ping request

func PingIP

func PingIP(ip string, count int) (res PingResult, err error)

Pings an IP for "count" number of times

type PingResults

type PingResults struct {
	// Success Results
	Success []PingResult
	// Failed Results
	Failed []PingResult
}

Stores results of PingAddrs

func PingAddrs

func PingAddrs(addresses []string, asc bool) (result PingResults)

Ping a list of addresses and sort the results in asc or dsc order

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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