nego

package
v0.0.0-...-fdd8d4b Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2019 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLackData = errors.New("LACK OF DATA")
)

Errors caused by handlers

View Source
var ErrMockCommit = errors.New("MOCK")

ErrMockCommit is for mocking the error on handler's committments.

Functions

This section is empty.

Types

type ControlHandler

type ControlHandler interface {
	Handler
	Command() telbyte.Command
	Handle() error
}

ControlHandler takes care of control commands (e.g. GA, IP, etc.) in its Handle function. Note that the option commands (i.e. WILL, WONT, DO, DONT) should not be handled by ControlHandler, but rather to be processed within an OptionHandler.

type Handler

type Handler interface {
}

Handler is registered to negotiator for telnet command interpretion

type HandlerCommittee

type HandlerCommittee interface {
	Commit(p packet.Packet) error
	GotError(err error)
}

HandlerCommittee takes any result or error that committed by a handler.

type MockCommittee

type MockCommittee struct {
	Packet packet.Packet
	Err    error
	// contains filtered or unexported fields
}

MockCommittee is for unit tests only

func NewMockCommittee

func NewMockCommittee(bad bool) *MockCommittee

NewMockCommittee returns a committee pointer that just for unit testing, with the 'bad' parameter which causes an ErrMock on any Commit().

func (*MockCommittee) Commit

func (s *MockCommittee) Commit(p packet.Packet) error

Commit for unit test, which causes an ErrMockCommit on a bad committee

func (*MockCommittee) GotError

func (s *MockCommittee) GotError(err error)

GotError for unit tests, which records error in the Err field.

type Negotiator

type Negotiator struct {
	*common.BaseSubProc
	// contains filtered or unexported fields
}

Negotiator takes care of telnet negotiations

func New

func New(sender common.PacketSender) *Negotiator

New negotiator takes a PacketSender for its handlers to feed replies. It is created with an empty knowledge base, i.e. you'll have to feed in Handlers with Know() method.

func (*Negotiator) Commit

func (nego *Negotiator) Commit(p packet.Packet) error

Commit a packet to the negotiator's sender

func (*Negotiator) Consider

func (nego *Negotiator) Consider(p packet.Packet)

Consider how to deal with or to ignore the packet

func (*Negotiator) Know

func (nego *Negotiator) Know(handler Handler)

Know an handler makes the negotiator being able to deal with the corresponding incoming option

func (*Negotiator) Run

func (nego *Negotiator) Run(ctx context.Context)

Run the negotiator in a goroutine for processing any input and output packets

type OptionContext

type OptionContext struct {
	context.Context

	// Cancel the handler's context when needed.
	Cancel context.CancelFunc
	// Logger provides a main.nvt logger with the option's name as the value of 'handler' field.
	Logger *zap.SugaredLogger
	// contains filtered or unexported fields
}

OptionContext passes necessary callbacks and objects, such as logger, context, etc., to option handlers. Handler should call SendCmd() or SendSub() to write data back to terminal, and call GotError() to notify terminal on error occurance. The context is cancelled when Cancel() is called manually or when its parent context is cancelled.

func NewOptionContext

func NewOptionContext(
	parentCtx context.Context,
	handler OptionHandler,
	committee HandlerCommittee) *OptionContext

NewOptionContext returns a new option context

func (*OptionContext) GotError

func (c *OptionContext) GotError(err error)

GotError should be called to report errors in handler to terminal.

func (*OptionContext) SendCmd

func (c *OptionContext) SendCmd(cmd telbyte.Command)

SendCmd takes a command byte, packed into an OptionCommandPacket, and sent to server as a telnet option command.

func (*OptionContext) SendSub

func (c *OptionContext) SendSub(parameters ...[]byte)

SendSub takes subnegotiation parameter(s), packed into a SubPacket, and send to server as a telnet subnegotiation.

type OptionHandler

type OptionHandler interface {
	Handler
	Option() telbyte.Option
	Handshake(ctx *OptionContext, inCmd telbyte.Command)
	Subnegotiate(ctx *OptionContext, inParameter []byte)
}

OptionHandler takes care of option commands and subnegotiations of a certain Telnet Option

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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