gossiphttp

package
v0.0.0-...-d90da2b Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package gossiphttp implements an HTTP/2 transport for gossip.

Protocol

Peers send two types of messages to each other:

  1. /api/v1/ckit/transport/message sends a stream of messages to a peer. The receiver does not respond with any messages.

  2. /api/v1/ckit/transport/stream opens a bidirectional communication channel to a peer, where both peers may send messages to each other. Once either peer closes the connection, the stream is terminated.

Both requests expect the Content-Type header to be set to application/x.ckit.

Requests MUST be delivered over HTTP/2. HTTP/1.X requests will be rejected with HTTP 505 HTTP Version Not Supported.

Message Format

All messages sent between peers have the same format:

+------------------------+
| Magic = 0xCC <1  byte> |
|------------------------|
| Data length  <2 bytes> |
|------------------------|
| Data         <n bytes> |
+------------------------+

It is recommended that the message data size kept within the UDP MTU size, normally 1400 bytes. The message data size must not exeed 65,535 bytes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// Optional logger to use.
	Log log.Logger

	// Client to use for communicating to peers. Required. The Transport used
	// by the client must be able to handle HTTP/2 requests for any peer.
	//
	// Note that TLS is not required for communication between peers. The
	// Client.Transport should be able to fall back to h2c for HTTP/2 traffic
	// when connections over HTTPS are not used.
	Client *http.Client

	// Timeout to use when sending a packet.
	PacketTimeout time.Duration

	// UseHTTPS defines whether TLS should be used for communication between
	// peers.
	UseHTTPS bool
}

Options controls the gossiphttp transport.

type Transport

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

Transport is an HTTP/2 implementation of memberlist.Transport. Call NewTransport to create one.

func NewTransport

func NewTransport(opts Options) (*Transport, prometheus.Collector, error)

NewTransport returns a new Transport. Transports must be attached to an HTTP server so their endpoints are invoked. See [Handler] for more information.

func (*Transport) DialAddressTimeout

func (t *Transport) DialAddressTimeout(addr memberlist.Address, timeout time.Duration) (net.Conn, error)

DialAddressTimeout implements NodeAwareTransport.

func (*Transport) DialTimeout

func (t *Transport) DialTimeout(addr string, timeout time.Duration) (net.Conn, error)

DialTimeout opens a bidirectional communication channel to the specified peer address.

func (*Transport) FinalAdvertiseAddr

func (t *Transport) FinalAdvertiseAddr(ip string, port int) (net.IP, int, error)

FinalAdvertiseAddr returns the address this peer uses to advertise its connections.

func (*Transport) Handler

func (t *Transport) Handler() (route string, handler http.Handler)

Handler returns the base HTTP route and handler for the Transport.

func (*Transport) PacketCh

func (t *Transport) PacketCh() <-chan *memberlist.Packet

PacketCh returns a channel of packets received from remote peers.

func (*Transport) Shutdown

func (t *Transport) Shutdown() error

Shutdown terminates the transport.

func (*Transport) StreamCh

func (t *Transport) StreamCh() <-chan net.Conn

StreamCh returns a channel of bidirectional communication channels opened by remote peers.

func (*Transport) WriteTo

func (t *Transport) WriteTo(b []byte, addr string) (time.Time, error)

WriteTo enqueues a message b to be sent to the peer specified by addr. The message is delivered in the background asynchronously by the transport.

func (*Transport) WriteToAddress

func (t *Transport) WriteToAddress(b []byte, addr memberlist.Address) (time.Time, error)

WriteToAddress implements NodeAwareTransport.

Jump to

Keyboard shortcuts

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