1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

TEST: Upgrade pion to v3.2.9. (#3567)

------

Co-authored-by: chundonglinlin <chundonglinlin@163.com>
This commit is contained in:
Winlin 2023-06-05 11:25:04 +08:00 committed by GitHub
parent 104cf14d68
commit df854339ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
1383 changed files with 118469 additions and 41421 deletions

View file

@ -0,0 +1,25 @@
### JetBrains IDE ###
#####################
.idea/
### Emacs Temporary Files ###
#############################
*~
### Folders ###
###############
bin/
vendor/
node_modules/
### Files ###
#############
*.ivf
*.ogg
tags
cover.out
*.sw[poe]
*.wasm
examples/sfu-ws/cert.pem
examples/sfu-ws/key.pem
wasm_exec.js

View file

@ -3,11 +3,114 @@ linters-settings:
check-shadowing: true
misspell:
locale: US
exhaustive:
default-signifies-exhaustive: true
gomodguard:
blocked:
modules:
- github.com/pkg/errors:
recommendations:
- errors
linters:
enable-all: true
enable:
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
- bidichk # Checks for dangerous unicode character sequences
- bodyclose # checks whether HTTP response body is closed successfully
- contextcheck # check the function whether use a non-inherited context
- decorder # check declaration order and count of types, constants, variables and functions
- depguard # Go linter that checks if package imports are in a list of acceptable packages
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
- dupl # Tool for code clone detection
- durationcheck # check for two durations multiplied together
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases
- errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and optionally reports occations, where the check for the returned error can be omitted.
- errname # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`.
- errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13.
- exhaustive # check exhaustiveness of enum switch statements
- exportloopref # checks for pointers to enclosing loop variables
- forcetypeassert # finds forced type assertions
- gci # Gci control golang package import order and make it always deterministic.
- gochecknoglobals # Checks that no globals are present in Go code
- gochecknoinits # Checks that no init functions are present in Go code
- gocognit # Computes and checks the cognitive complexity of functions
- goconst # Finds repeated strings that could be replaced by a constant
- gocritic # The most opinionated Go source code linter
- godox # Tool for detection of FIXME, TODO and other comment keywords
- goerr113 # Golang linter to check the errors handling expressions
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification
- gofumpt # Gofumpt checks whether code was gofumpt-ed.
- goheader # Checks is file header matches to pattern
- goimports # Goimports does everything that gofmt does. Additionally it checks unused imports
- gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod.
- gomodguard # Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations.
- goprintffuncname # Checks that printf-like functions are named with `f` at the end
- gosec # Inspects source code for security problems
- gosimple # Linter for Go source code that specializes in simplifying a code
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
- grouper # An analyzer to analyze expression groups.
- importas # Enforces consistent import aliases
- ineffassign # Detects when assignments to existing variables are not used
- misspell # Finds commonly misspelled English words in comments
- nakedret # Finds naked returns in functions greater than a specified function length
- nilerr # Finds the code that returns nil even if it checks that the error is not nil.
- nilnil # Checks that there is no simultaneous return of `nil` error and an invalid value.
- noctx # noctx finds sending http request without context.Context
- predeclared # find code that shadows one of Go's predeclared identifiers
- revive # golint replacement, finds style mistakes
- staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks
- stylecheck # Stylecheck is a replacement for golint
- tagliatelle # Checks the struct tags.
- tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17
- tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
- unconvert # Remove unnecessary type conversions
- unparam # Reports unused function parameters
- unused # Checks Go code for unused constants, variables, functions and types
- wastedassign # wastedassign finds wasted assignment statements
- whitespace # Tool for detection of leading and trailing whitespace
disable:
- funlen
- containedctx # containedctx is a linter that detects struct contained context.Context field
- cyclop # checks function and package cyclomatic complexity
- exhaustivestruct # Checks if all struct's fields are initialized
- forbidigo # Forbids identifiers
- funlen # Tool for detection of long functions
- gocyclo # Computes and checks the cyclomatic complexity of functions
- godot # Check if comments end in a period
- gomnd # An analyzer to detect magic numbers.
- ifshort # Checks that your code uses short syntax for if-statements whenever possible
- ireturn # Accept Interfaces, Return Concrete Types
- lll # Reports long lines
- maintidx # maintidx measures the maintainability index of each function.
- makezero # Finds slice declarations with non-zero initial length
- maligned # Tool to detect Go structs that would take less memory if their fields were sorted
- nestif # Reports deeply nested if statements
- nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity
- nolintlint # Reports ill-formed or insufficient nolint directives
- paralleltest # paralleltest detects missing usage of t.Parallel() method in your Go test
- prealloc # Finds slice declarations that could potentially be preallocated
- promlinter # Check Prometheus metrics naming via promlint
- rowserrcheck # checks whether Err of rows is checked successfully
- sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed.
- testpackage # linter that makes you use a separate _test package
- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers
- varnamelen # checks that the length of a variable's name matches its scope
- wrapcheck # Checks that errors returned from external packages are wrapped
- wsl # Whitespace Linter - Forces you to use empty lines!
issues:
exclude-use-default: false
exclude-rules:
# Allow complex tests, better to be self contained
- path: _test\.go
linters:
- gocognit
# Allow complex main function in examples
- path: examples
text: "of func `main` is high"
linters:
- gocognit
run:
skip-dirs-use-default: false

View file

@ -0,0 +1,2 @@
builds:
- skip: true

View file

@ -1,19 +0,0 @@
language: go
go:
- "1.x" # use the latest Go release
env:
- GO111MODULE=on
before_script:
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.18.0
script:
- golangci-lint run ./...
- rm -rf examples # Remove examples, no test coverage for them
- go test -coverpkg=$(go list ./... | tr '\n' ',') -coverprofile=cover.out -v -race -covermode=atomic ./...
- bash <(curl -s https://codecov.io/bash)
- bash .github/assert-contributors.sh
- bash .github/lint-disallowed-functions-in-library.sh
- bash .github/lint-commit-message.sh

View file

@ -0,0 +1,17 @@
# Thank you to everyone that made Pion possible. If you are interested in contributing
# we would love to have you https://github.com/pion/webrtc/wiki/Contributing
#
# This file is auto generated, using git to list all individuals contributors.
# see https://github.com/pion/.goassets/blob/master/scripts/generate-authors.sh for the scripting
Atsushi Watanabe <atsushi.w@ieee.org>
Bjørn Remseth <la3lma@gmail.com>
Doug Cone <nullvariable@users.noreply.github.com>
Hugo Arregui <hugo.arregui@gmail.com>
Javier Peletier <jm@epiclabs.io>
Jonas van den Berg <24623262+vonas@users.noreply.github.com>
Konstantin Itskov <konstantin.itskov@kovits.com>
Sean DuBois <seaduboi@amazon.com>
Sean DuBois <sean@siobud.com>
# List of contributors not appearing in Git history

View file

@ -9,7 +9,7 @@
<a href="https://pion.ly/slack"><img src="https://img.shields.io/badge/join-us%20on%20slack-gray.svg?longCache=true&logo=slack&colorB=brightgreen" alt="Slack Widget"></a>
<br>
<a href="https://travis-ci.org/pion/mdns"><img src="https://travis-ci.org/pion/mdns.svg?branch=master" alt="Build Status"></a>
<a href="https://godoc.org/github.com/pion/mdns"><img src="https://godoc.org/github.com/pion/mdns?status.svg" alt="GoDoc"></a>
<a href="https://pkg.go.dev/github.com/pion/mdns"><img src="https://godoc.org/github.com/pion/mdns?status.svg" alt="GoDoc"></a>
<a href="https://codecov.io/gh/pion/mdns"><img src="https://codecov.io/gh/pion/mdns/branch/master/graph/badge.svg" alt="Coverage Status"></a>
<a href="https://goreportcard.com/report/github.com/pion/mdns"><img src="https://goreportcard.com/badge/github.com/pion/mdns" alt="Go Report Card"></a>
<a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT"></a>
@ -21,7 +21,7 @@ Go mDNS implementation. The original user is Pion WebRTC, but we would love to s
### Running Server
For a mDNS server that responds to queries for `pion-test.local`
```sh
go run examples/listen/main.go
go run examples/server/main.go
```
@ -55,9 +55,5 @@ If you need commercial support or don't want to use public methods you can conta
### Contributing
Check out the **[contributing wiki](https://github.com/pion/webrtc/wiki/Contributing)** to join the group of amazing people making this project possible:
* [Sean DuBois](https://github.com/Sean-Der) - *Original Author*
* [Konstantin Itskov](https://github.com/trivigy) - Contributor
* [Hugo Arregui](https://github.com/hugoArregui)
### License
MIT License - see [LICENSE](LICENSE) for full text

View file

@ -0,0 +1,20 @@
#
# DO NOT EDIT THIS FILE
#
# It is automatically copied from https://github.com/pion/.goassets repository.
#
coverage:
status:
project:
default:
# Allow decreasing 2% of total coverage to avoid noise.
threshold: 2%
patch:
default:
target: 70%
only_pulls: true
ignore:
- "examples/*"
- "examples/**/*"

View file

@ -15,7 +15,7 @@ const (
// Config is used to configure a mDNS client or server.
type Config struct {
// QueryInterval controls how ofter we sends Queries until we
// QueryInterval controls how often we sends Queries until we
// get a response for the requested name
QueryInterval time.Duration

View file

@ -2,8 +2,10 @@ package mdns
import (
"context"
"errors"
"math/big"
"net"
"runtime"
"sync"
"time"
@ -23,6 +25,7 @@ type Conn struct {
queryInterval time.Duration
localNames []string
queries []query
ifaces []net.Interface
closed chan interface{}
}
@ -38,13 +41,14 @@ type queryResult struct {
}
const (
inboundBufferSize = 512
defaultQueryInterval = time.Second
destinationAddress = "224.0.0.251:5353"
maxMessageRecords = 3
responseTTL = 120
)
var errNoPositiveMTUFound = errors.New("no positive MTU found")
// Server establishes a mDNS connection over an existing conn
func Server(conn *ipv4.PacketConn, config *Config) (*Conn, error) {
if config == nil {
@ -56,11 +60,24 @@ func Server(conn *ipv4.PacketConn, config *Config) (*Conn, error) {
return nil, err
}
inboundBufferSize := 0
joinErrCount := 0
for i := range ifaces {
ifacesToUse := make([]net.Interface, 0, len(ifaces))
for i, ifc := range ifaces {
if err = conn.JoinGroup(&ifaces[i], &net.UDPAddr{IP: net.IPv4(224, 0, 0, 251)}); err != nil {
joinErrCount++
continue
}
ifcCopy := ifc
ifacesToUse = append(ifacesToUse, ifcCopy)
if ifaces[i].MTU > inboundBufferSize {
inboundBufferSize = ifaces[i].MTU
}
}
if inboundBufferSize == 0 {
return nil, errNoPositiveMTUFound
}
if joinErrCount >= len(ifaces) {
return nil, errJoiningMulticastGroup
@ -69,7 +86,6 @@ func Server(conn *ipv4.PacketConn, config *Config) (*Conn, error) {
dstAddr, err := net.ResolveUDPAddr("udp", destinationAddress)
if err != nil {
return nil, err
}
loggerFactory := config.LoggerFactory
@ -88,6 +104,7 @@ func Server(conn *ipv4.PacketConn, config *Config) (*Conn, error) {
socket: conn,
dstAddr: dstAddr,
localNames: localNames,
ifaces: ifacesToUse,
log: loggerFactory.NewLogger("mdns"),
closed: make(chan interface{}),
}
@ -95,7 +112,11 @@ func Server(conn *ipv4.PacketConn, config *Config) (*Conn, error) {
c.queryInterval = config.QueryInterval
}
go c.start()
// https://www.rfc-editor.org/rfc/rfc6762.html#section-17
// Multicast DNS messages carried by UDP may be up to the IP MTU of the
// physical interface, less the space required for the IP header (20
// bytes for IPv4; 40 bytes for IPv6) and the UDP header (8 bytes).
go c.start(inboundBufferSize - 20 - 8)
return c, nil
}
@ -132,6 +153,8 @@ func (c *Conn) Query(ctx context.Context, name string) (dnsmessage.ResourceHeade
ticker := time.NewTicker(c.queryInterval)
c.mu.Unlock()
defer ticker.Stop()
c.sendQuestion(nameWithSuffix)
for {
select {
@ -165,7 +188,11 @@ func interfaceForRemote(remote string) (net.IP, error) {
return nil, err
}
localAddr := conn.LocalAddr().(*net.UDPAddr)
localAddr, ok := conn.LocalAddr().(*net.UDPAddr)
if !ok {
return nil, errFailedCast
}
if err := conn.Close(); err != nil {
return nil, err
}
@ -197,9 +224,24 @@ func (c *Conn) sendQuestion(name string) {
return
}
if _, err := c.socket.WriteTo(rawQuery, nil, c.dstAddr); err != nil {
c.log.Warnf("Failed to send mDNS packet %v", err)
return
c.writeToSocket(rawQuery)
}
const isWindows = runtime.GOOS == "windows"
func (c *Conn) writeToSocket(b []byte) {
var wcm ipv4.ControlMessage
for i := range c.ifaces {
if isWindows {
if err := c.socket.SetMulticastInterface(&c.ifaces[i]); err != nil {
c.log.Warnf("Failed to set multicast interface for %d: %v", i, err)
}
} else {
wcm.IfIndex = c.ifaces[i].Index
}
if _, err := c.socket.WriteTo(b, &wcm, c.dstAddr); err != nil {
c.log.Warnf("Failed to send mDNS packet on interface %d: %v", i, err)
}
}
}
@ -236,13 +278,10 @@ func (c *Conn) sendAnswer(name string, dst net.IP) {
return
}
if _, err := c.socket.WriteTo(rawAnswer, nil, c.dstAddr); err != nil {
c.log.Warnf("Failed to send mDNS packet %v", err)
return
}
c.writeToSocket(rawAnswer)
}
func (c *Conn) start() {
func (c *Conn) start(inboundBufferSize int) { //nolint gocognit
defer func() {
c.mu.Lock()
defer c.mu.Unlock()
@ -255,7 +294,11 @@ func (c *Conn) start() {
for {
n, _, src, err := c.socket.ReadFrom(b)
if err != nil {
return
if errors.Is(err, net.ErrClosed) {
return
}
c.log.Warnf("Failed to ReadFrom %q %v", src, err)
continue
}
func() {
@ -269,7 +312,7 @@ func (c *Conn) start() {
for i := 0; i <= maxMessageRecords; i++ {
q, err := p.Question()
if err == dnsmessage.ErrSectionDone {
if errors.Is(err, dnsmessage.ErrSectionDone) {
break
} else if err != nil {
c.log.Warnf("Failed to parse mDNS packet %v", err)
@ -278,7 +321,6 @@ func (c *Conn) start() {
for _, localName := range c.localNames {
if localName == q.Name.String() {
localAddress, err := interfaceForRemote(src.String())
if err != nil {
c.log.Warnf("Failed to get local interface to communicate with %s: %v", src.String(), err)
@ -292,7 +334,7 @@ func (c *Conn) start() {
for i := 0; i <= maxMessageRecords; i++ {
a, err := p.AnswerHeader()
if err == dnsmessage.ErrSectionDone {
if errors.Is(err, dnsmessage.ErrSectionDone) {
return
}
if err != nil {
@ -306,7 +348,15 @@ func (c *Conn) start() {
for i := len(c.queries) - 1; i >= 0; i-- {
if c.queries[i].nameWithSuffix == a.Name.String() {
c.queries[i].queryResultChan <- queryResult{a, src}
ip, err := ipFromAnswerHeader(a, p)
if err != nil {
c.log.Warnf("Failed to parse mDNS answer %v", err)
return
}
c.queries[i].queryResultChan <- queryResult{a, &net.IPAddr{
IP: ip,
}}
c.queries = append(c.queries[:i], c.queries[i+1:]...)
}
}
@ -314,3 +364,21 @@ func (c *Conn) start() {
}()
}
}
func ipFromAnswerHeader(a dnsmessage.ResourceHeader, p dnsmessage.Parser) (ip []byte, err error) {
if a.Type == dnsmessage.TypeA {
resource, err := p.AResource()
if err != nil {
return nil, err
}
ip = net.IP(resource.A[:])
} else {
resource, err := p.AAAAResource()
if err != nil {
return nil, err
}
ip = resource.AAAA[:]
}
return
}

View file

@ -7,4 +7,5 @@ var (
errConnectionClosed = errors.New("mDNS: connection is closed")
errContextElapsed = errors.New("mDNS: context has elapsed")
errNilConfig = errors.New("mDNS: config must not be nil")
errFailedCast = errors.New("mDNS: failed to cast listener to UDPAddr")
)

View file

@ -1,9 +0,0 @@
module github.com/pion/mdns
go 1.12
require (
github.com/pion/logging v0.2.2
github.com/pion/transport v0.8.10
golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933
)

View file

@ -1,16 +0,0 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pion/logging v0.2.2 h1:M9+AIj/+pxNsDfAT64+MAVgJO0rsyLnoJKCqf//DoeY=
github.com/pion/logging v0.2.2/go.mod h1:k0/tDVsRCX2Mb2ZEmTqNa7CWsQPc+YYCB7Q+5pahoms=
github.com/pion/transport v0.8.10 h1:lTiobMEw2PG6BH/mgIVqTV2mBp/mPT+IJLaN8ZxgdHk=
github.com/pion/transport v0.8.10/go.mod h1:tBmha/UCjpum5hqTWhfAEs3CO4/tHSg0MYRhSzR+CZ8=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933 h1:e6HwijUxhDe+hPNjZQQn9bA5PW3vNmnN64U2ZW759Lk=
golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

View file

@ -0,0 +1,2 @@
// Package mdns implements mDNS (multicast DNS)
package mdns

View file

@ -1,15 +1,6 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:base"
],
"postUpdateOptions": [
"gomodTidy"
],
"commitBody": "Generated by renovateBot",
"packageRules": [
{
"packagePatterns": ["^golang.org/x/"],
"schedule": ["on the first day of the month"]
}
"github>pion/renovate-config"
]
}