-
-
Save MarcoPolo/b22203897c9294baca9f22981a42e5ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/examples/chat-with-rendezvous/chat.go b/examples/chat-with-rendezvous/chat.go | |
index 2b426297..67318aa1 100644 | |
--- a/examples/chat-with-rendezvous/chat.go | |
+++ b/examples/chat-with-rendezvous/chat.go | |
@@ -114,16 +114,13 @@ func main() { | |
// DHT, so that the bootstrapping node of the DHT can go down without | |
// inhibiting future peer discovery. | |
ctx := context.Background() | |
- kademliaDHT, err := dht.New(ctx, host) | |
+ kademliaDHT, err := dht.New(ctx, host, dht.Mode(dht.ModeServer)) | |
if err != nil { | |
panic(err) | |
} | |
- // Bootstrap the DHT. In the default configuration, this spawns a Background | |
- // thread that will refresh the peer table every five minutes. | |
- logger.Debug("Bootstrapping the DHT") | |
- if err = kademliaDHT.Bootstrap(ctx); err != nil { | |
- panic(err) | |
+ if config.isBootstrap { | |
+ select {} | |
} | |
// Let's connect to the bootstrap nodes first. They will tell us about the | |
@@ -143,6 +140,13 @@ func main() { | |
} | |
wg.Wait() | |
+ // Bootstrap the DHT. In the default configuration, this spawns a Background | |
+ // thread that will refresh the peer table every five minutes. | |
+ logger.Debug("Bootstrapping the DHT") | |
+ if err = kademliaDHT.Bootstrap(ctx); err != nil { | |
+ panic(err) | |
+ } | |
+ | |
// We use a rendezvous point "meet me here" to announce our location. | |
// This is like telling your friends to meet you at the Eiffel Tower. | |
logger.Info("Announcing ourselves...") | |
diff --git a/examples/chat-with-rendezvous/flags.go b/examples/chat-with-rendezvous/flags.go | |
index a2e8ed1d..ac8de858 100644 | |
--- a/examples/chat-with-rendezvous/flags.go | |
+++ b/examples/chat-with-rendezvous/flags.go | |
@@ -44,6 +44,7 @@ type Config struct { | |
BootstrapPeers addrList | |
ListenAddresses addrList | |
ProtocolID string | |
+ isBootstrap bool | |
} | |
func ParseFlags() (Config, error) { | |
@@ -53,6 +54,7 @@ func ParseFlags() (Config, error) { | |
flag.Var(&config.BootstrapPeers, "peer", "Adds a peer multiaddress to the bootstrap list") | |
flag.Var(&config.ListenAddresses, "listen", "Adds a multiaddress to the listen list") | |
flag.StringVar(&config.ProtocolID, "pid", "/chat/1.1.0", "Sets a protocol id for stream headers") | |
+ flag.BoolVar(&config.isBootstrap, "is_bootstrap", false, "Sets a protocol id for stream headers") | |
flag.Parse() | |
if len(config.BootstrapPeers) == 0 { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment