Skip to content

Commit 19723fe

Browse files
aschmahmannhacdias
authored andcommitted
fix: enable holepunching
1 parent 4ff9f0e commit 19723fe

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

setup.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,22 @@ func Setup(ctx context.Context, cfg Config, key crypto.PrivKey, dnsCache *cached
134134
}
135135

136136
opts := []libp2p.Option{
137-
libp2p.ListenAddrStrings(cfg.ListenAddrs...),
138137
libp2p.NATPortMap(),
139138
libp2p.ConnectionManager(cmgr),
140139
libp2p.Identity(key),
141140
libp2p.BandwidthReporter(bwc),
142141
libp2p.DefaultTransports,
143142
libp2p.DefaultMuxers,
144143
libp2p.ResourceManager(bitswapRcMgr),
144+
libp2p.EnableHolePunching(),
145+
}
146+
147+
if len(cfg.ListenAddrs) == 0 {
148+
// Note: because the transports are set above we must also set the listen addresses
149+
// We need to set listen addresses in order for hole punching to work
150+
opts = append(opts, libp2p.DefaultListenAddrs)
151+
} else {
152+
opts = append(opts, libp2p.ListenAddrStrings(cfg.ListenAddrs...))
145153
}
146154

147155
if len(cfg.AnnounceAddrs) > 0 {

0 commit comments

Comments
 (0)