mirror of
https://github.com/pion/stun.git
synced 2025-10-07 08:40:53 +08:00
Harmonize nolint directives
This commit is contained in:
@@ -60,7 +60,7 @@ func TestMappedAddress(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMappedAddressV6(t *testing.T) { // nolint:dupl
|
func TestMappedAddressV6(t *testing.T) { //nolint:dupl
|
||||||
m := new(Message)
|
m := new(Message)
|
||||||
addr := &MappedAddress{
|
addr := &MappedAddress{
|
||||||
IP: net.ParseIP("::"),
|
IP: net.ParseIP("::"),
|
||||||
@@ -88,7 +88,7 @@ func TestMappedAddressV6(t *testing.T) { // nolint:dupl
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAlternateServer(t *testing.T) { // nolint:dupl
|
func TestAlternateServer(t *testing.T) { //nolint:dupl
|
||||||
m := new(Message)
|
m := new(Message)
|
||||||
addr := &AlternateServer{
|
addr := &AlternateServer{
|
||||||
IP: net.ParseIP("122.12.34.5"),
|
IP: net.ParseIP("122.12.34.5"),
|
||||||
@@ -116,7 +116,7 @@ func TestAlternateServer(t *testing.T) { // nolint:dupl
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOtherAddress(t *testing.T) { // nolint:dupl
|
func TestOtherAddress(t *testing.T) { //nolint:dupl
|
||||||
m := new(Message)
|
m := new(Message)
|
||||||
addr := &OtherAddress{
|
addr := &OtherAddress{
|
||||||
IP: net.ParseIP("122.12.34.5"),
|
IP: net.ParseIP("122.12.34.5"),
|
||||||
|
@@ -130,7 +130,7 @@ func TestAgent_GC(t *testing.T) {
|
|||||||
)
|
)
|
||||||
gcDeadline := deadline.Add(-time.Second)
|
gcDeadline := deadline.Add(-time.Second)
|
||||||
deadlineNotGC := gcDeadline.AddDate(0, 0, -1)
|
deadlineNotGC := gcDeadline.AddDate(0, 0, -1)
|
||||||
a.SetHandler(func(e Event) { // nolint:errcheck,gosec
|
a.SetHandler(func(e Event) { //nolint:errcheck,gosec
|
||||||
id := e.TransactionID
|
id := e.TransactionID
|
||||||
shouldTimeOut, found := shouldTimeOutID[id]
|
shouldTimeOut, found := shouldTimeOutID[id]
|
||||||
if !found {
|
if !found {
|
||||||
|
@@ -9,7 +9,7 @@ func BenchmarkMessage_GetNotFound(b *testing.B) {
|
|||||||
m := New()
|
m := New()
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
m.Get(AttrRealm) // nolint:errcheck,gosec
|
m.Get(AttrRealm) //nolint:errcheck,gosec
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ func BenchmarkMessage_Get(b *testing.B) {
|
|||||||
m.Add(AttrUsername, []byte{1, 2, 3, 4, 5, 6, 7})
|
m.Add(AttrUsername, []byte{1, 2, 3, 4, 5, 6, 7})
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
m.Get(AttrUsername) // nolint:errcheck,gosec
|
m.Get(AttrUsername) //nolint:errcheck,gosec
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,12 +42,12 @@ func TestRawAttribute_AddTo(t *testing.T) {
|
|||||||
|
|
||||||
func TestMessage_GetNoAllocs(t *testing.T) {
|
func TestMessage_GetNoAllocs(t *testing.T) {
|
||||||
m := New()
|
m := New()
|
||||||
NewSoftware("c").AddTo(m) // nolint:errcheck,gosec
|
NewSoftware("c").AddTo(m) //nolint:errcheck,gosec
|
||||||
m.WriteHeader()
|
m.WriteHeader()
|
||||||
|
|
||||||
t.Run("Default", func(t *testing.T) {
|
t.Run("Default", func(t *testing.T) {
|
||||||
allocs := testing.AllocsPerRun(10, func() {
|
allocs := testing.AllocsPerRun(10, func() {
|
||||||
m.Get(AttrSoftware) // nolint:errcheck,gosec
|
m.Get(AttrSoftware) //nolint:errcheck,gosec
|
||||||
})
|
})
|
||||||
if allocs > 0 {
|
if allocs > 0 {
|
||||||
t.Error("allocated memory, but should not")
|
t.Error("allocated memory, but should not")
|
||||||
@@ -55,7 +55,7 @@ func TestMessage_GetNoAllocs(t *testing.T) {
|
|||||||
})
|
})
|
||||||
t.Run("Not found", func(t *testing.T) {
|
t.Run("Not found", func(t *testing.T) {
|
||||||
allocs := testing.AllocsPerRun(10, func() {
|
allocs := testing.AllocsPerRun(10, func() {
|
||||||
m.Get(AttrOrigin) // nolint:errcheck,gosec
|
m.Get(AttrOrigin) //nolint:errcheck,gosec
|
||||||
})
|
})
|
||||||
if allocs > 0 {
|
if allocs > 0 {
|
||||||
t.Error("allocated memory, but should not")
|
t.Error("allocated memory, but should not")
|
||||||
|
20
client.go
20
client.go
@@ -227,7 +227,7 @@ func (t *clientTransaction) handle(e Event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var clientTransactionPool = &sync.Pool{ // nolint:gochecknoglobals
|
var clientTransactionPool = &sync.Pool{ //nolint:gochecknoglobals
|
||||||
New: func() interface{} {
|
New: func() interface{} {
|
||||||
return &clientTransaction{
|
return &clientTransaction{
|
||||||
raw: make([]byte, 1500),
|
raw: make([]byte, 1500),
|
||||||
@@ -288,7 +288,8 @@ func (c *Client) SetRTO(rto time.Duration) {
|
|||||||
|
|
||||||
// StopErr occurs when Client fails to stop transaction while
|
// StopErr occurs when Client fails to stop transaction while
|
||||||
// processing error.
|
// processing error.
|
||||||
// nolint:errname
|
//
|
||||||
|
//nolint:errname
|
||||||
type StopErr struct {
|
type StopErr struct {
|
||||||
Err error // value returned by Stop()
|
Err error // value returned by Stop()
|
||||||
Cause error // error that caused Stop() call
|
Cause error // error that caused Stop() call
|
||||||
@@ -299,7 +300,8 @@ func (e StopErr) Error() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CloseErr indicates client close failure.
|
// CloseErr indicates client close failure.
|
||||||
// nolint:errname
|
//
|
||||||
|
//nolint:errname
|
||||||
type CloseErr struct {
|
type CloseErr struct {
|
||||||
AgentErr error
|
AgentErr error
|
||||||
ConnectionErr error
|
ConnectionErr error
|
||||||
@@ -307,7 +309,7 @@ type CloseErr struct {
|
|||||||
|
|
||||||
func sprintErr(err error) string {
|
func sprintErr(err error) string {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return "<nil>" // nolint:goconst
|
return "<nil>" //nolint:goconst
|
||||||
}
|
}
|
||||||
return err.Error()
|
return err.Error()
|
||||||
}
|
}
|
||||||
@@ -339,7 +341,7 @@ func closedOrPanic(err error) {
|
|||||||
if err == nil || errors.Is(err, ErrAgentClosed) {
|
if err == nil || errors.Is(err, ErrAgentClosed) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
panic(err) // nolint
|
panic(err) //nolint
|
||||||
}
|
}
|
||||||
|
|
||||||
type tickerCollector struct {
|
type tickerCollector struct {
|
||||||
@@ -431,7 +433,7 @@ type callbackWaitHandler struct {
|
|||||||
func (s *callbackWaitHandler) HandleEvent(e Event) {
|
func (s *callbackWaitHandler) HandleEvent(e Event) {
|
||||||
s.cond.L.Lock()
|
s.cond.L.Lock()
|
||||||
if s.callback == nil {
|
if s.callback == nil {
|
||||||
panic("s.callback is nil") // nolint
|
panic("s.callback is nil") //nolint
|
||||||
}
|
}
|
||||||
s.callback(e)
|
s.callback(e)
|
||||||
s.processed = true
|
s.processed = true
|
||||||
@@ -451,7 +453,7 @@ func (s *callbackWaitHandler) wait() {
|
|||||||
|
|
||||||
func (s *callbackWaitHandler) setCallback(f func(event Event)) {
|
func (s *callbackWaitHandler) setCallback(f func(event Event)) {
|
||||||
if f == nil {
|
if f == nil {
|
||||||
panic("f is nil") // nolint
|
panic("f is nil") //nolint
|
||||||
}
|
}
|
||||||
s.cond.L.Lock()
|
s.cond.L.Lock()
|
||||||
s.callback = f
|
s.callback = f
|
||||||
@@ -461,7 +463,7 @@ func (s *callbackWaitHandler) setCallback(f func(event Event)) {
|
|||||||
s.cond.L.Unlock()
|
s.cond.L.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
var callbackWaitHandlerPool = sync.Pool{ // nolint:gochecknoglobals
|
var callbackWaitHandlerPool = sync.Pool{ //nolint:gochecknoglobals
|
||||||
New: func() interface{} {
|
New: func() interface{} {
|
||||||
return &callbackWaitHandler{
|
return &callbackWaitHandler{
|
||||||
cond: sync.NewCond(new(sync.Mutex)),
|
cond: sync.NewCond(new(sync.Mutex)),
|
||||||
@@ -515,7 +517,7 @@ type buffer struct {
|
|||||||
buf []byte
|
buf []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
var bufferPool = &sync.Pool{ // nolint:gochecknoglobals
|
var bufferPool = &sync.Pool{ //nolint:gochecknoglobals
|
||||||
New: func() interface{} {
|
New: func() interface{} {
|
||||||
return &buffer{buf: make([]byte, 2048)}
|
return &buffer{buf: make([]byte, 2048)}
|
||||||
},
|
},
|
||||||
|
@@ -100,7 +100,7 @@ func BenchmarkClient_Do(b *testing.B) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
m := New()
|
m := New()
|
||||||
m.NewTransactionID() // nolint:errcheck,gosec
|
m.NewTransactionID() //nolint:errcheck,gosec
|
||||||
m.Encode()
|
m.Encode()
|
||||||
for pb.Next() {
|
for pb.Next() {
|
||||||
if err := client.Do(m, noopF); err != nil {
|
if err := client.Do(m, noopF); err != nil {
|
||||||
@@ -1479,7 +1479,7 @@ func TestClientImmediateTimeout(t *testing.T) {
|
|||||||
}
|
}
|
||||||
gotReads <- struct{}{}
|
gotReads <- struct{}{}
|
||||||
}()
|
}()
|
||||||
c.Start(MustBuild(response, BindingRequest), func(e Event) { // nolint:errcheck,gosec
|
c.Start(MustBuild(response, BindingRequest), func(e Event) { //nolint:errcheck,gosec
|
||||||
if errors.Is(e.Error, ErrTransactionTimeOut) {
|
if errors.Is(e.Error, ErrTransactionTimeOut) {
|
||||||
t.Error("unexpected error")
|
t.Error("unexpected error")
|
||||||
}
|
}
|
||||||
|
@@ -21,17 +21,17 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
workers = flag.Int("w", runtime.GOMAXPROCS(0), "concurrent workers") // nolint:gochecknoglobals
|
workers = flag.Int("w", runtime.GOMAXPROCS(0), "concurrent workers") //nolint:gochecknoglobals
|
||||||
addr = flag.String("addr", "localhost", "target address") // nolint:gochecknoglobals
|
addr = flag.String("addr", "localhost", "target address") //nolint:gochecknoglobals
|
||||||
port = flag.Int("port", stun.DefaultPort, "target port") // nolint:gochecknoglobals
|
port = flag.Int("port", stun.DefaultPort, "target port") //nolint:gochecknoglobals
|
||||||
duration = flag.Duration("d", time.Minute, "benchmark duration") // nolint:gochecknoglobals
|
duration = flag.Duration("d", time.Minute, "benchmark duration") //nolint:gochecknoglobals
|
||||||
network = flag.String("net", "udp", "protocol to use (udp, tcp)") // nolint:gochecknoglobals
|
network = flag.String("net", "udp", "protocol to use (udp, tcp)") //nolint:gochecknoglobals
|
||||||
cpuProfile = flag.String("cpuprofile", "", "file output of pprof cpu profile") // nolint:gochecknoglobals
|
cpuProfile = flag.String("cpuprofile", "", "file output of pprof cpu profile") //nolint:gochecknoglobals
|
||||||
memProfile = flag.String("memprofile", "", "file output of pprof memory profile") // nolint:gochecknoglobals
|
memProfile = flag.String("memprofile", "", "file output of pprof memory profile") //nolint:gochecknoglobals
|
||||||
realRand = flag.Bool("crypt", false, "use crypto/rand as random source") // nolint:gochecknoglobals
|
realRand = flag.Bool("crypt", false, "use crypto/rand as random source") //nolint:gochecknoglobals
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() { // nolint:gocognit
|
func main() { //nolint:gocognit
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
signals := make(chan os.Signal, 1)
|
signals := make(chan os.Signal, 1)
|
||||||
signal.Notify(signals, os.Interrupt)
|
signal.Notify(signals, os.Interrupt)
|
||||||
@@ -101,7 +101,7 @@ func main() { // nolint:gocognit
|
|||||||
log.Fatal("rand.Read failed:", err)
|
log.Fatal("rand.Read failed:", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mathRand.Read(req.TransactionID[:]) // nolint:gosec
|
mathRand.Read(req.TransactionID[:]) //nolint:gosec
|
||||||
}
|
}
|
||||||
req.Type = stun.BindingRequest
|
req.Type = stun.BindingRequest
|
||||||
req.WriteHeader()
|
req.WriteHeader()
|
||||||
|
@@ -78,7 +78,7 @@ func multiplex(conn *net.UDPConn, stunAddr net.Addr, stunConn io.Reader) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var stunServer = flag.String("stun", "stun.l.google.com:19302", "STUN Server to use") // nolint:gochecknoglobals
|
var stunServer = flag.String("stun", "stun.l.google.com:19302", "STUN Server to use") //nolint:gochecknoglobals
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
@@ -27,10 +27,10 @@ func (c *stunServerConn) Close() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
addrStrPtr = flag.String("server", "stun.voip.blackberry.com:3478", "STUN server address") // nolint:gochecknoglobals
|
addrStrPtr = flag.String("server", "stun.voip.blackberry.com:3478", "STUN server address") //nolint:gochecknoglobals
|
||||||
timeoutPtr = flag.Int("timeout", 3, "the number of seconds to wait for STUN server's response") // nolint:gochecknoglobals
|
timeoutPtr = flag.Int("timeout", 3, "the number of seconds to wait for STUN server's response") //nolint:gochecknoglobals
|
||||||
verbose = flag.Int("verbose", 1, "the verbosity level") // nolint:gochecknoglobals
|
verbose = flag.Int("verbose", 1, "the verbosity level") //nolint:gochecknoglobals
|
||||||
log logging.LeveledLogger // nolint:gochecknoglobals
|
log logging.LeveledLogger //nolint:gochecknoglobals
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -241,7 +241,7 @@ func parse(msg *stun.Message) (ret struct {
|
|||||||
stun.AttrResponseOrigin,
|
stun.AttrResponseOrigin,
|
||||||
stun.AttrMappedAddress,
|
stun.AttrMappedAddress,
|
||||||
stun.AttrSoftware:
|
stun.AttrSoftware:
|
||||||
break //nolint: staticcheck
|
break //nolint:staticcheck
|
||||||
default:
|
default:
|
||||||
log.Debugf("\t%v (l=%v)", attr, attr.Length)
|
log.Debugf("\t%v (l=%v)", attr, attr.Length)
|
||||||
}
|
}
|
||||||
|
@@ -14,7 +14,7 @@ import (
|
|||||||
"github.com/pion/stun"
|
"github.com/pion/stun"
|
||||||
)
|
)
|
||||||
|
|
||||||
var server = flag.String("server", "pion.ly:3478", "Stun server address") // nolint:gochecknoglobals
|
var server = flag.String("server", "pion.ly:3478", "Stun server address") //nolint:gochecknoglobals
|
||||||
|
|
||||||
const (
|
const (
|
||||||
udp = "udp4"
|
udp = "udp4"
|
||||||
@@ -23,7 +23,7 @@ const (
|
|||||||
timeoutMillis = 500
|
timeoutMillis = 500
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() { // nolint:gocognit
|
func main() { //nolint:gocognit
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
srvAddr, err := net.ResolveUDPAddr(udp, *server)
|
srvAddr, err := net.ResolveUDPAddr(udp, *server)
|
||||||
|
48
e2e/main.go
48
e2e/main.go
@@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
func test(network string) {
|
func test(network string) {
|
||||||
addr := resolve(network)
|
addr := resolve(network)
|
||||||
fmt.Println("START", strings.ToUpper(addr.Network())) // nolint
|
fmt.Println("START", strings.ToUpper(addr.Network())) //nolint
|
||||||
var (
|
var (
|
||||||
nonce stun.Nonce
|
nonce stun.Nonce
|
||||||
realm stun.Realm
|
realm stun.Realm
|
||||||
@@ -24,44 +24,44 @@ func test(network string) {
|
|||||||
)
|
)
|
||||||
conn, err := net.Dial(addr.Network(), addr.String())
|
conn, err := net.Dial(addr.Network(), addr.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln("failed to dial conn:", err) // nolint
|
log.Fatalln("failed to dial conn:", err) //nolint
|
||||||
}
|
}
|
||||||
var options []stun.ClientOption
|
var options []stun.ClientOption
|
||||||
if network == "tcp" {
|
if network == "tcp" {
|
||||||
// Switching to "NO-RTO" mode.
|
// Switching to "NO-RTO" mode.
|
||||||
fmt.Println("using WithNoRetransmit for TCP") // nolint
|
fmt.Println("using WithNoRetransmit for TCP") //nolint
|
||||||
options = append(options, stun.WithNoRetransmit)
|
options = append(options, stun.WithNoRetransmit)
|
||||||
}
|
}
|
||||||
client, err := stun.NewClient(conn, options...)
|
client, err := stun.NewClient(conn, options...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err) // nolint
|
log.Fatal(err) //nolint
|
||||||
}
|
}
|
||||||
// First request should error.
|
// First request should error.
|
||||||
request, err := stun.Build(stun.BindingRequest, stun.TransactionID, stun.Fingerprint)
|
request, err := stun.Build(stun.BindingRequest, stun.TransactionID, stun.Fingerprint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln("failed to build:", err) // nolint
|
log.Fatalln("failed to build:", err) //nolint
|
||||||
}
|
}
|
||||||
if err = client.Do(request, func(event stun.Event) {
|
if err = client.Do(request, func(event stun.Event) {
|
||||||
if event.Error != nil {
|
if event.Error != nil {
|
||||||
log.Fatalln("got event with error:", event.Error) // nolint
|
log.Fatalln("got event with error:", event.Error) //nolint
|
||||||
}
|
}
|
||||||
response := event.Message
|
response := event.Message
|
||||||
if response.Type != stun.BindingError {
|
if response.Type != stun.BindingError {
|
||||||
log.Fatalln("bad message", response) // nolint
|
log.Fatalln("bad message", response) //nolint
|
||||||
}
|
}
|
||||||
var errCode stun.ErrorCodeAttribute
|
var errCode stun.ErrorCodeAttribute
|
||||||
if codeErr := errCode.GetFrom(response); codeErr != nil {
|
if codeErr := errCode.GetFrom(response); codeErr != nil {
|
||||||
log.Fatalln("failed to get error code:", codeErr) // nolint
|
log.Fatalln("failed to get error code:", codeErr) //nolint
|
||||||
}
|
}
|
||||||
if errCode.Code != stun.CodeUnauthorized {
|
if errCode.Code != stun.CodeUnauthorized {
|
||||||
log.Fatalln("unexpected error code:", errCode) // nolint
|
log.Fatalln("unexpected error code:", errCode) //nolint
|
||||||
}
|
}
|
||||||
if parseErr := response.Parse(&nonce, &realm); parseErr != nil {
|
if parseErr := response.Parse(&nonce, &realm); parseErr != nil {
|
||||||
log.Fatalln("failed to parse:", parseErr) // nolint
|
log.Fatalln("failed to parse:", parseErr) //nolint
|
||||||
}
|
}
|
||||||
fmt.Println("Got nonce", nonce, "and realm", realm) // nolint
|
fmt.Println("Got nonce", nonce, "and realm", realm) //nolint
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
log.Fatalln("failed to Do:", err) // nolint
|
log.Fatalln("failed to Do:", err) //nolint
|
||||||
}
|
}
|
||||||
|
|
||||||
// Authenticating and sending second request.
|
// Authenticating and sending second request.
|
||||||
@@ -71,35 +71,35 @@ func test(network string) {
|
|||||||
stun.Fingerprint,
|
stun.Fingerprint,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err) // nolint
|
log.Fatalln(err) //nolint
|
||||||
}
|
}
|
||||||
if err = client.Do(request, func(event stun.Event) {
|
if err = client.Do(request, func(event stun.Event) {
|
||||||
if event.Error != nil {
|
if event.Error != nil {
|
||||||
log.Fatalln("got event with error:", event.Error) // nolint
|
log.Fatalln("got event with error:", event.Error) //nolint
|
||||||
}
|
}
|
||||||
response := event.Message
|
response := event.Message
|
||||||
if response.Type != stun.BindingSuccess {
|
if response.Type != stun.BindingSuccess {
|
||||||
var errCode stun.ErrorCodeAttribute
|
var errCode stun.ErrorCodeAttribute
|
||||||
if codeErr := errCode.GetFrom(response); codeErr != nil {
|
if codeErr := errCode.GetFrom(response); codeErr != nil {
|
||||||
log.Fatalln("failed to get error code:", codeErr) // nolint
|
log.Fatalln("failed to get error code:", codeErr) //nolint
|
||||||
}
|
}
|
||||||
log.Fatalln("bad message", response, errCode) // nolint
|
log.Fatalln("bad message", response, errCode) //nolint
|
||||||
}
|
}
|
||||||
var xorMapped stun.XORMappedAddress
|
var xorMapped stun.XORMappedAddress
|
||||||
if err = response.Parse(&xorMapped); err != nil {
|
if err = response.Parse(&xorMapped); err != nil {
|
||||||
log.Fatalln("failed to parse xor mapped address:", err) // nolint
|
log.Fatalln("failed to parse xor mapped address:", err) //nolint
|
||||||
}
|
}
|
||||||
if conn.LocalAddr().String() != xorMapped.String() {
|
if conn.LocalAddr().String() != xorMapped.String() {
|
||||||
log.Fatalln(conn.LocalAddr(), "!=", xorMapped) // nolint
|
log.Fatalln(conn.LocalAddr(), "!=", xorMapped) //nolint
|
||||||
}
|
}
|
||||||
fmt.Println("OK", response, "GOT", xorMapped) // nolint
|
fmt.Println("OK", response, "GOT", xorMapped) //nolint
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
log.Fatalln("failed to Do:", err) // nolint
|
log.Fatalln("failed to Do:", err) //nolint
|
||||||
}
|
}
|
||||||
if err := client.Close(); err != nil {
|
if err := client.Close(); err != nil {
|
||||||
log.Fatalln("failed to close client:", err) // nolint
|
log.Fatalln("failed to close client:", err) //nolint
|
||||||
}
|
}
|
||||||
fmt.Println("OK", strings.ToUpper(addr.Network())) // nolint
|
fmt.Println("OK", strings.ToUpper(addr.Network())) //nolint
|
||||||
}
|
}
|
||||||
|
|
||||||
func resolve(network string) net.Addr {
|
func resolve(network string) net.Addr {
|
||||||
@@ -115,14 +115,14 @@ func resolve(network string) net.Addr {
|
|||||||
case "tcp":
|
case "tcp":
|
||||||
resolved, resolveErr = net.ResolveTCPAddr("tcp", addr)
|
resolved, resolveErr = net.ResolveTCPAddr("tcp", addr)
|
||||||
default:
|
default:
|
||||||
panic("unknown network") // nolint
|
panic("unknown network") //nolint
|
||||||
}
|
}
|
||||||
if resolveErr == nil {
|
if resolveErr == nil {
|
||||||
return resolved
|
return resolved
|
||||||
}
|
}
|
||||||
time.Sleep(time.Millisecond * 300 * time.Duration(i))
|
time.Sleep(time.Millisecond * 300 * time.Duration(i))
|
||||||
}
|
}
|
||||||
panic(resolveErr) // nolint
|
panic(resolveErr) //nolint
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@@ -131,6 +131,7 @@ const (
|
|||||||
CodePeerAddrFamilyMismatch ErrorCode = 443 // Peer Address Family Mismatch
|
CodePeerAddrFamilyMismatch ErrorCode = 443 // Peer Address Family Mismatch
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//nolint:gocheckglobals
|
||||||
var errorReasons = map[ErrorCode][]byte{
|
var errorReasons = map[ErrorCode][]byte{
|
||||||
CodeTryAlternate: []byte("Try Alternate"),
|
CodeTryAlternate: []byte("Try Alternate"),
|
||||||
CodeBadRequest: []byte("Bad Request"),
|
CodeBadRequest: []byte("Bad Request"),
|
||||||
|
@@ -14,7 +14,7 @@ func BenchmarkErrorCode_AddTo(b *testing.B) {
|
|||||||
m := New()
|
m := New()
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
CodeStaleNonce.AddTo(m) // nolint:errcheck,gosec
|
CodeStaleNonce.AddTo(m) //nolint:errcheck,gosec
|
||||||
m.Reset()
|
m.Reset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -27,7 +27,7 @@ func BenchmarkErrorCodeAttribute_AddTo(b *testing.B) {
|
|||||||
Reason: []byte("not found!"),
|
Reason: []byte("not found!"),
|
||||||
}
|
}
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
a.AddTo(m) // nolint:errcheck,gosec
|
a.AddTo(m) //nolint:errcheck,gosec
|
||||||
m.Reset()
|
m.Reset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,9 +39,9 @@ func BenchmarkErrorCodeAttribute_GetFrom(b *testing.B) {
|
|||||||
Code: 404,
|
Code: 404,
|
||||||
Reason: []byte("not found!"),
|
Reason: []byte("not found!"),
|
||||||
}
|
}
|
||||||
a.AddTo(m) // nolint:errcheck,gosec
|
a.AddTo(m) //nolint:errcheck,gosec
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
a.GetFrom(m) // nolint:errcheck,gosec
|
a.GetFrom(m) //nolint:errcheck,gosec
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ func TestMessage_AddErrorCode(t *testing.T) {
|
|||||||
copy(m.TransactionID[:], transactionID)
|
copy(m.TransactionID[:], transactionID)
|
||||||
expectedCode := ErrorCode(438)
|
expectedCode := ErrorCode(438)
|
||||||
expectedReason := "Stale Nonce"
|
expectedReason := "Stale Nonce"
|
||||||
CodeStaleNonce.AddTo(m) // nolint:errcheck,gosec
|
CodeStaleNonce.AddTo(m) //nolint:errcheck,gosec
|
||||||
m.WriteHeader()
|
m.WriteHeader()
|
||||||
|
|
||||||
mRes := New()
|
mRes := New()
|
||||||
|
@@ -3,7 +3,8 @@ package stun
|
|||||||
import "errors"
|
import "errors"
|
||||||
|
|
||||||
// DecodeErr records an error and place when it is occurred.
|
// DecodeErr records an error and place when it is occurred.
|
||||||
// nolint:errname
|
//
|
||||||
|
//nolint:errname
|
||||||
type DecodeErr struct {
|
type DecodeErr struct {
|
||||||
Place DecodeErrPlace
|
Place DecodeErrPlace
|
||||||
Message string
|
Message string
|
||||||
|
@@ -19,10 +19,10 @@ var ErrFingerprintMismatch = errors.New("fingerprint check failed")
|
|||||||
//
|
//
|
||||||
// m := New()
|
// m := New()
|
||||||
// Fingerprint.AddTo(m)
|
// Fingerprint.AddTo(m)
|
||||||
var Fingerprint FingerprintAttr // nolint:gochecknoglobals
|
var Fingerprint FingerprintAttr //nolint:gochecknoglobals
|
||||||
|
|
||||||
const (
|
const (
|
||||||
fingerprintXORValue uint32 = 0x5354554e // nolint:staticcheck
|
fingerprintXORValue uint32 = 0x5354554e //nolint:staticcheck
|
||||||
fingerprintSize = 4 // 32 bit
|
fingerprintSize = 4 // 32 bit
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -19,7 +19,7 @@ func BenchmarkFingerprint_AddTo(b *testing.B) {
|
|||||||
addAttr(b, m, s)
|
addAttr(b, m, s)
|
||||||
b.SetBytes(int64(len(m.Raw)))
|
b.SetBytes(int64(len(m.Raw)))
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
Fingerprint.AddTo(m) // nolint:errcheck,gosec
|
Fingerprint.AddTo(m) //nolint:errcheck,gosec
|
||||||
m.WriteLength()
|
m.WriteLength()
|
||||||
m.Length -= attributeHeaderSize + fingerprintSize
|
m.Length -= attributeHeaderSize + fingerprintSize
|
||||||
m.Raw = m.Raw[:m.Length+messageHeaderSize]
|
m.Raw = m.Raw[:m.Length+messageHeaderSize]
|
||||||
@@ -31,7 +31,7 @@ func TestFingerprint_Check(t *testing.T) {
|
|||||||
m := new(Message)
|
m := new(Message)
|
||||||
addAttr(t, m, NewSoftware("software"))
|
addAttr(t, m, NewSoftware("software"))
|
||||||
m.WriteHeader()
|
m.WriteHeader()
|
||||||
Fingerprint.AddTo(m) // nolint:errcheck,gosec
|
Fingerprint.AddTo(m) //nolint:errcheck,gosec
|
||||||
m.WriteHeader()
|
m.WriteHeader()
|
||||||
if err := Fingerprint.Check(m); err != nil {
|
if err := Fingerprint.Check(m); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
@@ -65,7 +65,7 @@ func BenchmarkFingerprint_Check(b *testing.B) {
|
|||||||
addAttr(b, m, addr)
|
addAttr(b, m, addr)
|
||||||
addAttr(b, m, s)
|
addAttr(b, m, s)
|
||||||
m.WriteHeader()
|
m.WriteHeader()
|
||||||
Fingerprint.AddTo(m) // nolint:errcheck,gosec
|
Fingerprint.AddTo(m) //nolint:errcheck,gosec
|
||||||
m.WriteHeader()
|
m.WriteHeader()
|
||||||
b.SetBytes(int64(len(m.Raw)))
|
b.SetBytes(int64(len(m.Raw)))
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
|
@@ -68,7 +68,7 @@ func (m *Message) Parse(getters ...Getter) error {
|
|||||||
func MustBuild(setters ...Setter) *Message {
|
func MustBuild(setters ...Setter) *Message {
|
||||||
m, err := Build(setters...)
|
m, err := Build(setters...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err) // nolint
|
panic(err) //nolint
|
||||||
}
|
}
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
@@ -19,14 +19,14 @@ func BenchmarkBuildOverhead(b *testing.B) {
|
|||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
m := new(Message)
|
m := new(Message)
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
m.Build(&t, &username, &nonce, &realm, &Fingerprint) // nolint:errcheck,gosec
|
m.Build(&t, &username, &nonce, &realm, &Fingerprint) //nolint:errcheck,gosec
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
b.Run("BuildNonPointer", func(b *testing.B) {
|
b.Run("BuildNonPointer", func(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
m := new(Message)
|
m := new(Message)
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
m.Build(t, username, nonce, realm, Fingerprint) // nolint:errcheck,gosec // nolint:errcheck,gosec
|
m.Build(t, username, nonce, realm, Fingerprint) //nolint:errcheck,gosec //nolint:errcheck,gosec
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
b.Run("Raw", func(b *testing.B) {
|
b.Run("Raw", func(b *testing.B) {
|
||||||
@@ -36,10 +36,10 @@ func BenchmarkBuildOverhead(b *testing.B) {
|
|||||||
m.Reset()
|
m.Reset()
|
||||||
m.WriteHeader()
|
m.WriteHeader()
|
||||||
m.SetType(t)
|
m.SetType(t)
|
||||||
username.AddTo(m) // nolint:errcheck,gosec
|
username.AddTo(m) //nolint:errcheck,gosec
|
||||||
nonce.AddTo(m) // nolint:errcheck,gosec
|
nonce.AddTo(m) //nolint:errcheck,gosec
|
||||||
realm.AddTo(m) // nolint:errcheck,gosec
|
realm.AddTo(m) //nolint:errcheck,gosec
|
||||||
Fingerprint.AddTo(m) // nolint:errcheck,gosec
|
Fingerprint.AddTo(m) //nolint:errcheck,gosec
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
package stun
|
package stun
|
||||||
|
|
||||||
import ( // nolint:gci
|
import ( //nolint:gci
|
||||||
"crypto/md5" // nolint:gosec
|
"crypto/md5" //nolint:gosec
|
||||||
"crypto/sha1" // nolint:gosec
|
"crypto/sha1" //nolint:gosec
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -17,7 +17,7 @@ const credentialsSep = ":"
|
|||||||
// credentials. Password, username, and realm must be SASL-prepared.
|
// credentials. Password, username, and realm must be SASL-prepared.
|
||||||
func NewLongTermIntegrity(username, realm, password string) MessageIntegrity {
|
func NewLongTermIntegrity(username, realm, password string) MessageIntegrity {
|
||||||
k := strings.Join([]string{username, realm, password}, credentialsSep)
|
k := strings.Join([]string{username, realm, password}, credentialsSep)
|
||||||
h := md5.New() // nolint:gosec
|
h := md5.New() //nolint:gosec
|
||||||
fmt.Fprint(h, k)
|
fmt.Fprint(h, k)
|
||||||
return MessageIntegrity(h.Sum(nil))
|
return MessageIntegrity(h.Sum(nil))
|
||||||
}
|
}
|
||||||
|
@@ -21,7 +21,7 @@ func TestMessageIntegrity_AddTo_Simple(t *testing.T) {
|
|||||||
if err := i.AddTo(m); err != nil {
|
if err := i.AddTo(m); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
NewSoftware("software").AddTo(m) // nolint:errcheck,gosec
|
NewSoftware("software").AddTo(m) //nolint:errcheck,gosec
|
||||||
m.WriteHeader()
|
m.WriteHeader()
|
||||||
dM := new(Message)
|
dM := new(Message)
|
||||||
dM.Raw = m.Raw
|
dM.Raw = m.Raw
|
||||||
@@ -42,7 +42,7 @@ func TestMessageIntegrityWithFingerprint(t *testing.T) {
|
|||||||
m := new(Message)
|
m := new(Message)
|
||||||
m.TransactionID = [TransactionIDSize]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
|
m.TransactionID = [TransactionIDSize]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
|
||||||
m.WriteHeader()
|
m.WriteHeader()
|
||||||
NewSoftware("software").AddTo(m) // nolint:errcheck,gosec
|
NewSoftware("software").AddTo(m) //nolint:errcheck,gosec
|
||||||
i := NewShortTermIntegrity("pwd")
|
i := NewShortTermIntegrity("pwd")
|
||||||
if i.String() != "KEY: 0x707764" {
|
if i.String() != "KEY: 0x707764" {
|
||||||
t.Error("bad string", i)
|
t.Error("bad string", i)
|
||||||
@@ -81,7 +81,7 @@ func TestMessageIntegrity(t *testing.T) {
|
|||||||
func TestMessageIntegrityBeforeFingerprint(t *testing.T) {
|
func TestMessageIntegrityBeforeFingerprint(t *testing.T) {
|
||||||
m := new(Message)
|
m := new(Message)
|
||||||
m.WriteHeader()
|
m.WriteHeader()
|
||||||
Fingerprint.AddTo(m) // nolint:errcheck,gosec
|
Fingerprint.AddTo(m) //nolint:errcheck,gosec
|
||||||
i := NewShortTermIntegrity("password")
|
i := NewShortTermIntegrity("password")
|
||||||
if err := i.AddTo(m); err == nil {
|
if err := i.AddTo(m); err == nil {
|
||||||
t.Error("should error")
|
t.Error("should error")
|
||||||
@@ -106,7 +106,7 @@ func BenchmarkMessageIntegrity_AddTo(b *testing.B) {
|
|||||||
func BenchmarkMessageIntegrity_Check(b *testing.B) {
|
func BenchmarkMessageIntegrity_Check(b *testing.B) {
|
||||||
m := new(Message)
|
m := new(Message)
|
||||||
m.Raw = make([]byte, 0, 1024)
|
m.Raw = make([]byte, 0, 1024)
|
||||||
NewSoftware("software").AddTo(m) // nolint:errcheck,gosec
|
NewSoftware("software").AddTo(m) //nolint:errcheck,gosec
|
||||||
integrity := NewShortTermIntegrity("password")
|
integrity := NewShortTermIntegrity("password")
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
m.WriteHeader()
|
m.WriteHeader()
|
||||||
|
@@ -58,13 +58,13 @@ func (h *hmac) Sum(in []byte) []byte {
|
|||||||
|
|
||||||
if h.marshaled {
|
if h.marshaled {
|
||||||
if err := h.outer.(marshalable).UnmarshalBinary(h.opad); err != nil { //nolint:forcetypeassert
|
if err := h.outer.(marshalable).UnmarshalBinary(h.opad); err != nil { //nolint:forcetypeassert
|
||||||
panic(err) // nolint
|
panic(err) //nolint
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
h.outer.Reset()
|
h.outer.Reset()
|
||||||
h.outer.Write(h.opad) //nolint: errcheck,gosec
|
h.outer.Write(h.opad) //nolint:errcheck,gosec
|
||||||
}
|
}
|
||||||
h.outer.Write(in[origLen:]) //nolint: errcheck,gosec
|
h.outer.Write(in[origLen:]) //nolint:errcheck,gosec
|
||||||
return h.outer.Sum(in[:origLen])
|
return h.outer.Sum(in[:origLen])
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,13 +78,13 @@ func (h *hmac) BlockSize() int { return h.inner.BlockSize() }
|
|||||||
func (h *hmac) Reset() {
|
func (h *hmac) Reset() {
|
||||||
if h.marshaled {
|
if h.marshaled {
|
||||||
if err := h.inner.(marshalable).UnmarshalBinary(h.ipad); err != nil { //nolint:forcetypeassert
|
if err := h.inner.(marshalable).UnmarshalBinary(h.ipad); err != nil { //nolint:forcetypeassert
|
||||||
panic(err) // nolint
|
panic(err) //nolint
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
h.inner.Reset()
|
h.inner.Reset()
|
||||||
h.inner.Write(h.ipad) //nolint: errcheck,gosec
|
h.inner.Write(h.ipad) //nolint:errcheck,gosec
|
||||||
|
|
||||||
// If the underlying hash is marshalable, we can save some time by
|
// If the underlying hash is marshalable, we can save some time by
|
||||||
// saving a copy of the hash state now, and restoring it on future
|
// saving a copy of the hash state now, and restoring it on future
|
||||||
@@ -107,7 +107,7 @@ func (h *hmac) Reset() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
h.outer.Reset()
|
h.outer.Reset()
|
||||||
h.outer.Write(h.opad) //nolint: errcheck,gosec
|
h.outer.Write(h.opad) //nolint:errcheck,gosec
|
||||||
omarshal, err := marshalableOuter.MarshalBinary()
|
omarshal, err := marshalableOuter.MarshalBinary()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@@ -132,7 +132,7 @@ func New(h func() hash.Hash, key []byte) hash.Hash {
|
|||||||
hm.opad = make([]byte, blocksize)
|
hm.opad = make([]byte, blocksize)
|
||||||
if len(key) > blocksize {
|
if len(key) > blocksize {
|
||||||
// If key is too big, hash it.
|
// If key is too big, hash it.
|
||||||
hm.outer.Write(key) // nolint:errcheck,gosec
|
hm.outer.Write(key) //nolint:errcheck,gosec
|
||||||
key = hm.outer.Sum(nil)
|
key = hm.outer.Sum(nil)
|
||||||
}
|
}
|
||||||
copy(hm.ipad, key)
|
copy(hm.ipad, key)
|
||||||
@@ -143,7 +143,7 @@ func New(h func() hash.Hash, key []byte) hash.Hash {
|
|||||||
for i := range hm.opad {
|
for i := range hm.opad {
|
||||||
hm.opad[i] ^= 0x5c
|
hm.opad[i] ^= 0x5c
|
||||||
}
|
}
|
||||||
hm.inner.Write(hm.ipad) //nolint: errcheck,gosec
|
hm.inner.Write(hm.ipad) //nolint:errcheck,gosec
|
||||||
|
|
||||||
return hm
|
return hm
|
||||||
}
|
}
|
||||||
|
@@ -4,9 +4,9 @@
|
|||||||
|
|
||||||
package hmac
|
package hmac
|
||||||
|
|
||||||
import ( // nolint:gci
|
import ( //nolint:gci
|
||||||
"crypto/md5" // nolint:gosec
|
"crypto/md5" //nolint:gosec
|
||||||
"crypto/sha1" // nolint:gosec
|
"crypto/sha1" //nolint:gosec
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"crypto/sha512"
|
"crypto/sha512"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -405,7 +405,7 @@ func hmacTests() []hmacTest {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
sha512.New384,
|
sha512.New384,
|
||||||
[]byte{ // nolint:dupl
|
[]byte{ //nolint:dupl
|
||||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
|
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
|
||||||
@@ -485,7 +485,7 @@ func hmacTests() []hmacTest {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
sha512.New,
|
sha512.New,
|
||||||
[]byte{ // nolint:dupl
|
[]byte{ //nolint:dupl
|
||||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
|
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
|
||||||
@@ -588,7 +588,7 @@ func BenchmarkHMACSHA256_1K(b *testing.B) {
|
|||||||
h := New(sha256.New, key)
|
h := New(sha256.New, key)
|
||||||
b.SetBytes(int64(len(buf)))
|
b.SetBytes(int64(len(buf)))
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
h.Write(buf) // nolint:errcheck,gosec
|
h.Write(buf) //nolint:errcheck,gosec
|
||||||
h.Reset()
|
h.Reset()
|
||||||
mac := h.Sum(nil)
|
mac := h.Sum(nil)
|
||||||
buf[0] = mac[0]
|
buf[0] = mac[0]
|
||||||
@@ -601,7 +601,7 @@ func BenchmarkHMACSHA256_32(b *testing.B) {
|
|||||||
h := New(sha256.New, key)
|
h := New(sha256.New, key)
|
||||||
b.SetBytes(int64(len(buf)))
|
b.SetBytes(int64(len(buf)))
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
h.Write(buf) // nolint:errcheck,gosec
|
h.Write(buf) //nolint:errcheck,gosec
|
||||||
h.Reset()
|
h.Reset()
|
||||||
mac := h.Sum(nil)
|
mac := h.Sum(nil)
|
||||||
buf[0] = mac[0]
|
buf[0] = mac[0]
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
package hmac
|
package hmac
|
||||||
|
|
||||||
import ( // nolint:gci
|
import ( //nolint:gci
|
||||||
"crypto/sha1" // nolint:gosec
|
"crypto/sha1" //nolint:gosec
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"hash"
|
"hash"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -18,7 +18,7 @@ func (h *hmac) resetTo(key []byte) {
|
|||||||
|
|
||||||
if len(key) > blocksize {
|
if len(key) > blocksize {
|
||||||
// If key is too big, hash it.
|
// If key is too big, hash it.
|
||||||
h.outer.Write(key) // nolint:errcheck,gosec
|
h.outer.Write(key) //nolint:errcheck,gosec
|
||||||
key = h.outer.Sum(nil)
|
key = h.outer.Sum(nil)
|
||||||
}
|
}
|
||||||
copy(h.ipad, key)
|
copy(h.ipad, key)
|
||||||
@@ -29,12 +29,12 @@ func (h *hmac) resetTo(key []byte) {
|
|||||||
for i := range h.opad {
|
for i := range h.opad {
|
||||||
h.opad[i] ^= 0x5c
|
h.opad[i] ^= 0x5c
|
||||||
}
|
}
|
||||||
h.inner.Write(h.ipad) //nolint: errcheck,gosec
|
h.inner.Write(h.ipad) //nolint:errcheck,gosec
|
||||||
|
|
||||||
h.marshaled = false
|
h.marshaled = false
|
||||||
}
|
}
|
||||||
|
|
||||||
var hmacSHA1Pool = &sync.Pool{ // nolint:gochecknoglobals
|
var hmacSHA1Pool = &sync.Pool{ //nolint:gochecknoglobals
|
||||||
New: func() interface{} {
|
New: func() interface{} {
|
||||||
h := New(sha1.New, make([]byte, sha1.BlockSize))
|
h := New(sha1.New, make([]byte, sha1.BlockSize))
|
||||||
return h
|
return h
|
||||||
@@ -56,7 +56,7 @@ func PutSHA1(h hash.Hash) {
|
|||||||
hmacSHA1Pool.Put(hm)
|
hmacSHA1Pool.Put(hm)
|
||||||
}
|
}
|
||||||
|
|
||||||
var hmacSHA256Pool = &sync.Pool{ // nolint:gochecknoglobals
|
var hmacSHA256Pool = &sync.Pool{ //nolint:gochecknoglobals
|
||||||
New: func() interface{} {
|
New: func() interface{} {
|
||||||
h := New(sha256.New, make([]byte, sha256.BlockSize))
|
h := New(sha256.New, make([]byte, sha256.BlockSize))
|
||||||
return h
|
return h
|
||||||
@@ -82,8 +82,8 @@ func PutSHA256(h hash.Hash) {
|
|||||||
//
|
//
|
||||||
// Put and Acquire functions are internal functions to project, so
|
// Put and Acquire functions are internal functions to project, so
|
||||||
// checking it via such assert is optimal.
|
// checking it via such assert is optimal.
|
||||||
func assertHMACSize(h *hmac, size, blocksize int) { //nolint: unparam
|
func assertHMACSize(h *hmac, size, blocksize int) { //nolint:unparam
|
||||||
if h.Size() != size || h.BlockSize() != blocksize {
|
if h.Size() != size || h.BlockSize() != blocksize {
|
||||||
panic("BUG: hmac size invalid") // nolint
|
panic("BUG: hmac size invalid") //nolint
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
package hmac
|
package hmac
|
||||||
|
|
||||||
import ( // nolint:gci
|
import ( //nolint:gci
|
||||||
"crypto/sha1" // nolint:gosec
|
"crypto/sha1" //nolint:gosec
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -14,7 +14,7 @@ func BenchmarkHMACSHA1_512(b *testing.B) {
|
|||||||
h := AcquireSHA1(key)
|
h := AcquireSHA1(key)
|
||||||
b.SetBytes(int64(len(buf)))
|
b.SetBytes(int64(len(buf)))
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
h.Write(buf) // nolint:errcheck,gosec
|
h.Write(buf) //nolint:errcheck,gosec
|
||||||
h.Reset()
|
h.Reset()
|
||||||
mac := h.Sum(nil)
|
mac := h.Sum(nil)
|
||||||
buf[0] = mac[0]
|
buf[0] = mac[0]
|
||||||
@@ -29,7 +29,7 @@ func BenchmarkHMACSHA1_512_Pool(b *testing.B) {
|
|||||||
b.SetBytes(int64(len(buf)))
|
b.SetBytes(int64(len(buf)))
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
h := AcquireSHA1(key)
|
h := AcquireSHA1(key)
|
||||||
h.Write(buf) // nolint:errcheck,gosec
|
h.Write(buf) //nolint:errcheck,gosec
|
||||||
h.Reset()
|
h.Reset()
|
||||||
mac := h.Sum(tBuf)
|
mac := h.Sum(tBuf)
|
||||||
buf[0] = mac[0]
|
buf[0] = mac[0]
|
||||||
@@ -68,7 +68,7 @@ func TestHMACReset(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHMACPool_SHA1(t *testing.T) { // nolint:dupl
|
func TestHMACPool_SHA1(t *testing.T) { //nolint:dupl
|
||||||
for i, tt := range hmacTests() {
|
for i, tt := range hmacTests() {
|
||||||
if tt.blocksize != sha1.BlockSize || tt.size != sha1.Size {
|
if tt.blocksize != sha1.BlockSize || tt.size != sha1.Size {
|
||||||
continue
|
continue
|
||||||
@@ -102,7 +102,7 @@ func TestHMACPool_SHA1(t *testing.T) { // nolint:dupl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHMACPool_SHA256(t *testing.T) { // nolint:dupl
|
func TestHMACPool_SHA256(t *testing.T) { //nolint:dupl
|
||||||
for i, tt := range hmacTests() {
|
for i, tt := range hmacTests() {
|
||||||
if tt.blocksize != sha256.BlockSize || tt.size != sha256.Size {
|
if tt.blocksize != sha256.BlockSize || tt.size != sha256.Size {
|
||||||
continue
|
continue
|
||||||
|
@@ -432,11 +432,11 @@ const (
|
|||||||
// Common STUN message types.
|
// Common STUN message types.
|
||||||
var (
|
var (
|
||||||
// Binding request message type.
|
// Binding request message type.
|
||||||
BindingRequest = NewType(MethodBinding, ClassRequest) // nolint:gochecknoglobals
|
BindingRequest = NewType(MethodBinding, ClassRequest) //nolint:gochecknoglobals
|
||||||
// Binding success response message type
|
// Binding success response message type
|
||||||
BindingSuccess = NewType(MethodBinding, ClassSuccessResponse) // nolint:gochecknoglobals
|
BindingSuccess = NewType(MethodBinding, ClassSuccessResponse) //nolint:gochecknoglobals
|
||||||
// Binding error response message type.
|
// Binding error response message type.
|
||||||
BindingError = NewType(MethodBinding, ClassErrorResponse) // nolint:gochecknoglobals
|
BindingError = NewType(MethodBinding, ClassErrorResponse) //nolint:gochecknoglobals
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c MessageClass) String() string {
|
func (c MessageClass) String() string {
|
||||||
@@ -450,7 +450,7 @@ func (c MessageClass) String() string {
|
|||||||
case ClassErrorResponse:
|
case ClassErrorResponse:
|
||||||
return "error response"
|
return "error response"
|
||||||
default:
|
default:
|
||||||
panic("unknown message class") // nolint
|
panic("unknown message class") //nolint
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -266,7 +266,7 @@ func BenchmarkMessage_WriteTo(b *testing.B) {
|
|||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
m.WriteTo(buf) // nolint:errcheck,gosec
|
m.WriteTo(buf) //nolint:errcheck,gosec
|
||||||
buf.Reset()
|
buf.Reset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -502,7 +502,7 @@ func TestMessage_String(t *testing.T) {
|
|||||||
|
|
||||||
func TestIsMessage(t *testing.T) {
|
func TestIsMessage(t *testing.T) {
|
||||||
m := New()
|
m := New()
|
||||||
NewSoftware("software").AddTo(m) // nolint:errcheck,gosec
|
NewSoftware("software").AddTo(m) //nolint:errcheck,gosec
|
||||||
m.WriteHeader()
|
m.WriteHeader()
|
||||||
|
|
||||||
tt := [...]struct {
|
tt := [...]struct {
|
||||||
@@ -531,7 +531,7 @@ func BenchmarkIsMessage(b *testing.B) {
|
|||||||
m := New()
|
m := New()
|
||||||
m.Type = MessageType{Method: MethodBinding, Class: ClassRequest}
|
m.Type = MessageType{Method: MethodBinding, Class: ClassRequest}
|
||||||
m.TransactionID = NewTransactionID()
|
m.TransactionID = NewTransactionID()
|
||||||
NewSoftware("cydev/stun test").AddTo(m) // nolint:errcheck,gosec
|
NewSoftware("cydev/stun test").AddTo(m) //nolint:errcheck,gosec
|
||||||
m.WriteHeader()
|
m.WriteHeader()
|
||||||
|
|
||||||
b.SetBytes(int64(messageHeaderSize))
|
b.SetBytes(int64(messageHeaderSize))
|
||||||
@@ -546,7 +546,7 @@ func BenchmarkIsMessage(b *testing.B) {
|
|||||||
|
|
||||||
func loadData(tb testing.TB, name string) []byte {
|
func loadData(tb testing.TB, name string) []byte {
|
||||||
name = filepath.Join("testdata", name)
|
name = filepath.Join("testdata", name)
|
||||||
f, err := os.Open(name) //nolint: gosec
|
f, err := os.Open(name) //nolint:gosec
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tb.Fatal(err)
|
tb.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -634,7 +634,7 @@ func BenchmarkMessageFull(b *testing.B) {
|
|||||||
}
|
}
|
||||||
m.WriteAttributes()
|
m.WriteAttributes()
|
||||||
m.WriteHeader()
|
m.WriteHeader()
|
||||||
Fingerprint.AddTo(m) // nolint:errcheck,gosec
|
Fingerprint.AddTo(m) //nolint:errcheck,gosec
|
||||||
m.WriteHeader()
|
m.WriteHeader()
|
||||||
m.Reset()
|
m.Reset()
|
||||||
}
|
}
|
||||||
@@ -688,7 +688,7 @@ func TestMessage_Contains(t *testing.T) {
|
|||||||
func ExampleMessage() {
|
func ExampleMessage() {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
m := new(Message)
|
m := new(Message)
|
||||||
m.Build(BindingRequest, // nolint:errcheck,gosec
|
m.Build(BindingRequest, //nolint:errcheck,gosec
|
||||||
NewTransactionIDSetter([TransactionIDSize]byte{
|
NewTransactionIDSetter([TransactionIDSize]byte{
|
||||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1,
|
1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1,
|
||||||
}),
|
}),
|
||||||
@@ -714,11 +714,11 @@ func ExampleMessage() {
|
|||||||
decoded.Raw = make([]byte, 0, 1024) // for ReadFrom that reuses m.Raw
|
decoded.Raw = make([]byte, 0, 1024) // for ReadFrom that reuses m.Raw
|
||||||
// ReadFrom does not allocate internal buffer for reading from io.Reader,
|
// ReadFrom does not allocate internal buffer for reading from io.Reader,
|
||||||
// instead it uses m.Raw, expanding it length to capacity.
|
// instead it uses m.Raw, expanding it length to capacity.
|
||||||
decoded.ReadFrom(buf) // nolint:errcheck,gosec
|
decoded.ReadFrom(buf) //nolint:errcheck,gosec
|
||||||
fmt.Println("has software:", decoded.Contains(AttrSoftware))
|
fmt.Println("has software:", decoded.Contains(AttrSoftware))
|
||||||
fmt.Println("has nonce:", decoded.Contains(AttrNonce))
|
fmt.Println("has nonce:", decoded.Contains(AttrNonce))
|
||||||
var software Software
|
var software Software
|
||||||
decoded.Parse(&software) // nolint:errcheck,gosec
|
decoded.Parse(&software) //nolint:errcheck,gosec
|
||||||
// Rule for Parse method is same as for Build.
|
// Rule for Parse method is same as for Build.
|
||||||
fmt.Println("software:", software)
|
fmt.Println("software:", software)
|
||||||
if err := Fingerprint.Check(decoded); err == nil {
|
if err := Fingerprint.Check(decoded); err == nil {
|
||||||
@@ -901,7 +901,7 @@ func BenchmarkMessage_CloneTo(b *testing.B) {
|
|||||||
}
|
}
|
||||||
b.SetBytes(int64(len(m.Raw)))
|
b.SetBytes(int64(len(m.Raw)))
|
||||||
a := new(Message)
|
a := new(Message)
|
||||||
m.CloneTo(a) // nolint:errcheck,gosec
|
m.CloneTo(a) //nolint:errcheck,gosec
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if err := m.CloneTo(a); err != nil {
|
if err := m.CloneTo(a); err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
@@ -930,7 +930,7 @@ func TestMessage_AddTo(t *testing.T) {
|
|||||||
if b.Equal(m) {
|
if b.Equal(m) {
|
||||||
t.Fatal("should not be equal")
|
t.Fatal("should not be equal")
|
||||||
}
|
}
|
||||||
m.AddTo(b) // nolint:errcheck,gosec
|
m.AddTo(b) //nolint:errcheck,gosec
|
||||||
if !b.Equal(m) {
|
if !b.Equal(m) {
|
||||||
t.Fatal("should be equal")
|
t.Fatal("should be equal")
|
||||||
}
|
}
|
||||||
@@ -948,7 +948,7 @@ func BenchmarkMessage_AddTo(b *testing.B) {
|
|||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
a := new(Message)
|
a := new(Message)
|
||||||
m.CloneTo(a) // nolint:errcheck,gosec
|
m.CloneTo(a) //nolint:errcheck,gosec
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if err := m.AddTo(a); err != nil {
|
if err := m.AddTo(a); err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
|
@@ -82,7 +82,7 @@ func TestRFC5769(t *testing.T) {
|
|||||||
if err := r.GetFrom(m); err != nil {
|
if err := r.GetFrom(m); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
if r.String() != "example.org" { // nolint:goconst
|
if r.String() != "example.org" { //nolint:goconst
|
||||||
t.Error("bad realm")
|
t.Error("bad realm")
|
||||||
}
|
}
|
||||||
// checking HMAC
|
// checking HMAC
|
||||||
|
6
stun.go
6
stun.go
@@ -17,12 +17,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// bin is shorthand to binary.BigEndian.
|
// bin is shorthand to binary.BigEndian.
|
||||||
var bin = binary.BigEndian // nolint:gochecknoglobals
|
var bin = binary.BigEndian //nolint:gochecknoglobals
|
||||||
|
|
||||||
func readFullOrPanic(r io.Reader, v []byte) int {
|
func readFullOrPanic(r io.Reader, v []byte) int {
|
||||||
n, err := io.ReadFull(r, v)
|
n, err := io.ReadFull(r, v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err) // nolint
|
panic(err) //nolint
|
||||||
}
|
}
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
@@ -30,7 +30,7 @@ func readFullOrPanic(r io.Reader, v []byte) int {
|
|||||||
func writeOrPanic(w io.Writer, v []byte) int {
|
func writeOrPanic(w io.Writer, v []byte) int {
|
||||||
n, err := w.Write(v)
|
n, err := w.Write(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err) // nolint
|
panic(err) //nolint
|
||||||
}
|
}
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
@@ -30,7 +30,7 @@ func NewUDPServer(
|
|||||||
|
|
||||||
udpConn, err := net.ListenUDP(network, &net.UDPAddr{IP: net.ParseIP(ip), Port: 0})
|
udpConn, err := net.ListenUDP(network, &net.UDPAddr{IP: net.ParseIP(ip), Port: 0})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err) // nolint
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// necessary for ipv6
|
// necessary for ipv6
|
||||||
@@ -68,7 +68,7 @@ func NewUDPServer(
|
|||||||
select {
|
select {
|
||||||
case err := <-errCh:
|
case err := <-errCh:
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err) // nolint
|
t.Fatal(err) //nolint
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@@ -76,7 +76,7 @@ func NewUDPServer(
|
|||||||
|
|
||||||
err := udpConn.Close()
|
err := udpConn.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err) // nolint
|
t.Fatal(err) //nolint
|
||||||
}
|
}
|
||||||
|
|
||||||
<-errCh
|
<-errCh
|
||||||
|
@@ -74,7 +74,7 @@ func BenchmarkUsername_AddTo(b *testing.B) {
|
|||||||
func BenchmarkUsername_GetFrom(b *testing.B) {
|
func BenchmarkUsername_GetFrom(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
m := new(Message)
|
m := new(Message)
|
||||||
Username("test").AddTo(m) // nolint:errcheck,gosec
|
Username("test").AddTo(m) //nolint:errcheck,gosec
|
||||||
var u Username
|
var u Username
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
@@ -260,8 +260,8 @@ func BenchmarkNonce_GetFrom(b *testing.B) {
|
|||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
m := New()
|
m := New()
|
||||||
n := NewNonce("nonce")
|
n := NewNonce("nonce")
|
||||||
n.AddTo(m) // nolint:errcheck,gosec
|
n.AddTo(m) //nolint:errcheck,gosec
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
n.GetFrom(m) // nolint:errcheck,gosec
|
n.GetFrom(m) //nolint:errcheck,gosec
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
4
uri.go
4
uri.go
@@ -37,10 +37,10 @@ func ParseURI(rawURI string) (URI, error) {
|
|||||||
return URI{}, urlParseErr
|
return URI{}, urlParseErr
|
||||||
}
|
}
|
||||||
if u.Scheme != Scheme && u.Scheme != SchemeSecure {
|
if u.Scheme != Scheme && u.Scheme != SchemeSecure {
|
||||||
return URI{}, fmt.Errorf("unknown uri scheme %q", u.Scheme) //nolint: goerr113
|
return URI{}, fmt.Errorf("unknown uri scheme %q", u.Scheme) //nolint:goerr113
|
||||||
}
|
}
|
||||||
if u.Opaque == "" {
|
if u.Opaque == "" {
|
||||||
return URI{}, errors.New("invalid uri format: expected opaque") //nolint: goerr113
|
return URI{}, errors.New("invalid uri format: expected opaque") //nolint:goerr113
|
||||||
}
|
}
|
||||||
// Using URL methods to split host.
|
// Using URL methods to split host.
|
||||||
u.Host = u.Opaque
|
u.Host = u.Opaque
|
||||||
|
12
uri_test.go
12
uri_test.go
@@ -35,12 +35,12 @@ func TestParseURI(t *testing.T) {
|
|||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
out, parseErr := ParseURI(tc.in) //nolint: scopelint
|
out, parseErr := ParseURI(tc.in) //nolint:scopelint
|
||||||
if parseErr != nil {
|
if parseErr != nil {
|
||||||
t.Fatal(parseErr)
|
t.Fatal(parseErr)
|
||||||
}
|
}
|
||||||
if out != tc.out { //nolint: scopelint
|
if out != tc.out { //nolint:scopelint
|
||||||
t.Errorf("%s != %s", out, tc.out) //nolint: scopelint
|
t.Errorf("%s != %s", out, tc.out) //nolint:scopelint
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -63,7 +63,7 @@ func TestParseURI(t *testing.T) {
|
|||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
_, parseErr := ParseURI(tc.in) //nolint: scopelint
|
_, parseErr := ParseURI(tc.in) //nolint:scopelint
|
||||||
if parseErr == nil {
|
if parseErr == nil {
|
||||||
t.Fatal("should fail, but did not")
|
t.Fatal("should fail, but did not")
|
||||||
}
|
}
|
||||||
@@ -109,8 +109,8 @@ func TestURI_String(t *testing.T) {
|
|||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
if v := tc.uri.String(); v != tc.out { //nolint: scopelint
|
if v := tc.uri.String(); v != tc.out { //nolint:scopelint
|
||||||
t.Errorf("%q != %q", v, tc.out) //nolint: scopelint
|
t.Errorf("%q != %q", v, tc.out) //nolint:scopelint
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@@ -20,7 +20,7 @@ func BenchmarkXORMappedAddress_AddTo(b *testing.B) {
|
|||||||
ip := net.ParseIP("192.168.1.32")
|
ip := net.ParseIP("192.168.1.32")
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
addr := &XORMappedAddress{IP: ip, Port: 3654}
|
addr := &XORMappedAddress{IP: ip, Port: 3654}
|
||||||
addr.AddTo(m) // nolint:errcheck,gosec
|
addr.AddTo(m) //nolint:errcheck,gosec
|
||||||
m.Reset()
|
m.Reset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -107,7 +107,7 @@ func TestXORMappedAddress_GetFrom_Invalid(t *testing.T) {
|
|||||||
|
|
||||||
addr.IP = expectedIP
|
addr.IP = expectedIP
|
||||||
addr.Port = expectedPort
|
addr.Port = expectedPort
|
||||||
addr.AddTo(m) // nolint:errcheck,gosec
|
addr.AddTo(m) //nolint:errcheck,gosec
|
||||||
m.WriteHeader()
|
m.WriteHeader()
|
||||||
|
|
||||||
mRes := New()
|
mRes := New()
|
||||||
@@ -165,7 +165,7 @@ func TestXORMappedAddress_AddTo_IPv6(t *testing.T) {
|
|||||||
IP: net.ParseIP("fe80::dc2b:44ff:fe20:6009"),
|
IP: net.ParseIP("fe80::dc2b:44ff:fe20:6009"),
|
||||||
Port: 21254,
|
Port: 21254,
|
||||||
}
|
}
|
||||||
addr.AddTo(m) // nolint:errcheck,gosec
|
addr.AddTo(m) //nolint:errcheck,gosec
|
||||||
m.WriteHeader()
|
m.WriteHeader()
|
||||||
|
|
||||||
mRes := New()
|
mRes := New()
|
||||||
|
Reference in New Issue
Block a user