drpcmigrate

package
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2021 License: MIT Imports: 7 Imported by: 15

README

package drpcmigrate

import "storj.io/drpc/drpcmigrate"

Package drpcmigrate provides tools to support drpc concurrently alongside gRPC on the same ports. See the grpc_and_drpc example in the examples folder for expected usage.

Usage

var Closed = errs.New("listener closed")

Closed is returned by routed listeners when the mux is closed.

var DRPCHeader = "DRPC!!!1"

DRPCHeader is a header for DRPC connections to use. This is designed to not conflict with a headerless gRPC, HTTP, or TLS request.

func DialWithHeader
func DialWithHeader(ctx context.Context, network, address string, header string) (net.Conn, error)

DialWithHeader is like net.Dial, but uses HeaderConns with the provided header.

type HeaderConn
type HeaderConn struct {
	net.Conn
}

HeaderConn fulfills the net.Conn interface. On the first call to Write it will write the Header.

func NewHeaderConn
func NewHeaderConn(conn net.Conn, header string) *HeaderConn

NewHeaderConn returns a new *HeaderConn that writes the provided header as part of the first Write.

func (*HeaderConn) Write
func (d *HeaderConn) Write(buf []byte) (n int, err error)

Write will write buf to the underlying conn. If this is the first time Write is called it will prepend the Header to the beginning of the write.

type HeaderDialer
type HeaderDialer struct {
	net.Dialer
	Header string
}

HeaderDialer is a net.Dialer-like that prefixes all conns with the provided header.

func (*HeaderDialer) Dial
func (d *HeaderDialer) Dial(network, address string) (net.Conn, error)

Dial will dial the address on the named network, creating a connection that will write the configured Header on the first user-requested write.

func (*HeaderDialer) DialContext
func (d *HeaderDialer) DialContext(ctx context.Context, network, address string) (net.Conn, error)

DialContext will dial the address on the named network, creating a connection that will write the configured Header on the first user-requested write.

type ListenMux
type ListenMux struct {
}

ListenMux lets one multiplex a listener into different listeners based on the first bytes sent on the connection.

func NewListenMux
func NewListenMux(base net.Listener, prefixLen int) *ListenMux

NewListenMux creates a ListenMux that reads the prefixLen bytes from any connections Accepted by the passed in listener and dispatches to the appropriate route.

func (*ListenMux) Default
func (m *ListenMux) Default() net.Listener

Default returns the net.Listener that is used if no route matches.

func (*ListenMux) Route
func (m *ListenMux) Route(prefix string) net.Listener

Route returns a listener that will be used if the first bytes are the given prefix. The length of the prefix must match the original passed in prefixLen.

func (*ListenMux) Run
func (m *ListenMux) Run(ctx context.Context) error

Run calls listen on the provided listener and passes connections to the routed listeners.

Documentation

Overview

Package drpcmigrate provides tools to support drpc concurrently alongside gRPC on the same ports. See the grpc_and_drpc example in the examples folder for expected usage.

Index

Constants

This section is empty.

Variables

View Source
var Closed = errs.New("listener closed")

Closed is returned by routed listeners when the mux is closed.

View Source
var DRPCHeader = "DRPC!!!1"

DRPCHeader is a header for DRPC connections to use. This is designed to not conflict with a headerless gRPC, HTTP, or TLS request.

Functions

func DialWithHeader

func DialWithHeader(ctx context.Context, network, address string, header string) (net.Conn, error)

DialWithHeader is like net.Dial, but uses HeaderConns with the provided header.

Types

type HeaderConn

type HeaderConn struct {
	net.Conn
	// contains filtered or unexported fields
}

HeaderConn fulfills the net.Conn interface. On the first call to Write it will write the Header.

func NewHeaderConn

func NewHeaderConn(conn net.Conn, header string) *HeaderConn

NewHeaderConn returns a new *HeaderConn that writes the provided header as part of the first Write.

func (*HeaderConn) Write

func (d *HeaderConn) Write(buf []byte) (n int, err error)

Write will write buf to the underlying conn. If this is the first time Write is called it will prepend the Header to the beginning of the write.

type HeaderDialer

type HeaderDialer struct {
	net.Dialer
	Header string
}

HeaderDialer is a net.Dialer-like that prefixes all conns with the provided header.

func (*HeaderDialer) Dial

func (d *HeaderDialer) Dial(network, address string) (net.Conn, error)

Dial will dial the address on the named network, creating a connection that will write the configured Header on the first user-requested write.

func (*HeaderDialer) DialContext

func (d *HeaderDialer) DialContext(ctx context.Context, network, address string) (net.Conn, error)

DialContext will dial the address on the named network, creating a connection that will write the configured Header on the first user-requested write.

type ListenMux

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

ListenMux lets one multiplex a listener into different listeners based on the first bytes sent on the connection.

func NewListenMux

func NewListenMux(base net.Listener, prefixLen int) *ListenMux

NewListenMux creates a ListenMux that reads the prefixLen bytes from any connections Accepted by the passed in listener and dispatches to the appropriate route.

func (*ListenMux) Default

func (m *ListenMux) Default() net.Listener

Default returns the net.Listener that is used if no route matches.

func (*ListenMux) Route

func (m *ListenMux) Route(prefix string) net.Listener

Route returns a listener that will be used if the first bytes are the given prefix. The length of the prefix must match the original passed in prefixLen.

func (*ListenMux) Run

func (m *ListenMux) Run(ctx context.Context) error

Run calls listen on the provided listener and passes connections to the routed listeners.

Jump to

Keyboard shortcuts

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