proxy

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2021 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const Protocol = "/proxy-example/0.0.1"

Protocol defines the libp2p protocol that we will use for the libp2p proxy service that we are going to provide. This will tag the streams used for this service. Streams are multiplexed and their protocol tag helps libp2p handle them to the right handler functions.

Variables

This section is empty.

Functions

func Start

func Start()

Types

type ProxyService

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

ProxyService provides HTTP proxying on top of libp2p by launching an HTTP server which tunnels the requests to a destination peer running ProxyService too.

func NewProxyService

func NewProxyService(h host.Host, proxyAddr ma.Multiaddr, dest peer.ID) *ProxyService

NewProxyService attaches a proxy service to the given libp2p Host. The proxyAddr parameter specifies the address on which the HTTP proxy server listens. The dest parameter specifies the peer ID of the remote peer in charge of performing the HTTP requests.

ProxyAddr/dest may be nil/"" it is not necessary that this host provides a listening HTTP server (and instead its only function is to perform the proxied http requests it receives from a different peer.

The addresses for the dest peer should be part of the host's peerstore.

func (*ProxyService) Serve

func (p *ProxyService) Serve()

Serve listens on the ProxyService's proxy address. This effectively allows to set the listening address as http proxy.

func (*ProxyService) ServeHTTP

func (p *ProxyService) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface. WARNING: This is the simplest approach to a proxy. Therefore we do not do any of the things that should be done when implementing a reverse proxy (like handling headers correctly). For how to do it properly, see: https://golang.org/src/net/http/httputil/reverseproxy.go?s=3845:3920#L121

ServeHTTP opens a stream to the dest peer for every HTTP request. Streams are multiplexed over single connections so, unlike connections themselves, they are cheap to create and dispose of.

Jump to

Keyboard shortcuts

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