transport

package
v0.0.0-...-379bc4c Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn interface {
	InboundConn
	OutboundConn
	Close() error
}

type Inbound

type Inbound interface {
	Packets() <-chan *packet.Packet
	Stop() error
}

An inbound transport is a channel'ed abstraction around a net.UDPConn. Provides an abstraction around inbound packets on the network to allow using the existing protocol implementation without a miIO network handy. Consumers of this interface should never close the underlying UDP connection without first calling Stop().

func NewInbound

func NewInbound(socket InboundConn) Inbound

type InboundConn

type InboundConn interface {
	ReadFromUDP(b []byte) (int, *net.UDPAddr, error)
}

InboundConn is an abstraction around net.UDPConn to allow mocking during tests.

type Outbound

type Outbound interface {
	// Handle handles incoming packets and triggers waiting continuations.
	Handle(pkt *packet.Packet) error
	// Call makes a call, waits for a Response and returns the raw bytes returned.
	Call(method string, params interface{}) ([]byte, error)
	// CallAndDeserialize makes a call, waits for a Response and deserialises the JSON
	// payload into `ret`.
	CallAndDeserialize(method string, params interface{}, resp interface{}) error
	// Send will send a raw packet without waiting for a Response.
	Send(packet *packet.Packet) error
}

Outbound transport is an abstraction around a net.UDPConn for outbound interaction with a networked miIO device. Consumers should never close the underlying socket and continue to use the service. Outbound also provides retry and timeout logic.

func NewOutbound

func NewOutbound(crypto packet.Crypto, dest net.Addr, socket OutboundConn) Outbound

type OutboundConn

type OutboundConn interface {
	WriteTo([]byte, net.Addr) (int, error)
}

type Request

type Request struct {
	ID     uint32      `json:"id"`
	Method string      `json:"method"`
	Params interface{} `json:"params"`
}

type Response

type Response struct {
	ID     uint32      `json:"id"`
	Result interface{} `json:"result"`
}

type Transport

type Transport interface {
	Inbound() Inbound
	NewOutbound(crypto packet.Crypto, dest net.Addr) Outbound
	Close() error
}

func NewTransport

func NewTransport(socket Conn) Transport

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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