shttp

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2022 License: Apache-2.0 Imports: 10 Imported by: 2

README

HTTP over SCION

This package contains glue code to use the standard net/http libraries for HTTP over SCION.

This uses a QUIC session with a single stream as a transport, instead of the standard TCP (for which we do not have an implementation on top of SCION). As TLS is always enabled in QUIC, we use an insecure TLS session with self signed certificates to get something similar to TCP for insecure HTTP. For HTTPS, we'll have two TLS sessions; the insecure TLS for the basic transport and on top of that, the "normal" TLS for the actual web content. This may seem silly, and the net/http library provides enough hooks that would allow using the "normal" TLS session directly. However, only this setup allows to implement CONNECT, e.g. to proxy HTTPS traffic over HTTP.

Client

We use the standard net/http Client/Transport with a customized Dial function:

// Create a client with our Transport/Dialer:
client := &http.Client{
    Transport: shttp.DefaultTransport,
}
// Make requests as usual
resp, err := client.Get("http://server:8080/download")

Hostnames are resolved by parsing the /etc/hosts file or by a RAINS lookup (see Hostnames). URLs potentially containing raw SCION addresses must be mangled before passing into the client (or any other place where they might be parsed as URL).

resp, err := client.Get(shttp.MangleSCIONURL("http://1-ff00:0:110,127.0.0.1:8080/download"))
Server

The server is used just like the standard net/http server; the handlers work all the same, only a custom listener is used for serving.

Example:

handler := http.FileServer(http.Dir("/usr/share/doc"))))
log.Fatal(shttp.ListenAndServe(":80", handler))

Documentation

Overview

package shttp provides glue to use net/http libraries for HTTP over SCION.

Index

Constants

This section is empty.

Variables

View Source
var DefaultTransport = &http.Transport{
	Proxy: http.ProxyFromEnvironment,
	DialContext: (&Dialer{
		QuicConfig: nil,
		Policy:     nil,
	}).DialContext,
	ForceAttemptHTTP2:     true,
	MaxIdleConns:          100,
	IdleConnTimeout:       90 * time.Second,
	TLSHandshakeTimeout:   10 * time.Second,
	ExpectContinueTimeout: 1 * time.Second,
}

DefaultTransport is the default RoundTripper that can be used for HTTP over SCION/QUIC. This is equivalent to net/http.DefaultTransport with DialContext overridden to use shttp.Dialer, which dials connections over SCION/QUIC.

Functions

func ListenAndServe

func ListenAndServe(addr string, handler http.Handler) error

ListenAndServe listens for HTTP connections on the SCION address addr and calls Serve with handler to handle requests

func ListenAndServeTLS added in v0.4.0

func ListenAndServeTLS(addr, certFile, keyFile string, handler http.Handler) error

ListenAndServe listens for HTTPS connections on the SCION address addr and calls Serve with handler to handle requests

func MangleSCIONAddrURL

func MangleSCIONAddrURL(url string) string

MangleSCIONAddrURL mangles a SCION address in the host part of a URL-ish string so that it can be safely used as a URL, i.e. it can be parsed by net/url.Parse

Types

type Dialer added in v0.4.0

type Dialer struct {
	Local      netaddr.IPPort
	QuicConfig *quic.Config
	Policy     pan.Policy
	// contains filtered or unexported fields
}

Dialer dials an insecure, single-stream QUIC connection over SCION (just pretend it's TCP). This is the Dialer used for shttp.DefaultTransport.

func NewTransport added in v0.5.0

func NewTransport(quicCfg *quic.Config, policy pan.Policy) (*http.Transport, *Dialer)

NewTransport creates a new RoundTripper that can be used for HTTP over SCION/QUIC, providing a custom QuicConfig and Policy to the Dialer. This equivalent to net/http.DefaultTransport with an overridden DialContext. Both the Transport and the Dialer are returned, as the Dialer is not otherwise accessible from the Transport.

func (*Dialer) DialContext added in v0.4.0

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

DialContext dials an insecure, single-stream QUIC connection over SCION. This can be used as the DialContext function in net/http.Transport.

func (*Dialer) SetPolicy added in v0.5.0

func (d *Dialer) SetPolicy(policy pan.Policy)

type Server

type Server struct {
	*http.Server
}

Server wraps a http.Server making it work with SCION

func (*Server) ListenAndServe

func (srv *Server) ListenAndServe() error

ListenAndServe listens for QUIC connections on srv.Addr and calls Serve to handle incoming requests

func (*Server) ListenAndServeTLS added in v0.4.0

func (srv *Server) ListenAndServeTLS(certFile, keyFile string) error

func (*Server) Serve

func (srv *Server) Serve(l net.Listener) error

func (*Server) ServeTLS added in v0.4.0

func (srv *Server) ServeTLS(l net.Listener, certFile, keyFile string) error

Jump to

Keyboard shortcuts

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