Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't hole punch if either peer is behind a Symmetric NAT #1046

Closed
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
78ce16b
emit NAT device type
aarshkshah1992 Jan 27, 2021
0b45239
unit tests
aarshkshah1992 Jan 27, 2021
3566bfd
emit event for NAT Device Type
aarshkshah1992 Jan 28, 2021
29d4987
updated deps
aarshkshah1992 Jan 28, 2021
5484ccb
refactor tcp-udp NAT events
aarshkshah1992 Feb 1, 2021
1537769
update go ver
aarshkshah1992 Feb 1, 2021
c2295d5
go mod tidy
aarshkshah1992 Feb 1, 2021
2296117
update deps
aarshkshah1992 Feb 1, 2021
d337499
fix multiple events
aarshkshah1992 Feb 1, 2021
1956fea
Implement support for simultaneous open
vyzo Aug 26, 2019
cfef141
updated deps
aarshkshah1992 Jan 12, 2021
10adf33
simultaneous connect
aarshkshah1992 Jan 15, 2021
ef26854
added tests
aarshkshah1992 Jan 15, 2021
ae61f65
added tests
aarshkshah1992 Jan 15, 2021
0b0b410
more testing
aarshkshah1992 Jan 15, 2021
90cd9bb
host changes
aarshkshah1992 Jan 16, 2021
2603920
test scripts
aarshkshah1992 Jan 18, 2021
e868d73
default listen
aarshkshah1992 Jan 18, 2021
431a9a6
addrs
aarshkshah1992 Jan 18, 2021
fa9994c
relay server
aarshkshah1992 Jan 18, 2021
001aa52
rela server
aarshkshah1992 Jan 18, 2021
14ef1ec
relay server
aarshkshah1992 Jan 18, 2021
450d431
relay server
aarshkshah1992 Jan 18, 2021
36ca4a7
addrs
aarshkshah1992 Jan 18, 2021
1bdb86c
testing
aarshkshah1992 Jan 18, 2021
1d6d07f
server code
aarshkshah1992 Jan 18, 2021
5ecac86
server code
aarshkshah1992 Jan 18, 2021
d9d7e6a
more changes
aarshkshah1992 Jan 19, 2021
dcf822c
upated swarm
aarshkshah1992 Jan 19, 2021
2ee5344
clean-up
aarshkshah1992 Jan 21, 2021
46ef4d8
cleaned up PR
aarshkshah1992 Jan 21, 2021
749086f
rebased to have NAT type event
aarshkshah1992 Feb 2, 2021
37141ec
better logging
aarshkshah1992 Feb 2, 2021
5bf6a8f
remove log
aarshkshah1992 Feb 2, 2021
837edb0
log connection as well
aarshkshah1992 Feb 2, 2021
35b7b8a
remove chatty logs
aarshkshah1992 Feb 2, 2021
9482582
fix go-multiaddr
aarshkshah1992 Feb 3, 2021
eddb65c
fix logging
aarshkshah1992 Feb 3, 2021
6ec9163
event driven hole punching
aarshkshah1992 Feb 3, 2021
d0d527c
always dial public addrs
aarshkshah1992 Feb 3, 2021
651ae86
address review
aarshkshah1992 Feb 18, 2021
9b483aa
rebased PR
aarshkshah1992 Feb 19, 2021
3e9dc38
fix typo
aarshkshah1992 Feb 19, 2021
ea96e13
fixed errs
aarshkshah1992 Feb 19, 2021
792ff75
fixed errs
aarshkshah1992 Feb 19, 2021
6efab25
save NAT type to peerstore
aarshkshah1992 Feb 19, 2021
00bd3a7
added a test
aarshkshah1992 Feb 19, 2021
48350b4
removed double init
aarshkshah1992 Feb 19, 2021
9267948
finished merging
aarshkshah1992 Feb 23, 2021
b553c16
unit tests
aarshkshah1992 Feb 24, 2021
f981b25
fixed races
aarshkshah1992 Feb 24, 2021
a3fee65
update deps due to license
ZBoIsHere Aug 2, 2021
9b67b75
Merge pull request #1146 from ZBoIsHere/feat/evt-based-hole-punching-…
Stebalien Aug 2, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ os:
language: go

go:
- 1.13.x
- 1.14.x

env:
global:
Expand Down
18 changes: 13 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"context"
"crypto/rand"
"errors"
"fmt"
"time"

Expand Down Expand Up @@ -92,6 +93,8 @@ type Config struct {
EnableAutoRelay bool
AutoNATConfig
StaticRelays []peer.AddrInfo

EnableHolePunching bool
}

func (cfg *Config) makeSwarm(ctx context.Context) (*swarm.Swarm, error) {
Expand Down Expand Up @@ -185,12 +188,17 @@ func (cfg *Config) NewNode(ctx context.Context) (host.Host, error) {
return nil, err
}

if cfg.EnableHolePunching && !cfg.Relay {
return nil, errors.New("cannot enable hole punching; relay is not enabled")
}

h, err := bhost.NewHost(ctx, swrm, &bhost.HostOpts{
ConnManager: cfg.ConnManager,
AddrsFactory: cfg.AddrsFactory,
NATManager: cfg.NATManager,
EnablePing: !cfg.DisablePing,
UserAgent: cfg.UserAgent,
ConnManager: cfg.ConnManager,
AddrsFactory: cfg.AddrsFactory,
NATManager: cfg.NATManager,
EnablePing: !cfg.DisablePing,
UserAgent: cfg.UserAgent,
EnableHolePunching: cfg.EnableHolePunching,
})

if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions config/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ func SecurityConstructor(security interface{}) (SecC, error) {
}, nil
}

func makeInsecureTransport(id peer.ID, privKey crypto.PrivKey) sec.SecureTransport {
func makeInsecureTransport(id peer.ID, privKey crypto.PrivKey) sec.SecureMuxer {
secMuxer := new(csms.SSMuxer)
secMuxer.AddTransport(insecure.ID, insecure.NewWithIdentity(id, privKey))
return secMuxer
}

func makeSecurityTransport(h host.Host, tpts []MsSecC) (sec.SecureTransport, error) {
func makeSecurityTransport(h host.Host, tpts []MsSecC) (sec.SecureMuxer, error) {
secMuxer := new(csms.SSMuxer)
transportSet := make(map[string]struct{}, len(tpts))
for _, tptC := range tpts {
Expand Down
27 changes: 17 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,51 @@ module github.com/libp2p/go-libp2p
go 1.12

require (
github.com/gogo/protobuf v1.3.1
github.com/gogo/protobuf v1.3.2
github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9 // indirect
github.com/golang/protobuf v1.4.3 // indirect
github.com/google/gopacket v1.1.18 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/ipfs/go-cid v0.0.7
github.com/ipfs/go-datastore v0.4.4
github.com/ipfs/go-datastore v0.4.5
github.com/ipfs/go-detect-race v0.0.1
github.com/ipfs/go-ipfs-util v0.0.2
github.com/ipfs/go-log v1.0.4
github.com/jbenet/go-cienv v0.1.0
github.com/jbenet/goprocess v0.1.4
github.com/jpillora/backoff v1.0.0
github.com/libp2p/go-addr-util v0.0.2
github.com/libp2p/go-conn-security-multistream v0.2.0
github.com/libp2p/go-conn-security-multistream v0.2.1-0.20210121071012-12bfa39db1aa
github.com/libp2p/go-eventbus v0.2.1
github.com/libp2p/go-libp2p-autonat v0.4.0
github.com/libp2p/go-libp2p-blankhost v0.2.0
github.com/libp2p/go-libp2p-circuit v0.4.0
github.com/libp2p/go-libp2p-core v0.8.0
github.com/libp2p/go-libp2p-core v0.8.1-0.20210202093214-7116e2835272
github.com/libp2p/go-libp2p-discovery v0.5.0
github.com/libp2p/go-libp2p-loggables v0.1.0
github.com/libp2p/go-libp2p-mplex v0.4.1
github.com/libp2p/go-libp2p-nat v0.0.6
github.com/libp2p/go-libp2p-netutil v0.1.0
github.com/libp2p/go-libp2p-noise v0.1.1
github.com/libp2p/go-libp2p-peerstore v0.2.6
github.com/libp2p/go-libp2p-swarm v0.4.0
github.com/libp2p/go-libp2p-swarm v0.4.1-0.20210119090647-fca9031125ef
github.com/libp2p/go-libp2p-testing v0.4.0
github.com/libp2p/go-libp2p-tls v0.1.3
github.com/libp2p/go-libp2p-transport-upgrader v0.4.0
github.com/libp2p/go-libp2p-transport-upgrader v0.4.1-0.20210121071125-d8a8d95aceff
github.com/libp2p/go-libp2p-yamux v0.5.1
github.com/libp2p/go-msgio v0.0.6
github.com/libp2p/go-netroute v0.1.3
github.com/libp2p/go-stream-muxer-multistream v0.3.0
github.com/libp2p/go-tcp-transport v0.2.1
github.com/libp2p/go-ws-transport v0.4.0
github.com/miekg/dns v1.1.31 // indirect
github.com/multiformats/go-multiaddr v0.3.1
github.com/multiformats/go-multiaddr v0.3.2-0.20210121092939-900a4d7ebbca
github.com/multiformats/go-multiaddr-dns v0.2.0
github.com/multiformats/go-multistream v0.2.0
github.com/onsi/ginkgo v1.12.1 // indirect
github.com/multiformats/go-multistream v0.2.1-0.20210121060916-85f04aad069c
github.com/onsi/ginkgo v1.14.0 // indirect
github.com/stretchr/testify v1.6.1
github.com/whyrusleeping/mdns v0.0.0-20190826153040-b9b60ed33aa9
google.golang.org/protobuf v1.23.0 // indirect
go.uber.org/zap v1.16.0 // indirect
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a // indirect
google.golang.org/protobuf v1.25.0 // indirect
)