Skip to content

Commit 6812d18

Browse files
committed
libp2p: Enable relay service
1 parent c631eb4 commit 6812d18

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

rolling-shutter/p2p/p2p.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/pkg/errors"
1919
"github.com/rs/zerolog/log"
2020

21+
"github.com/shutter-network/rolling-shutter/rolling-shutter/cmd/shversion"
2122
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/encodeable/address"
2223
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/encodeable/env"
2324
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/encodeable/keys"
@@ -198,8 +199,10 @@ func createHost(
198199
options := []libp2p.Option{
199200
libp2p.Identity(&config.PrivKey.Key),
200201
libp2p.ListenAddrs(config.ListenAddrs...),
202+
libp2p.UserAgent(fmt.Sprintf("shutter-network/%s", shversion.VersionShort())),
201203
libp2p.ConnectionManager(connectionManager),
202204
libp2p.ProtocolVersion(protocolVersion),
205+
libp2p.EnableRelay(),
203206
libp2p.Ping(true),
204207
}
205208

@@ -213,6 +216,17 @@ func createHost(
213216
// Attempt to open ports using uPNP for NATed hosts.
214217
libp2p.NATPortMap(),
215218
)
219+
if len(config.BootstrapPeers) > 0 {
220+
options = append(options,
221+
libp2p.EnableAutoRelayWithStaticRelays(config.BootstrapPeers),
222+
)
223+
}
224+
if config.IsBootstrapNode {
225+
// Enable the Relay service on bootstrap nodes so other peers can connect through us
226+
options = append(options,
227+
libp2p.EnableRelayService(),
228+
)
229+
}
216230
}
217231

218232
p2pHost, err := libp2p.New(options...)

0 commit comments

Comments
 (0)