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

For regression test, add srs-bench to 3rdparty

This commit is contained in:
winlin 2021-03-04 13:23:01 +08:00
parent de87dd427d
commit 876210f6c9
1158 changed files with 256967 additions and 3 deletions

View file

@ -0,0 +1,13 @@
linters-settings:
govet:
check-shadowing: true
misspell:
locale: US
linters:
enable-all: true
disable:
- funlen
issues:
exclude-use-default: false

View file

@ -0,0 +1,19 @@
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,21 @@
MIT License
Copyright (c) 2018
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -0,0 +1,63 @@
<h1 align="center">
<br>
Pion mDNS
<br>
</h1>
<h4 align="center">A Go implementation of mDNS</h4>
<p align="center">
<a href="https://pion.ly"><img src="https://img.shields.io/badge/pion-mdns-gray.svg?longCache=true&colorB=brightgreen" alt="Pion mDNS"></a>
<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://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>
</p>
<br>
Go mDNS implementation. The original user is Pion WebRTC, but we would love to see it work for everyone.
### Running Server
For a mDNS server that responds to queries for `pion-test.local`
```sh
go run examples/listen/main.go
```
### Running Client
To query using Pion you can run the `query` example
```sh
go run examples/query/main.go
```
You can use the macOS client
```
dns-sd -q pion-test.local
```
Or the avahi client
```
avahi-resolve -a pion-test.local
```
### References
https://tools.ietf.org/html/rfc6762
https://tools.ietf.org/id/draft-ietf-rtcweb-mdns-ice-candidates-02.html
### Community
Pion has an active community on the [Golang Slack](https://invite.slack.golangbridge.org/). Sign up and join the **#pion** channel for discussions and support. You can also use [Pion mailing list](https://groups.google.com/forum/#!forum/pion).
We are always looking to support **your projects**. Please reach out if you have something to build!
If you need commercial support or don't want to use public methods you can contact us at [team@pion.ly](mailto:team@pion.ly)
### 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,27 @@
package mdns
import (
"time"
"github.com/pion/logging"
)
const (
// DefaultAddress is the default used by mDNS
// and in most cases should be the address that the
// net.Conn passed to Server is bound to
DefaultAddress = "224.0.0.0:5353"
)
// Config is used to configure a mDNS client or server.
type Config struct {
// QueryInterval controls how ofter we sends Queries until we
// get a response for the requested name
QueryInterval time.Duration
// LocalNames are the names that we will generate answers for
// when we get questions
LocalNames []string
LoggerFactory logging.LoggerFactory
}

View file

@ -0,0 +1,316 @@
package mdns
import (
"context"
"math/big"
"net"
"sync"
"time"
"github.com/pion/logging"
"golang.org/x/net/dns/dnsmessage"
"golang.org/x/net/ipv4"
)
// Conn represents a mDNS Server
type Conn struct {
mu sync.RWMutex
log logging.LeveledLogger
socket *ipv4.PacketConn
dstAddr *net.UDPAddr
queryInterval time.Duration
localNames []string
queries []query
closed chan interface{}
}
type query struct {
nameWithSuffix string
queryResultChan chan queryResult
}
type queryResult struct {
answer dnsmessage.ResourceHeader
addr net.Addr
}
const (
inboundBufferSize = 512
defaultQueryInterval = time.Second
destinationAddress = "224.0.0.251:5353"
maxMessageRecords = 3
responseTTL = 120
)
// Server establishes a mDNS connection over an existing conn
func Server(conn *ipv4.PacketConn, config *Config) (*Conn, error) {
if config == nil {
return nil, errNilConfig
}
ifaces, err := net.Interfaces()
if err != nil {
return nil, err
}
joinErrCount := 0
for i := range ifaces {
if err = conn.JoinGroup(&ifaces[i], &net.UDPAddr{IP: net.IPv4(224, 0, 0, 251)}); err != nil {
joinErrCount++
}
}
if joinErrCount >= len(ifaces) {
return nil, errJoiningMulticastGroup
}
dstAddr, err := net.ResolveUDPAddr("udp", destinationAddress)
if err != nil {
return nil, err
}
loggerFactory := config.LoggerFactory
if loggerFactory == nil {
loggerFactory = logging.NewDefaultLoggerFactory()
}
localNames := []string{}
for _, l := range config.LocalNames {
localNames = append(localNames, l+".")
}
c := &Conn{
queryInterval: defaultQueryInterval,
queries: []query{},
socket: conn,
dstAddr: dstAddr,
localNames: localNames,
log: loggerFactory.NewLogger("mdns"),
closed: make(chan interface{}),
}
if config.QueryInterval != 0 {
c.queryInterval = config.QueryInterval
}
go c.start()
return c, nil
}
// Close closes the mDNS Conn
func (c *Conn) Close() error {
select {
case <-c.closed:
return nil
default:
}
if err := c.socket.Close(); err != nil {
return err
}
<-c.closed
return nil
}
// Query sends mDNS Queries for the following name until
// either the Context is canceled/expires or we get a result
func (c *Conn) Query(ctx context.Context, name string) (dnsmessage.ResourceHeader, net.Addr, error) {
select {
case <-c.closed:
return dnsmessage.ResourceHeader{}, nil, errConnectionClosed
default:
}
nameWithSuffix := name + "."
queryChan := make(chan queryResult, 1)
c.mu.Lock()
c.queries = append(c.queries, query{nameWithSuffix, queryChan})
ticker := time.NewTicker(c.queryInterval)
c.mu.Unlock()
c.sendQuestion(nameWithSuffix)
for {
select {
case <-ticker.C:
c.sendQuestion(nameWithSuffix)
case <-c.closed:
return dnsmessage.ResourceHeader{}, nil, errConnectionClosed
case res := <-queryChan:
return res.answer, res.addr, nil
case <-ctx.Done():
return dnsmessage.ResourceHeader{}, nil, errContextElapsed
}
}
}
func ipToBytes(ip net.IP) (out [4]byte) {
rawIP := ip.To4()
if rawIP == nil {
return
}
ipInt := big.NewInt(0)
ipInt.SetBytes(rawIP)
copy(out[:], ipInt.Bytes())
return
}
func interfaceForRemote(remote string) (net.IP, error) {
conn, err := net.Dial("udp", remote)
if err != nil {
return nil, err
}
localAddr := conn.LocalAddr().(*net.UDPAddr)
if err := conn.Close(); err != nil {
return nil, err
}
return localAddr.IP, nil
}
func (c *Conn) sendQuestion(name string) {
packedName, err := dnsmessage.NewName(name)
if err != nil {
c.log.Warnf("Failed to construct mDNS packet %v", err)
return
}
msg := dnsmessage.Message{
Header: dnsmessage.Header{},
Questions: []dnsmessage.Question{
{
Type: dnsmessage.TypeA,
Class: dnsmessage.ClassINET,
Name: packedName,
},
},
}
rawQuery, err := msg.Pack()
if err != nil {
c.log.Warnf("Failed to construct mDNS packet %v", err)
return
}
if _, err := c.socket.WriteTo(rawQuery, nil, c.dstAddr); err != nil {
c.log.Warnf("Failed to send mDNS packet %v", err)
return
}
}
func (c *Conn) sendAnswer(name string, dst net.IP) {
packedName, err := dnsmessage.NewName(name)
if err != nil {
c.log.Warnf("Failed to construct mDNS packet %v", err)
return
}
msg := dnsmessage.Message{
Header: dnsmessage.Header{
Response: true,
Authoritative: true,
},
Answers: []dnsmessage.Resource{
{
Header: dnsmessage.ResourceHeader{
Type: dnsmessage.TypeA,
Class: dnsmessage.ClassINET,
Name: packedName,
TTL: responseTTL,
},
Body: &dnsmessage.AResource{
A: ipToBytes(dst),
},
},
},
}
rawAnswer, err := msg.Pack()
if err != nil {
c.log.Warnf("Failed to construct mDNS packet %v", err)
return
}
if _, err := c.socket.WriteTo(rawAnswer, nil, c.dstAddr); err != nil {
c.log.Warnf("Failed to send mDNS packet %v", err)
return
}
}
func (c *Conn) start() {
defer func() {
c.mu.Lock()
defer c.mu.Unlock()
close(c.closed)
}()
b := make([]byte, inboundBufferSize)
p := dnsmessage.Parser{}
for {
n, _, src, err := c.socket.ReadFrom(b)
if err != nil {
return
}
func() {
c.mu.RLock()
defer c.mu.RUnlock()
if _, err := p.Start(b[:n]); err != nil {
c.log.Warnf("Failed to parse mDNS packet %v", err)
return
}
for i := 0; i <= maxMessageRecords; i++ {
q, err := p.Question()
if err == dnsmessage.ErrSectionDone {
break
} else if err != nil {
c.log.Warnf("Failed to parse mDNS packet %v", err)
return
}
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)
continue
}
c.sendAnswer(q.Name.String(), localAddress)
}
}
}
for i := 0; i <= maxMessageRecords; i++ {
a, err := p.AnswerHeader()
if err == dnsmessage.ErrSectionDone {
return
}
if err != nil {
c.log.Warnf("Failed to parse mDNS packet %v", err)
return
}
if a.Type != dnsmessage.TypeA && a.Type != dnsmessage.TypeAAAA {
continue
}
for i := len(c.queries) - 1; i >= 0; i-- {
if c.queries[i].nameWithSuffix == a.Name.String() {
c.queries[i].queryResultChan <- queryResult{a, src}
c.queries = append(c.queries[:i], c.queries[i+1:]...)
}
}
}
}()
}
}

View file

@ -0,0 +1,10 @@
package mdns
import "errors"
var (
errJoiningMulticastGroup = errors.New("mDNS: failed to join multicast group")
errConnectionClosed = errors.New("mDNS: connection is closed")
errContextElapsed = errors.New("mDNS: context has elapsed")
errNilConfig = errors.New("mDNS: config must not be nil")
)

View file

@ -0,0 +1,9 @@
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

@ -0,0 +1,16 @@
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,15 @@
{
"extends": [
"config:base"
],
"postUpdateOptions": [
"gomodTidy"
],
"commitBody": "Generated by renovateBot",
"packageRules": [
{
"packagePatterns": ["^golang.org/x/"],
"schedule": ["on the first day of the month"]
}
]
}