diff --git a/common/common.go b/common/common.go index 278f68a2..0e6410c2 100644 --- a/common/common.go +++ b/common/common.go @@ -73,15 +73,24 @@ func DefaultNetwork(opts ...NetOption) (NetBoostrapper, error) { return nil, fin.Cleanup(err) } + libp2pOptions := []libp2p.Option{ + libp2p.Peerstore(pstore), + libp2p.ConnectionManager(config.ConnManager), + libp2p.DisableRelay(), + } + if config.AnnounceAddr != nil { + libp2pOptions = append(libp2pOptions, libp2p.AddrsFactory(func([]ma.Multiaddr) []ma.Multiaddr { + return []ma.Multiaddr{config.AnnounceAddr} + })) + } + h, d, err := ipfslite.SetupLibp2p( ctx, hostKey, nil, []ma.Multiaddr{config.HostAddr}, litestore, - libp2p.Peerstore(pstore), - libp2p.ConnectionManager(config.ConnManager), - libp2p.DisableRelay(), + libp2pOptions..., ) if err != nil { return nil, fin.Cleanup(err) @@ -292,6 +301,7 @@ type NetConfig struct { MongoUri string MongoDB string HostAddr ma.Multiaddr + AnnounceAddr ma.Multiaddr ConnManager cconnmgr.ConnManager GRPCServerOptions []grpc.ServerOption GRPCDialOptions []grpc.DialOption @@ -388,6 +398,13 @@ func WithNetDebug(enabled bool) NetOption { } } +func WithAnnounceAddr(addr ma.Multiaddr) NetOption { + return func(c *NetConfig) error { + c.AnnounceAddr = addr + return nil + } +} + type netBoostrapper struct { app.Net litepeer *ipfslite.Peer diff --git a/threadsd/main.go b/threadsd/main.go index af3c68a9..4f8063fd 100644 --- a/threadsd/main.go +++ b/threadsd/main.go @@ -34,6 +34,7 @@ func main() { repo := fs.String("repo", ".threads", "Repo location") hostAddrStr := fs.String("hostAddr", "/ip4/0.0.0.0/tcp/4006", "Libp2p host bind address") + announceAddrStr := fs.String("announceAddr", "", "Libp2p announce address") // Should be supplied as multiaddr, /ip4//tcp/4006 apiAddrStr := fs.String("apiAddr", "/ip4/127.0.0.1/tcp/6006", "gRPC API bind address") apiProxyAddrStr := fs.String("apiProxyAddr", "/ip4/127.0.0.1/tcp/6007", "gRPC API web proxy bind address") connLowWater := fs.Uint("connLowWater", 100, "Low watermark of libp2p connections that'll be maintained") @@ -60,6 +61,13 @@ func main() { if err != nil { log.Fatal(err) } + var announceAddr ma.Multiaddr + if *announceAddrStr != "" { + announceAddr, err = ma.NewMultiaddr(*announceAddrStr) + if err != nil { + log.Fatal(err) + } + } apiAddr, err := ma.NewMultiaddr(*apiAddrStr) if err != nil { log.Fatal(err) @@ -93,6 +101,9 @@ func main() { log.Debugf("repo: %v", *repo) log.Debugf("hostAddr: %v", *hostAddrStr) + if announceAddr != nil { + log.Debugf("announceAddr: %v", *announceAddrStr) + } log.Debugf("apiAddr: %v", *apiAddrStr) log.Debugf("apiProxyAddr: %v", *apiProxyAddrStr) log.Debugf("connLowWater: %v", *connLowWater) @@ -128,6 +139,9 @@ func main() { } else { opts = append(opts, common.WithNetBadgerPersistence(*repo)) } + if announceAddr != nil { + opts = append(opts, common.WithAnnounceAddr(announceAddr)) + } n, err := common.DefaultNetwork(opts...) if err != nil { log.Fatal(err)