Sample
github.com/quic-go/quic-go v0.61.0: quic.Connection.SendDatagram
Verified sample for golang github.com/quic-go/quic-go v0.61.0: quic.Connection.SendDatagram. The contract ran on go 1.26 · linux debian/x64 · docker and…
sha256:9ffcf9a533365e8c0072690923aeefb871693e492011db83907ad90bb69169dd
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 1
- Signing keys that built it
- 1
Declared environment
go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a… |
2026-09-05 |
Case
HOW- Goal
- verify quic.Connection.SendDatagram in pkg:golang/github.com/quic-go/quic-go@v0.61.0
- Packages
- Symbols
-
- quic.Connection.SendDatagram
- Environment
- go 1.26.6
- Created
- 2026-09-05T11:44:46Z
Contract
- quic.Connection.SendDatagram transmits datagram payload over an active QUIC connection with EnableDatagrams enabled
- quic.Connection.SendDatagram returns error when datagram support is disabled in quic.Config
- quic.Connection.SendDatagram returns DatagramTooLargeError when datagram payload exceeds maximum payload size
- quic.Connection.SendDatagram transmits zero-length datagram payload successfully
Files
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
Source
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify quic.Connection.SendDatagram in pkg:golang/github.com/quic-go/quic-go@v0.61.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/quic-go/quic-go@v0.61.0
Demonstrate these symbols/APIs:
- quic.Connection.SendDatagram
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:2f8063d7e21cef5211220f93fc891876a88b400f0f9d8608005613718afbdf64","contract":["quic.Connection.SendDatagram transmits datagram payload over an active QUIC connection with EnableDatagrams enabled","quic.Connection.SendDatagram returns error when datagram support is disabled in quic.Config","quic.Connection.SendDatagram returns DatagramTooLargeError when datagram payload exceeds maximum payload size","quic.Connection.SendDatagram transmits zero-length datagram payload successfully"],"goal":"verify quic.Connection.SendDatagram in pkg:golang/github.com/quic-go/quic-go@v0.61.0","kind":"HOW","packages":["pkg:golang/github.com/quic-go/quic-go@v0.61.0"],"schemaVersion":1,"symbols":["quic.Connection.SendDatagram"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","packageManagerVersion":"1.26.6","runtime":"go","runtimeVersion":"1.26.6","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/quic-go/quic-go@v0.61.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/quic-go/quic-go@v0.61.0","symbols":["quic.Connection.SendDatagram"],"verifierAdapter":"golang@1"}
module sample
go 1.26.6
require github.com/quic-go/quic-go v0.61.0
require (
golang.org/x/crypto v0.54.0 // indirect
golang.org/x/net v0.56.0 // indirect
golang.org/x/sys v0.47.0 // indirect
)
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/quic-go/go-ossfuzz-seeds v0.1.0 h1:APacT+iIaNF6fd8AGEiN3bT/Jtkd2jz4v4TzM7MFjy0=
github.com/quic-go/go-ossfuzz-seeds v0.1.0/go.mod h1:3IOHRbJIc+L6YKMwfDtJAM9Vj9k0YY4muhuyUYk5tbk=
github.com/quic-go/quic-go v0.61.0 h1:ui88A53s8MSVYLC56en0KQ17HARk+9986Dn0SBfKNvA=
github.com/quic-go/quic-go v0.61.0/go.mod h1:9So2anK4Tp22URSQq00k+Vo2PNkle96ycDPDHL4s9vs=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
go.uber.org/mock v0.5.2 h1:LbtPTcP8A5k9WPXj54PPPbjcI4Y6lhyOZXn+VS7wNko=
go.uber.org/mock v0.5.2/go.mod h1:wLlUxC2vVTPTaE3UD51E0BGOAElKrILxhVSDYQLld5o=
golang.org/x/crypto v0.54.0 h1:YLIA59K4fiNzHzjnZt2tUJQjQtUWfWbeHBqKtk3eScw=
golang.org/x/crypto v0.54.0/go.mod h1:KWL8ny2AZdGR2cWmzeHrp2azQPGogOv+HeQaVEXC2dk=
golang.org/x/net v0.56.0 h1:Rw8j/hFzGvJUZwNBXnAtf5sVDVt+65SK2C7IxCxZt5o=
golang.org/x/net v0.56.0/go.mod h1:D3Ku6r+V6JROoZK144D2XfMHFcMq/0zSfLelVTCFKec=
golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs=
golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
package main
import (
"bytes"
"context"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"crypto/tls"
"crypto/x509"
"crypto/x509/pkix"
"errors"
"fmt"
"math/big"
"os"
"time"
"github.com/quic-go/quic-go"
)
// Connection is a type alias for quic.Conn to demonstrate quic.Connection API semantics.
type Connection = quic.Conn
const alpn = "quic-send-datagram-demo"
func generateTLSConfig() (*tls.Config, error) {
key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
if err != nil {
return nil, fmt.Errorf("generate private key: %w", err)
}
template := x509.Certificate{
SerialNumber: big.NewInt(1),
Subject: pkix.Name{
Organization: []string{"Sample Org"},
},
NotBefore: time.Now().Add(-1 * time.Hour),
NotAfter: time.Now().Add(24 * time.Hour),
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
BasicConstraintsValid: true,
}
certDER, err := x509.CreateCertificate(rand.Reader, &template, &template, &key.PublicKey, key)
if err != nil {
return nil, fmt.Errorf("create certificate: %w", err)
}
tlsCert := tls.Certificate{
Certificate: [][]byte{certDER},
PrivateKey: key,
}
return &tls.Config{
Certificates: []tls.Certificate{tlsCert},
NextProtos: []string{alpn},
}, nil
}
func clientTLSConfig() *tls.Config {
return &tls.Config{
InsecureSkipVerify: true,
NextProtos: []string{alpn},
}
}
func main() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
serverTLS, err := generateTLSConfig()
if err != nil {
fmt.Fprintf(os.Stderr, "failed to generate TLS config: %v\n", err)
os.Exit(1)
}
listener, err := quic.ListenAddr("127.0.0.1:0", serverTLS, &quic.Config{
EnableDatagrams: true,
MaxIdleTimeout: 5 * time.Second,
})
if err != nil {
fmt.Fprintf(os.Stderr, "quic.ListenAddr failed: %v\n", err)
os.Exit(1)
}
defer listener.Close()
serverConnChan := make(chan *Connection, 1)
go func() {
conn, err := listener.Accept(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "listener.Accept failed: %v\n", err)
return
}
serverConnChan <- conn
}()
clientTLS := clientTLSConfig()
clientConn, err := quic.DialAddr(ctx, listener.Addr().String(), clientTLS, &quic.Config{
EnableDatagrams: true,
MaxIdleTimeout: 5 * time.Second,
})
if err != nil {
fmt.Fprintf(os.Stderr, "quic.DialAddr failed: %v\n", err)
os.Exit(1)
}
defer clientConn.CloseWithError(0, "client exit")
serverConn := <-serverConnChan
defer serverConn.CloseWithError(0, "server exit")
// 1. Client sends a datagram using quic.Connection.SendDatagram
clientPayload := []byte("hello from client via quic.Connection.SendDatagram")
if err := clientConn.SendDatagram(clientPayload); err != nil {
fmt.Fprintf(os.Stderr, "clientConn.SendDatagram failed: %v\n", err)
os.Exit(1)
}
fmt.Printf("Client sent datagram: %s\n", clientPayload)
// Server receives the datagram
receivedDatagram, err := serverConn.ReceiveDatagram(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "serverConn.ReceiveDatagram failed: %v\n", err)
os.Exit(1)
}
fmt.Printf("Server received datagram: %s\n", string(receivedDatagram))
if !bytes.Equal(receivedDatagram, clientPayload) {
fmt.Fprintf(os.Stderr, "datagram payload mismatch\n")
os.Exit(1)
}
// 2. Server responds with a datagram using quic.Connection.SendDatagram
serverPayload := []byte("response from server via quic.Connection.SendDatagram")
if err := serverConn.SendDatagram(serverPayload); err != nil {
fmt.Fprintf(os.Stderr, "serverConn.SendDatagram failed: %v\n", err)
os.Exit(1)
}
fmt.Printf("Server sent datagram: %s\n", serverPayload)
receivedResponse, err := clientConn.ReceiveDatagram(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "clientConn.ReceiveDatagram failed: %v\n", err)
os.Exit(1)
}
fmt.Printf("Client received datagram: %s\n", string(receivedResponse))
if !bytes.Equal(receivedResponse, serverPayload) {
fmt.Fprintf(os.Stderr, "response datagram payload mismatch\n")
os.Exit(1)
}
// 3. Demonstrate DatagramTooLargeError when sending oversized payload
oversized := make([]byte, 65536)
largeErr := clientConn.SendDatagram(oversized)
var tooLargeErr *quic.DatagramTooLargeError
if errors.As(largeErr, &tooLargeErr) {
fmt.Printf("SendDatagram correctly rejected oversized payload: max payload is %d bytes\n", tooLargeErr.MaxDatagramPayloadSize)
} else {
fmt.Fprintf(os.Stderr, "expected DatagramTooLargeError, got: %v\n", largeErr)
os.Exit(1)
}
fmt.Println("quic.Connection.SendDatagram demonstration completed successfully.")
}
{
"schemaVersion": 1,
"goal": "verify quic.Connection.SendDatagram in pkg:golang/github.com/quic-go/quic-go@v0.61.0",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/quic-go/quic-go@v0.61.0"
],
"symbols": [
"quic.Connection.SendDatagram"
]
}
package main
import (
"bytes"
"context"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"crypto/tls"
"crypto/x509"
"crypto/x509/pkix"
"errors"
"fmt"
"math/big"
"os"
"strings"
"time"
"github.com/quic-go/quic-go"
)
// Connection is a type alias for quic.Conn to demonstrate quic.Connection API semantics.
type Connection = quic.Conn
const alpn = "quic-send-datagram-contract"
func generateTLSConfig() (*tls.Config, error) {
key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
if err != nil {
return nil, fmt.Errorf("generate private key: %w", err)
}
template := x509.Certificate{
SerialNumber: big.NewInt(1),
Subject: pkix.Name{
Organization: []string{"Contract Org"},
},
NotBefore: time.Now().Add(-1 * time.Hour),
NotAfter: time.Now().Add(24 * time.Hour),
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
BasicConstraintsValid: true,
}
certDER, err := x509.CreateCertificate(rand.Reader, &template, &template, &key.PublicKey, key)
if err != nil {
return nil, fmt.Errorf("create certificate: %w", err)
}
tlsCert := tls.Certificate{
Certificate: [][]byte{certDER},
PrivateKey: key,
}
return &tls.Config{
Certificates: []tls.Certificate{tlsCert},
NextProtos: []string{alpn},
}, nil
}
func clientTLSConfig() *tls.Config {
return &tls.Config{
InsecureSkipVerify: true,
NextProtos: []string{alpn},
}
}
func main() {
if err := runContract(); err != nil {
fmt.Fprintf(os.Stderr, "Contract verification failed: %v\n", err)
os.Exit(1)
}
fmt.Println("All quic.Connection.SendDatagram contract assertions passed.")
}
func runContract() error {
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
serverTLS, err := generateTLSConfig()
if err != nil {
return fmt.Errorf("generateTLSConfig failed: %w", err)
}
// 1. Establish connection with EnableDatagrams = true
listener, err := quic.ListenAddr("127.0.0.1:0", serverTLS, &quic.Config{
EnableDatagrams: true,
MaxIdleTimeout: 5 * time.Second,
})
if err != nil {
return fmt.Errorf("quic.ListenAddr failed: %w", err)
}
defer listener.Close()
serverConnChan := make(chan *Connection, 1)
serverErrChan := make(chan error, 1)
go func() {
conn, err := listener.Accept(ctx)
if err != nil {
serverErrChan <- err
return
}
serverConnChan <- conn
}()
clientTLS := clientTLSConfig()
clientConn, err := quic.DialAddr(ctx, listener.Addr().String(), clientTLS, &quic.Config{
EnableDatagrams: true,
MaxIdleTimeout: 5 * time.Second,
})
if err != nil {
return fmt.Errorf("quic.DialAddr failed: %w", err)
}
defer clientConn.CloseWithError(0, "client finished")
var serverConn *Connection
select {
case serverConn = <-serverConnChan:
defer serverConn.CloseWithError(0, "server finished")
case err := <-serverErrChan:
return fmt.Errorf("listener.Accept failed: %w", err)
case <-ctx.Done():
return fmt.Errorf("timeout waiting for server conn: %w", ctx.Err())
}
// Assertion 1: quic.Connection.SendDatagram transmits datagram payload over an active QUIC connection with EnableDatagrams enabled
clientMsg := []byte("ping-datagram-payload")
if err := clientConn.SendDatagram(clientMsg); err != nil {
return fmt.Errorf("client SendDatagram failed: %w", err)
}
receivedAtServer, err := serverConn.ReceiveDatagram(ctx)
if err != nil {
return fmt.Errorf("server ReceiveDatagram failed: %w", err)
}
if !bytes.Equal(receivedAtServer, clientMsg) {
return fmt.Errorf("server ReceiveDatagram payload mismatch: got %q, want %q", receivedAtServer, clientMsg)
}
serverMsg := []byte("pong-datagram-response")
if err := serverConn.SendDatagram(serverMsg); err != nil {
return fmt.Errorf("server SendDatagram failed: %w", err)
}
receivedAtClient, err := clientConn.ReceiveDatagram(ctx)
if err != nil {
return fmt.Errorf("client ReceiveDatagram failed: %w", err)
}
if !bytes.Equal(receivedAtClient, serverMsg) {
return fmt.Errorf("client ReceiveDatagram payload mismatch: got %q, want %q", receivedAtClient, serverMsg)
}
// Assertion 2: quic.Connection.SendDatagram returns error when datagram support is disabled in quic.Config
disabledListener, err := quic.ListenAddr("127.0.0.1:0", serverTLS, &quic.Config{
EnableDatagrams: false,
MaxIdleTimeout: 5 * time.Second,
})
if err != nil {
return fmt.Errorf("disabled quic.ListenAddr failed: %w", err)
}
defer disabledListener.Close()
disabledServerConnChan := make(chan *Connection, 1)
go func() {
conn, err := disabledListener.Accept(ctx)
if err == nil {
disabledServerConnChan <- conn
}
}()
disabledClientConn, err := quic.DialAddr(ctx, disabledListener.Addr().String(), clientTLS, &quic.Config{
EnableDatagrams: false,
MaxIdleTimeout: 5 * time.Second,
})
if err != nil {
return fmt.Errorf("disabled quic.DialAddr failed: %w", err)
}
defer disabledClientConn.CloseWithError(0, "disabled client finished")
disabledServerConn := <-disabledServerConnChan
defer disabledServerConn.CloseWithError(0, "disabled server finished")
disabledErr := disabledClientConn.SendDatagram([]byte("disabled-test"))
if disabledErr == nil {
return fmt.Errorf("expected error for SendDatagram when datagrams disabled, got nil")
}
if !strings.Contains(disabledErr.Error(), "datagram support disabled") {
return fmt.Errorf("expected 'datagram support disabled' error, got %v", disabledErr)
}
// Assertion 3: quic.Connection.SendDatagram returns DatagramTooLargeError when datagram payload exceeds maximum payload size
oversizedPayload := make([]byte, 64*1024)
largeErr := clientConn.SendDatagram(oversizedPayload)
if largeErr == nil {
return fmt.Errorf("expected error when SendDatagram called with oversized payload, got nil")
}
var tooLargeErr *quic.DatagramTooLargeError
if !errors.As(largeErr, &tooLargeErr) {
return fmt.Errorf("expected DatagramTooLargeError, got: %T (%v)", largeErr, largeErr)
}
if tooLargeErr.MaxDatagramPayloadSize <= 0 {
return fmt.Errorf("expected MaxDatagramPayloadSize > 0, got %d", tooLargeErr.MaxDatagramPayloadSize)
}
// Assertion 4: quic.Connection.SendDatagram transmits zero-length datagram payload successfully
zeroPayload := []byte{}
if err := clientConn.SendDatagram(zeroPayload); err != nil {
return fmt.Errorf("SendDatagram with zero-length payload failed: %w", err)
}
receivedZero, err := serverConn.ReceiveDatagram(ctx)
if err != nil {
return fmt.Errorf("ReceiveDatagram for zero-length payload failed: %w", err)
}
if len(receivedZero) != 0 {
return fmt.Errorf("expected 0 bytes received for zero-length datagram, got %d bytes", len(receivedZero))
}
return nil
}
Origin Seeder
anonymous