eventsocket

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2023 License: Apache-2.0 Imports: 15 Imported by: 10

Documentation

Index

Constants

View Source
const (
	// Open is sent when a TCP connection is created.
	Open = TCPEvent(iota)
	// Close is sent when a TCP connection is closed.
	Close
)

Variables

View Source
var (
	// Filename is a command-line flag holding the name of the unix-domain
	// socket that should be used by the client and server. It is put here in an
	// attempt to have just one standard flag name.
	Filename = flag.String("tcpinfo.eventsocket", "", "The filename of the unix-domain socket on which events are served.")
)

Functions

func MustRun

func MustRun(ctx context.Context, socket string, handler Handler)

MustRun will read from the passed-in socket filename until the context is cancelled. Any errors are fatal.

Types

type FlowEvent

type FlowEvent struct {
	Event     TCPEvent
	Timestamp time.Time
	UUID      string
	ID        *inetdiag.SockID //`json:",omitempty"`
}

FlowEvent is the data that is sent down the socket in JSONL form to the clients. The UUID, Timestamp, and Event fields will always be filled in, all other fields are optional.

type Handler

type Handler interface {
	Open(ctx context.Context, timestamp time.Time, uuid string, ID *inetdiag.SockID)
	Close(ctx context.Context, timestamp time.Time, uuid string)
}

Handler is the interface that all interested users of the event socket notifications should implement. It has two methods, one called on Open events and one called on Close events.

type Server

type Server interface {
	Listen() error
	Serve(context.Context) error
	FlowCreated(timestamp time.Time, uuid string, sockid inetdiag.SockID)
	FlowDeleted(timestamp time.Time, uuid string)
}

Server is the interface that has the methods that actually serve the events over the unix domain socket. You should make new Server objects with eventsocket.New or eventsocket.NullServer.

func New

func New(filename string) Server

New makes a new server that serves clients on the provided Unix domain socket.

func NullServer

func NullServer() Server

NullServer returns a Server that does nothing. It is made so that code that may or may not want to use a eventsocket can receive a Server interface and not have to worry about whether it is nil.

type TCPEvent

type TCPEvent int

TCPEvent refers to the kind of socket event that has occurred. Right now, we support Open and Close events, but it is not impossible to imagine future versions that do more.

func (TCPEvent) String

func (i TCPEvent) String() string

Jump to

Keyboard shortcuts

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