all: clear docs, testa and Makefile (fixes #19)

This commit is contained in:
Aleksandr Razumov
2017-02-18 14:20:21 +03:00
parent af1a7982ad
commit 3d9022e65f
15 changed files with 83 additions and 35 deletions

View File

@@ -1,4 +1,4 @@
Copyright (c) 2016-2017 Aleksandr Razumov, Cydev. All Rigths Reserved.
Copyright (c) 2016-2017 Aleksandr Razumov, Cydev. All Rights Reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are

View File

@@ -39,41 +39,17 @@ escape:
@go build -gcflags '-m -l' 2>&1 \
| grep -v "<autogenerated>" \
| grep escapes
blackbox:
@TEST_EXTERNAL=1 go test -run TestClientSend -v
format:
goimports -w .
bench-compare:
go test -bench . > bench.go-16
go-tip test -bench . > bench.go-tip
@benchcmp bench.go-16 bench.go-tip
install:
go get -u sourcegraph.com/sqs/goreturns
go get -u github.com/alecthomas/gometalinter
gometalinter --install --update
go get -u github.com/cydev/go-fuzz/go-fuzz-build
go get -u github.com/dvyukov/go-fuzz/go-fuzz
push:
git push origin dev
release:
@read -p "Enter new release version: " version; \
./extras/scripts/release.sh $$version
prepare:
go get github.com/mitchellh/gox
go get github.com/tools/godep
godep restore
bindata:
go-bindata-assetfs -prefix="extras" extras/web/...
mv bindata_assetfs.go bindata.go
gofmt -w bindata.go
godep save -r ./...
package:
./extras/scripts/package.sh $(VERSION) $(ITERATION)
docker-build:
docker build -t gortc/stun .

View File

@@ -10,9 +10,52 @@ Package stun implements Session Traversal Utilities for
NAT (STUN) [RFC 5389](https://tools.ietf.org/html/rfc5389) with focus
on speed and zero allocations in hot paths, no external dependencies.
Currently in active development, API is subject to change.
# stability
Package is currently approaching beta stage, API should be fairly stable
and implementation is almost complete. Bug reports are welcome.
RFC 3489 implementation is ignored by purpose, this RFC is obselete
and can be implemented in separate package.
Additional attributes are unlikely to be implemented in scope of stun package,
the only exception is constants for attribute or message types.
Needs go 1.7 or better.
# RFC 3489 notes
RFC 5389 obseletes RFC 3489, so implementation was ignored by purpose, however,
RFC 3489 can be easily implemented as separate package.
# requirements
Go 1.8 is currently supported and tested in CI. Should work on 1.7 and tip.
# benchmarks
Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz, go 1.7:
```
benchmark iter time/iter throughput bytes alloc allocs
--------- ---- --------- ---------- ----------- ------
BenchmarkMappedAddress_AddTo-8 50000000 25.90 ns/op 0 B/op 0 allocs/op
BenchmarkAlternateServer_AddTo-8 50000000 25.90 ns/op 0 B/op 0 allocs/op
BenchmarkMessage_GetNotFound-8 200000000 6.10 ns/op 0 B/op 0 allocs/op
BenchmarkErrorCode_AddTo-8 30000000 45.10 ns/op 0 B/op 0 allocs/op
BenchmarkErrorCodeAttribute_AddTo-8 50000000 36.90 ns/op 0 B/op 0 allocs/op
BenchmarkErrorCodeAttribute_GetFrom-8 200000000 9.20 ns/op 0 B/op 0 allocs/op
BenchmarkFingerprint_AddTo-8 30000000 52.50 ns/op 1294.63 MB/s 0 B/op 0 allocs/op
BenchmarkFingerprint_Check-8 30000000 45.50 ns/op 1670.92 MB/s 0 B/op 0 allocs/op
BenchmarkMessageIntegrity_AddTo-8 2000000 884.00 ns/op 22.62 MB/s 480 B/op 6 allocs/op
BenchmarkMessageIntegrity_Check-8 2000000 982.00 ns/op 24.43 MB/s 480 B/op 6 allocs/op
BenchmarkMessage_Write-8 100000000 18.50 ns/op 1513.46 MB/s 0 B/op 0 allocs/op
BenchmarkMessageType_Value-8 2000000000 0.27 ns/op 0 B/op 0 allocs/op
BenchmarkMessage_WriteTo-8 100000000 15.40 ns/op 0 B/op 0 allocs/op
BenchmarkMessage_ReadFrom-8 100000000 22.70 ns/op 881.70 MB/s 0 B/op 0 allocs/op
BenchmarkMessage_ReadBytes-8 100000000 14.60 ns/op 1371.19 MB/s 0 B/op 0 allocs/op
BenchmarkIsMessage-8 2000000000 1.03 ns/op 19389.66 MB/s 0 B/op 0 allocs/op
BenchmarkMessage_NewTransactionID-8 1000000 1448.00 ns/op 0 B/op 0 allocs/op
BenchmarkMessageFull-8 10000000 151.00 ns/op 0 B/op 0 allocs/op
BenchmarkMessageFullHardcore-8 30000000 57.50 ns/op 0 B/op 0 allocs/op
BenchmarkMessage_WriteHeader-8 200000000 6.42 ns/op 0 B/op 0 allocs/op
BenchmarkUnknownAttributes/AddTo-8 100000000 23.00 ns/op 0 B/op 0 allocs/op
BenchmarkUnknownAttributes/GetFrom-8 100000000 16.90 ns/op 0 B/op 0 allocs/op
BenchmarkXOR-8 50000000 23.60 ns/op 43421.24 MB/s 0 B/op 0 allocs/op
BenchmarkXORSafe-8 10000000 169.00 ns/op 6048.93 MB/s 0 B/op 0 allocs/op
BenchmarkXORFast-8 100000000 23.00 ns/op 44457.23 MB/s 0 B/op 0 allocs/op
BenchmarkXORMappedAddress_AddTo-8 50000000 38.30 ns/op 0 B/op 0 allocs/op
BenchmarkXORMappedAddress_GetFrom-8 50000000 25.40 ns/op 0 B/op 0 allocs/op
```

View File

@@ -10,7 +10,8 @@ import (
//
// This attribute is used only by servers for achieving backwards
// compatibility with RFC 3489 clients.
// https://tools.ietf.org/html/rfc5389#section-15.4
//
// https://tools.ietf.org/html/rfc5389#section-15.1
type MappedAddress struct {
IP net.IP
Port int
@@ -18,7 +19,7 @@ type MappedAddress struct {
// AlternateServer represents ALTERNATE-SERVER attribute.
//
// https://tools.ietf.org/html/rfc5389#section-15.4
// https://tools.ietf.org/html/rfc5389#section-15.11
type AlternateServer struct {
IP net.IP
Port int

View File

@@ -6,6 +6,8 @@ import (
)
// ErrorCodeAttribute represents ERROR-CODE attribute.
//
// https://tools.ietf.org/html/rfc5389#section-15.6
type ErrorCodeAttribute struct {
Code ErrorCode
Reason []byte

3
examples/README.md Normal file
View File

@@ -0,0 +1,3 @@
# Fuzzer corpus
examples directory contains corpus for fuzzer.

View File

@@ -6,6 +6,8 @@ import (
)
// FingerprintAttr represents FINGERPRINT attribute.
//
// https://tools.ietf.org/html/rfc5389#section-15.5
type FingerprintAttr byte
// CRCMismatch represents CRC check error.
@@ -54,7 +56,7 @@ func (FingerprintAttr) AddTo(m *Message) error {
}
// Check reads fingerprint value from m and checks it, returning error if any.
// Can return *DecodeErr, ErrAttributeNotFound and *CRCMismatch.
// Can return *DecodeErr, ErrAttributeNotFound, and *CRCMismatch.
func (FingerprintAttr) Check(m *Message) error {
b, err := m.Get(AttrFingerprint)
if err != nil {

View File

@@ -33,6 +33,10 @@ func TestFingerprint_Check(t *testing.T) {
if err := Fingerprint.Check(m); err != nil {
t.Error(err)
}
m.Raw[3] = m.Raw[3] + 1
if err, ok := Fingerprint.Check(m).(*CRCMismatch); !ok {
t.Error(err, "should be *CRCMissmatch")
}
}
func BenchmarkFingerprint_Check(b *testing.B) {

View File

@@ -37,7 +37,7 @@ func NewLongtermIntegrity(username, realm, password string) *MessageIntegrity {
// version of MessageIntegrity is not implemented. Implementation and changes
// to it is subject to security review.
//
// https://tools.ietf.org/html/rfc5389#section-15.3
// https://tools.ietf.org/html/rfc5389#section-15.4
type MessageIntegrity struct {
Key []byte // HMAC key
}

View File

@@ -1,5 +1,11 @@
package stun
// STUN aligns attributes on 32-bit boundaries, attributes whose content
// is not a multiple of 4 bytes are padded with 1, 2, or 3 bytes of
// padding so that its value contains a multiple of 4 bytes. The
// padding bits are ignored, and may be any value.
//
// https://tools.ietf.org/html/rfc5389#section-15
const padding = 4
func nearestPaddedValueLength(l int) int {

View File

@@ -13,7 +13,7 @@ func NewRealm(nonce string) *Realm {
// Realm represents REALM attribute.
//
// https://tools.ietf.org/html/rfc5389#section-15.8
// https://tools.ietf.org/html/rfc5389#section-15.7
type Realm struct {
Raw []byte
}

View File

@@ -11,6 +11,8 @@ var ErrSoftwareTooBig = errors.New(
)
// Software is SOFTWARE attribute.
//
// https://tools.ietf.org/html/rfc5389#section-15.10
type Software struct {
Raw []byte
}

5
testdata/README.md vendored Normal file
View File

@@ -0,0 +1,5 @@
# Test data
testdata directory contains data that is used as input for tests.
Data was gathered from real world implementations of STUN in
Firefox and Chrome browsers.

View File

@@ -2,7 +2,9 @@ package stun
import "errors"
// UnknownAttributes represents UNKNOWN-ATTRIBUTES
// UnknownAttributes represents UNKNOWN-ATTRIBUTES attribute.
//
// https://tools.ietf.org/html/rfc5389#section-15.9
type UnknownAttributes struct {
Types []AttrType
}

View File

@@ -13,6 +13,8 @@ const (
)
// XORMappedAddress implements XOR-MAPPED-ADDRESS attribute.
//
// https://tools.ietf.org/html/rfc5389#section-15.2
type XORMappedAddress struct {
IP net.IP
Port int