httpt

package
v0.0.0-...-99e8b4e Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Brahms

type Brahms interface {
	IsActive() bool
	ReceiveNode(other brahms.Node)
	ReadView() brahms.View
}

Brahms provides the handler with the state of the algorithm

type Decoder

type Decoder interface {
	Decode(v interface{}) (err error)
}

Decoder is used for decoding messages from the request

type Encoder

type Encoder interface {
	Encode(v interface{}) (err error)
}

Encoder is used for encoding messages to the handlers response

type Handler

type Handler struct {
	C chan []byte
	// contains filtered or unexported fields
}

Handler handles brahms related messages

func NewHandler

func NewHandler(b Brahms, bufn int, to time.Duration) *Handler

NewHandler initates a new handler with default json encoding

func NewHandlerWithEncoding

func NewHandlerWithEncoding(b Brahms, bufn int, to time.Duration, enc func(r io.Writer) Encoder, dec func(r io.Reader) Decoder) *Handler

NewHandlerWithEncoding initates a new handler with custom encoding

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type MsgEmitReq

type MsgEmitReq struct {
	Data []byte `json:"data"`
}

MsgEmitReq requests a peer to emit data

type MsgNode

type MsgNode struct {
	IP   net.IP `json:"ip"`
	Port uint16 `json:"port"`
}

MsgNode transports node information

type MsgProbeResp

type MsgProbeResp struct {
	Active bool `json:"active"`
}

MsgProbeResp returns status info of a node

type MsgPullResp

type MsgPullResp []MsgNode

MsgPullResp returns a list of nodes info

type MsgPushReq

type MsgPushReq struct{ MsgNode }

MsgPushReq pushes information of a single node

type Transport

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

Transport is a transport that uses an http client

func New

func New(logw io.Writer) (tr *Transport)

New initializes the transport

func (*Transport) Emit

func (tr *Transport) Emit(ctx context.Context, c chan<- brahms.NID, id brahms.NID, msg []byte, to brahms.Node)

Emit implements custom message emitting

func (*Transport) Probe

func (tr *Transport) Probe(ctx context.Context, c chan<- brahms.NID, id brahms.NID, n brahms.Node)

Probe implements node status probing

func (*Transport) Pull

func (tr *Transport) Pull(ctx context.Context, c chan<- brahms.View, from brahms.Node)

Pull impelents node information pulling

func (*Transport) Push

func (tr *Transport) Push(ctx context.Context, self brahms.Node, to brahms.Node)

Push implements node information pushing

func (*Transport) Request

func (tr *Transport) Request(ctx context.Context, method string, n brahms.Node, path string, body io.Reader, msg interface{}) (err error)

Request performs a http request on the provided node an decodes the response into msg

func (*Transport) RequestOrLog

func (tr *Transport) RequestOrLog(ctx context.Context, method string, n brahms.Node, path string, body io.Reader, msg interface{}) (ok bool)

RequestOrLog will perform the request and log the error if anything fails

type TransportErr

type TransportErr struct {
	E  error
	Op string
}

TransportErr describes an error during transport functions

func (TransportErr) Error

func (e TransportErr) Error() string

Jump to

Keyboard shortcuts

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