sfproto

package
v0.0.0-...-0dfd57a Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultKeepalive = 30 * time.Second
View Source
const DefaultPort = "23100"
View Source
const DefaultTlsPort = "23443"

Variables

View Source
var (
	ErrClosed = errors.New("The other end is closed.")
)

Functions

func Dial

func Dial(cfg *NetConfig) (sarif.Connection, error)

func NewClientFactory

func NewClientFactory(cfg NetConfig) sarif.ClientFactory

func SetDefaultLogger

func SetDefaultLogger(l Logger)

func Subscribe

func Subscribe(action, device string) sarif.Message

func Transmit

func Transmit(a, b Conn) error

Types

type AuthType

type AuthType string
const (
	AuthNone        AuthType = "none"
	AuthChallenge   AuthType = ""
	AuthCertificate          = "certificate"
)

type Broker

type Broker struct {
	Log Logger
	// contains filtered or unexported fields
}

Broker dispatches messages to connections based on their subscriptions.

func NewBroker

func NewBroker() *Broker

NewBroker returns a new broker that dispatches messages.

func (*Broker) AuthenticateAndListenOnConn

func (b *Broker) AuthenticateAndListenOnConn(auth AuthType, c Conn) error

func (*Broker) Listen

func (b *Broker) Listen(cfg *NetConfig) error

Listen starts accepting connections on the specified network and blocks until an error is received.

func (*Broker) ListenOnBridge

func (b *Broker) ListenOnBridge(conn Conn) error

ListenOnBridge forms a bridge between two brokers by transmitting all messages in both directions, regardless of subscriptions. The call blocks until an error is received.

func (*Broker) ListenOnConn

func (b *Broker) ListenOnConn(conn Conn) error

ListenOnConn starts listening on the connection for incoming messages and sends outgoing messages based on its subscriptions. The call blocks until an error is received, for example when the connection is closed.

func (*Broker) ListenOnGateway

func (b *Broker) ListenOnGateway(conn Conn) error

ListenOnGateway forms a client-server-relationship between two brokers by transmitting all local messages to the gateway, but receiving only subscribed messages in return.

func (*Broker) NewClient

func (b *Broker) NewClient(ci sarif.ClientInfo) (sarif.Client, error)

func (*Broker) NewLocalConn

func (b *Broker) NewLocalConn() Conn

NewLocalConn creates a new local connection and starts listening on it.

func (*Broker) PrintSubtree

func (b *Broker) PrintSubtree(w io.Writer) error

func (*Broker) SetDuplicateDepth

func (b *Broker) SetDuplicateDepth(depth int)

SetDuplicateDepth sets the number of stored messages to check for duplicates. A zero value disables duplicate checking.

func (*Broker) SetLogger

func (b *Broker) SetLogger(log Logger)

SetLogger sets the default log output.

func (*Broker) TraceMessages

func (b *Broker) TraceMessages(enabled bool)

TraceMessages enables debug output of individual messages

type Conn

type Conn interface {
	Read() (sarif.Message, error)
	Write(msg sarif.Message) error
	Close() error
}

func NewByteConn

func NewByteConn(conn io.ReadWriteCloser) Conn

func NewPipe

func NewPipe() (a, b Conn)

func RawDial

func RawDial(cfg *NetConfig) (Conn, error)

Dial connects to a sarif broker.

type Logger

type Logger interface {
	Debugln(v ...interface{})
	Infoln(v ...interface{})
	Warnln(v ...interface{})
	Errorln(v ...interface{})
	Fatalln(v ...interface{})
	Debugf(format string, v ...interface{})
	Infof(format string, v ...interface{})
	Warnf(format string, v ...interface{})
	Errorf(format string, v ...interface{})
	Fatalf(format string, v ...interface{})
}

type NetConfig

type NetConfig struct {
	Address     string
	Auth        AuthType
	Certificate string
	Key         string
	Authority   string
	Tls         *tls.Config `json:"-"`
	Keepalive   int         `json:",omitempty"`
}

type NetListener

type NetListener struct {
	net.Listener
	// contains filtered or unexported fields
}

func Listen

func Listen(cfg *NetConfig) (*NetListener, error)

func (*NetListener) Accept

func (l *NetListener) Accept() (Conn, error)

Jump to

Keyboard shortcuts

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