Skip to content

Commit

Permalink
Merge remote-tracking branch 'parent/master' into 3319-amplification
Browse files Browse the repository at this point in the history
# Conflicts:
#	server.go
  • Loading branch information
birneee committed May 13, 2022
2 parents f82e447 + 60bbe92 commit 3e2f97e
Show file tree
Hide file tree
Showing 113 changed files with 3,429 additions and 2,294 deletions.
14 changes: 12 additions & 2 deletions .circleci/config.yml
@@ -1,5 +1,11 @@
version: 2.1
executors:
test-go118:
docker:
- image: "cimg/go:1.18"
environment:
runrace: true
TIMESCALE_FACTOR: 3
test-go117:
docker:
- image: "cimg/go:1.17"
Expand All @@ -15,7 +21,7 @@ executors:

jobs:
"test": &test
executor: test-go117
executor: test-go118
steps:
- checkout
- run:
Expand All @@ -42,14 +48,18 @@ jobs:
- run:
name: "Run self integration tests with qlog"
command: ginkgo -v -randomizeAllSpecs -trace integrationtests/self -- -qlog
go118:
<<: *test
go117:
<<: *test
executor: test-go117
go116:
<<: *test
executor: test-go116

workflows:
workflow:
jobs:
- go116
- go118
- go117
- go116
2 changes: 1 addition & 1 deletion .github/workflows/cross-compile.yml
Expand Up @@ -4,7 +4,7 @@ jobs:
strategy:
fail-fast: false
matrix:
go: [ "1.16.x", "1.17.x" ]
go: [ "1.17.x", "1.18.x" ]
runs-on: ubuntu-latest
name: "Cross Compilation (Go ${{matrix.go}})"
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/go-generate.sh
Expand Up @@ -20,4 +20,4 @@ go generate ./...
cd ..

# don't compare fuzzing corpora
diff --exclude=corpus -ruN orig generated
diff --exclude=corpus --exclude=.git -ruN orig generated
2 changes: 1 addition & 1 deletion .github/workflows/go-generate.yml
Expand Up @@ -6,7 +6,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: "1.17.x"
go-version: "1.18.x"
- name: Install dependencies
run: go build
- name: Install code generators
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/integration.yml
Expand Up @@ -5,7 +5,7 @@ jobs:
strategy:
fail-fast: false
matrix:
go: [ "1.16.x", "1.17.x", "1.18.0-beta1" ]
go: [ "1.16.x", "1.17.x", "1.18.x" ]
runs-on: ubuntu-latest
env:
DEBUG: false # set this to true to export qlogs and save them as artifacts
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Expand Up @@ -7,7 +7,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: "1.17.x"
go-version: "1.18.x"
- name: Check that no non-test files import Ginkgo or Gomega
run: .github/workflows/no_ginkgo.sh
- name: Check that go.mod is tidied
Expand All @@ -28,4 +28,4 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.41.1
version: v1.45.2
2 changes: 1 addition & 1 deletion .github/workflows/unit.yml
Expand Up @@ -7,7 +7,7 @@ jobs:
fail-fast: false
matrix:
os: [ "ubuntu", "windows", "macos" ]
go: [ "1.16.x", "1.17.x", "1.18.0-beta1" ]
go: [ "1.16.x", "1.17.x", "1.18.x" ]
runs-on: ${{ matrix.os }}-latest
name: Unit tests (${{ matrix.os}}, Go ${{ matrix.go }})
steps:
Expand Down
1 change: 0 additions & 1 deletion .golangci.yml
Expand Up @@ -28,7 +28,6 @@ linters:
- ineffassign
- misspell
- prealloc
- scopelint
- staticcheck
- stylecheck
- structcheck
Expand Down
13 changes: 6 additions & 7 deletions README.md
Expand Up @@ -3,17 +3,15 @@
<img src="docs/quic.png" width=303 height=124>

[![PkgGoDev](https://pkg.go.dev/badge/github.com/lucas-clemente/quic-go)](https://pkg.go.dev/github.com/lucas-clemente/quic-go)
[![Travis Build Status](https://img.shields.io/travis/lucas-clemente/quic-go/master.svg?style=flat-square&label=Travis+build)](https://travis-ci.org/lucas-clemente/quic-go)
[![CircleCI Build Status](https://img.shields.io/circleci/project/github/lucas-clemente/quic-go.svg?style=flat-square&label=CircleCI+build)](https://circleci.com/gh/lucas-clemente/quic-go)
[![Windows Build Status](https://img.shields.io/appveyor/ci/lucas-clemente/quic-go/master.svg?style=flat-square&label=windows+build)](https://ci.appveyor.com/project/lucas-clemente/quic-go/branch/master)
[![Code Coverage](https://img.shields.io/codecov/c/github/lucas-clemente/quic-go/master.svg?style=flat-square)](https://codecov.io/gh/lucas-clemente/quic-go/)

quic-go is an implementation of the [QUIC protocol, RFC 9000](https://datatracker.ietf.org/doc/html/rfc9000) protocol in Go.
quic-go is an implementation of the [QUIC protocol, RFC 9000](https://datatracker.ietf.org/doc/html/rfc9000) protocol in Go, including the [Unreliable Datagram Extension, RFC 9221](https://datatracker.ietf.org/doc/html/rfc9221).

In addition to RFC 9000, it currently implements the [IETF QUIC draft-29](https://tools.ietf.org/html/draft-ietf-quic-transport-29). Support for draft-29 will eventually be dropped, as it is phased out of the ecosystem.

## Guides

*We currently support Go 1.16.x and Go 1.17.x.*
*We currently support Go 1.16.x, Go 1.17.x, and Go 1.18.x.*

Running tests:

Expand Down Expand Up @@ -51,11 +49,12 @@ http.Client{
| [algernon](https://github.com/xyproto/algernon) | Small self-contained pure-Go web server with Lua, Markdown, HTTP/2, QUIC, Redis and PostgreSQL support | ![GitHub Repo stars](https://img.shields.io/github/stars/xyproto/algernon?style=flat-square) |
| [caddy](https://github.com/caddyserver/caddy/) | Fast, multi-platform web server with automatic HTTPS | ![GitHub Repo stars](https://img.shields.io/github/stars/caddyserver/caddy?style=flat-square) |
| [go-ipfs](https://github.com/ipfs/go-ipfs) | IPFS implementation in go | ![GitHub Repo stars](https://img.shields.io/github/stars/ipfs/go-ipfs?style=flat-square) |
| [nextdns](https://github.com/nextdns/nextdns) | NextDNS CLI client (DoH Proxy) | ![GitHub Repo stars](https://img.shields.io/github/stars/nextdns/nextdns?style=flat-square) |
| [syncthing](https://github.com/syncthing/syncthing/) | Open Source Continuous File Synchronization | ![GitHub Repo stars](https://img.shields.io/github/stars/syncthing/syncthing?style=flat-square) |
| [traefik](https://github.com/traefik/traefik) | The Cloud Native Application Proxy | ![GitHub Repo stars](https://img.shields.io/github/stars/traefik/traefik?style=flat-square) |
| [v2ray-core](https://github.com/v2fly/v2ray-core) | A platform for building proxies to bypass network restrictions | ![GitHub Repo stars](https://img.shields.io/github/stars/v2fly/v2ray-core?style=flat-square) |
| [cloudflared](https://github.com/cloudflare/cloudflared) | A tunneling daemon that proxies traffic from the Cloudflare network to your origins | ![GitHub Repo stars](https://img.shields.io/github/stars/cloudflare/cloudflared?style=flat-square) |
| [cloudflared](https://github.com/cloudflare/cloudflared) | A tunneling daemon that proxies traffic from the Cloudflare network to your origins | ![GitHub Repo stars](https://img.shields.io/github/stars/cloudflare/cloudflared?style=flat-square) |
| [OONI Probe](https://github.com/ooni/probe-cli) | The Open Observatory of Network Interference (OONI) aims to empower decentralized efforts in documenting Internet censorship around the world. | ![GitHub Repo stars](https://img.shields.io/github/stars/ooni/probe-cli?style=flat-square) |


## Contributing

Expand Down
68 changes: 35 additions & 33 deletions client.go
Expand Up @@ -14,7 +14,7 @@ import (
)

type client struct {
conn sendConn
sconn sendConn
// If the client is created with DialAddr, we create a packet conn.
// If it is started with Dial, we take a packet conn as a parameter.
createdPacketConn bool
Expand All @@ -35,7 +35,7 @@ type client struct {

handshakeChan chan struct{}

session quicSession
conn quicConn

tracer logging.ConnectionTracer
tracingID uint64
Expand All @@ -49,26 +49,26 @@ var (
)

// DialAddr establishes a new QUIC connection to a server.
// It uses a new UDP connection and closes this connection when the QUIC session is closed.
// It uses a new UDP connection and closes this connection when the QUIC connection is closed.
// The hostname for SNI is taken from the given address.
// The tls.Config.CipherSuites allows setting of TLS 1.3 cipher suites.
func DialAddr(
addr string,
tlsConf *tls.Config,
config *Config,
) (Session, error) {
) (Connection, error) {
return DialAddrContext(context.Background(), addr, tlsConf, config)
}

// DialAddrEarly establishes a new 0-RTT QUIC connection to a server.
// It uses a new UDP connection and closes this connection when the QUIC session is closed.
// It uses a new UDP connection and closes this connection when the QUIC connection is closed.
// The hostname for SNI is taken from the given address.
// The tls.Config.CipherSuites allows setting of TLS 1.3 cipher suites.
func DialAddrEarly(
addr string,
tlsConf *tls.Config,
config *Config,
) (EarlySession, error) {
) (EarlyConnection, error) {
return DialAddrEarlyContext(context.Background(), addr, tlsConf, config)
}

Expand All @@ -79,13 +79,13 @@ func DialAddrEarlyContext(
addr string,
tlsConf *tls.Config,
config *Config,
) (EarlySession, error) {
sess, err := dialAddrContext(ctx, addr, tlsConf, config, true)
) (EarlyConnection, error) {
conn, err := dialAddrContext(ctx, addr, tlsConf, config, true)
if err != nil {
return nil, err
}
utils.Logger.WithPrefix(utils.DefaultLogger, "client").Debugf("Returning early session")
return sess, nil
utils.Logger.WithPrefix(utils.DefaultLogger, "client").Debugf("Returning early connection")
return conn, nil
}

// DialAddrContext establishes a new QUIC connection to a server using the provided context.
Expand All @@ -95,7 +95,7 @@ func DialAddrContext(
addr string,
tlsConf *tls.Config,
config *Config,
) (Session, error) {
) (Connection, error) {
return dialAddrContext(ctx, addr, tlsConf, config, false)
}

Expand All @@ -105,7 +105,7 @@ func dialAddrContext(
tlsConf *tls.Config,
config *Config,
use0RTT bool,
) (quicSession, error) {
) (quicConn, error) {
udpAddr, err := net.ResolveUDPAddr("udp", addr)
if err != nil {
return nil, err
Expand All @@ -131,7 +131,7 @@ func Dial(
host string,
tlsConf *tls.Config,
config *Config,
) (Session, error) {
) (Connection, error) {
return dialContext(context.Background(), pconn, remoteAddr, host, tlsConf, config, false, false)
}

Expand All @@ -146,7 +146,7 @@ func DialEarly(
host string,
tlsConf *tls.Config,
config *Config,
) (EarlySession, error) {
) (EarlyConnection, error) {
return DialEarlyContext(context.Background(), pconn, remoteAddr, host, tlsConf, config)
}

Expand All @@ -159,7 +159,7 @@ func DialEarlyContext(
host string,
tlsConf *tls.Config,
config *Config,
) (EarlySession, error) {
) (EarlyConnection, error) {
return dialContext(ctx, pconn, remoteAddr, host, tlsConf, config, true, false)
}

Expand All @@ -172,7 +172,7 @@ func DialContext(
host string,
tlsConf *tls.Config,
config *Config,
) (Session, error) {
) (Connection, error) {
return dialContext(ctx, pconn, remoteAddr, host, tlsConf, config, false, false)
}

Expand All @@ -185,7 +185,7 @@ func dialContext(
config *Config,
use0RTT bool,
createdPacketConn bool,
) (quicSession, error) {
) (quicConn, error) {
if tlsConf == nil {
return nil, errors.New("quic: tls.Config not set")
}
Expand All @@ -203,21 +203,21 @@ func dialContext(
}
c.packetHandlers = packetHandlers

c.tracingID = nextSessionTracingID()
c.tracingID = nextConnTracingID()
if c.config.Tracer != nil {
c.tracer = c.config.Tracer.TracerForConnection(
context.WithValue(ctx, SessionTracingKey, c.tracingID),
context.WithValue(ctx, ConnectionTracingKey, c.tracingID),
protocol.PerspectiveClient,
c.destConnID,
)
}
if c.tracer != nil {
c.tracer.StartedConnection(c.conn.LocalAddr(), c.conn.RemoteAddr(), c.srcConnID, c.destConnID)
c.tracer.StartedConnection(c.sconn.LocalAddr(), c.sconn.RemoteAddr(), c.srcConnID, c.destConnID)
}
if err := c.dial(ctx); err != nil {
return nil, err
}
return c.session, nil
return c.conn, nil
}

func newClient(
Expand All @@ -231,6 +231,8 @@ func newClient(
) (*client, error) {
if tlsConf == nil {
tlsConf = &tls.Config{}
} else {
tlsConf = tlsConf.Clone()
}
if tlsConf.ServerName == "" {
sni := host
Expand Down Expand Up @@ -265,7 +267,7 @@ func newClient(
c := &client{
srcConnID: srcConnID,
destConnID: destConnID,
conn: newSendPconn(pconn, remoteAddr),
sconn: newSendPconn(pconn, remoteAddr),
createdPacketConn: createdPacketConn,
use0RTT: use0RTT,
tlsConf: tlsConf,
Expand All @@ -278,10 +280,10 @@ func newClient(
}

func (c *client) dial(ctx context.Context) error {
c.logger.Infof("Starting new connection to %s (%s -> %s), source connection ID %s, destination connection ID %s, version %s", c.tlsConf.ServerName, c.conn.LocalAddr(), c.conn.RemoteAddr(), c.srcConnID, c.destConnID, c.version)
c.logger.Infof("Starting new connection to %s (%s -> %s), source connection ID %s, destination connection ID %s, version %s", c.tlsConf.ServerName, c.sconn.LocalAddr(), c.sconn.RemoteAddr(), c.srcConnID, c.destConnID, c.version)

c.session = newClientSession(
c.conn,
c.conn = newClientConnection(
c.sconn,
c.packetHandlers,
c.destConnID,
c.srcConnID,
Expand All @@ -295,11 +297,11 @@ func (c *client) dial(ctx context.Context) error {
c.logger,
c.version,
)
c.packetHandlers.Add(c.srcConnID, c.session)
c.packetHandlers.Add(c.srcConnID, c.conn)

errorChan := make(chan error, 1)
go func() {
err := c.session.run() // returns as soon as the session is closed
err := c.conn.run() // returns as soon as the connection is closed

if e := (&errCloseForRecreating{}); !errors.As(err, &e) && c.createdPacketConn {
c.packetHandlers.Destroy()
Expand All @@ -308,15 +310,15 @@ func (c *client) dial(ctx context.Context) error {
}()

// only set when we're using 0-RTT
// Otherwise, earlySessionChan will be nil. Receiving from a nil chan blocks forever.
var earlySessionChan <-chan struct{}
// Otherwise, earlyConnChan will be nil. Receiving from a nil chan blocks forever.
var earlyConnChan <-chan struct{}
if c.use0RTT {
earlySessionChan = c.session.earlySessionReady()
earlyConnChan = c.conn.earlyConnReady()
}

select {
case <-ctx.Done():
c.session.shutdown()
c.conn.shutdown()
return ctx.Err()
case err := <-errorChan:
var recreateErr *errCloseForRecreating
Expand All @@ -327,10 +329,10 @@ func (c *client) dial(ctx context.Context) error {
return c.dial(ctx)
}
return err
case <-earlySessionChan:
case <-earlyConnChan:
// ready to send 0-RTT data
return nil
case <-c.session.HandshakeComplete().Done():
case <-c.conn.HandshakeComplete().Done():
// handshake successfully completed
return nil
}
Expand Down

0 comments on commit 3e2f97e

Please sign in to comment.