Ver Fonte

Add docstrings for `use_relay`/`use_auto_relay`, add them to hivemind-cli (#547)

Alexander Borzunov há 2 anos atrás
pai
commit
03852a4c5d

+ 11 - 0
hivemind/hivemind_cli/run_dht.py

@@ -55,6 +55,15 @@ def main():
         help="Path to a private key file. If defined, makes the peer ID deterministic. "
         "If the file does not exist, writes a new private key to this file.",
     )
+    parser.add_argument(
+        "--no_relay",
+        action="store_false",
+        dest="use_relay",
+        help="Disable circuit relay functionality in libp2p (see https://docs.libp2p.io/concepts/nat/circuit-relay/)",
+    )
+    parser.add_argument(
+        "--use_auto_relay", action="store_true", help="Look for libp2p relays to reach peers behind NATs/firewalls"
+    )
     parser.add_argument(
         "--refresh_period", type=int, default=30, help="Period (in seconds) for fetching the keys from DHT"
     )
@@ -68,6 +77,8 @@ def main():
         announce_maddrs=args.announce_maddrs,
         use_ipfs=args.use_ipfs,
         identity_path=args.identity_path,
+        use_relay=args.use_relay,
+        use_auto_relay=args.use_auto_relay,
     )
     log_visible_maddrs(dht.get_visible_maddrs(), only_p2p=args.use_ipfs)
 

+ 9 - 0
hivemind/hivemind_cli/run_server.py

@@ -35,6 +35,15 @@ def main():
                         help='Multiaddrs to listen for external connections from other p2p instances; default: all IPv4 and TCP: /ip4/0.0.0.0/tcp/0')
     parser.add_argument('--announce_maddrs', type=list, nargs='+', default=None, required=False,
                         help='Visible multiaddrs the host announces for external connections from other p2p instances')
+    parser.add_argument(
+        "--no_relay",
+        action="store_false",
+        dest="use_relay",
+        help="Disable circuit relay functionality in libp2p (see https://docs.libp2p.io/concepts/nat/circuit-relay/)",
+    )
+    parser.add_argument(
+        "--use_auto_relay", action="store_true", help="Look for libp2p relays to reach peers behind NATs/firewalls"
+    )
 
     parser.add_argument('--num_handlers', type=int, default=None, required=False,
                         help='server will use this many processes to handle incoming requests')

+ 6 - 2
hivemind/p2p/p2p_daemon.py

@@ -127,9 +127,13 @@ class P2P:
         :param relay_hop_limit: sets the hop limit for hop relays
         :param startup_timeout: raise a P2PDaemonError if the daemon does not start in ``startup_timeout`` seconds
         :param tls: Enables TLS1.3 channel security protocol
-        :param use_auto_relay: enables autorelay
         :param use_ipfs: Bootstrap to IPFS (incompatible with initial_peers)
-        :param use_relay: enables circuit relay
+        :param use_relay: Enable circuit relay functionality in libp2p
+                          (see https://docs.libp2p.io/concepts/nat/circuit-relay/).
+                          If enabled (default), others can use you as a relay.
+                          If you want use relays yourself (to reach peers behind NATs/firewalls),
+                          please also pass `use_auto_relay=True`.
+        :param use_auto_relay: Look for libp2p relays to reach peers behind NATs/firewalls
         :param quic: Deprecated, has no effect since libp2p 0.17.0
         :param use_relay_hop: Deprecated, has no effect since libp2p 0.17.0
         :param use_relay_discovery: Deprecated, has no effect since libp2p 0.17.0