feat: Waku v2 bridge

Issue #12610
This commit is contained in:
Michal Iskierko
2023-11-12 13:29:38 +01:00
parent 56e7bd01ca
commit 6d31343205
6716 changed files with 1982502 additions and 5891 deletions

24
vendor/github.com/pion/mdns/.gitignore generated vendored Normal file
View File

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

89
vendor/github.com/pion/mdns/.golangci.yml generated vendored Normal file
View File

@@ -0,0 +1,89 @@
linters-settings:
govet:
check-shadowing: true
misspell:
locale: US
exhaustive:
default-signifies-exhaustive: true
gomodguard:
blocked:
modules:
- github.com/pkg/errors:
recommendations:
- errors
linters:
enable:
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
- bodyclose # checks whether HTTP response body is closed successfully
- deadcode # Finds unused code
- 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
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases
- exhaustive # check exhaustiveness of enum switch statements
- exportloopref # checks for pointers to enclosing loop variables
- 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
- golint # Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes
- 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
- 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
- noctx # noctx finds sending http request without context.Context
- scopelint # Scopelint checks for unpinned variables in go programs
- staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks
- structcheck # Finds unused struct fields
- stylecheck # Stylecheck is a replacement for golint
- 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
- varcheck # Finds unused global variables and constants
- whitespace # Tool for detection of leading and trailing whitespace
disable:
- 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.
- lll # Reports long lines
- 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
- prealloc # Finds slice declarations that could potentially be preallocated
- 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
- 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

21
vendor/github.com/pion/mdns/LICENSE generated vendored Normal file
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.

65
vendor/github.com/pion/mdns/README.md generated vendored Normal file
View File

@@ -0,0 +1,65 @@
<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://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>
</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)
* [Atsushi Watanabe](https://github.com/at-wat)
* [Doug Cone](https://github.com/nullvariable)
### License
MIT License - see [LICENSE](LICENSE) for full text

20
vendor/github.com/pion/mdns/codecov.yml generated vendored Normal file
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/**/*"

27
vendor/github.com/pion/mdns/config.go generated vendored Normal file
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 often 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
}

317
vendor/github.com/pion/mdns/conn.go generated vendored Normal file
View File

@@ -0,0 +1,317 @@
package mdns
import (
"context"
"errors"
"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()
defer ticker.Stop()
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() { //nolint gocognit
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 errors.Is(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 errors.Is(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:]...)
}
}
}
}()
}
}

10
vendor/github.com/pion/mdns/errors.go generated vendored Normal file
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")
)

2
vendor/github.com/pion/mdns/mdns.go generated vendored Normal file
View File

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

15
vendor/github.com/pion/mdns/renovate.json generated vendored Normal file
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"]
}
]
}