From b7ab52ccfea7c54fc5a213459fcf4a0a5d5852a6 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 16 Jul 2019 13:52:11 -0700 Subject: [PATCH 1/4] Configure bootstrap nodes to serve as a relay --- Gopkg.lock | 2 ++ cmd/mesh-bootstrap/main.go | 25 +++++++++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 5c2f9ed68..99aa4ab9c 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -1264,6 +1264,7 @@ "github.com/jpillora/backoff", "github.com/libp2p/go-libp2p", "github.com/libp2p/go-libp2p-autonat-svc", + "github.com/libp2p/go-libp2p-circuit", "github.com/libp2p/go-libp2p-connmgr", "github.com/libp2p/go-libp2p-crypto", "github.com/libp2p/go-libp2p-discovery", @@ -1275,6 +1276,7 @@ "github.com/libp2p/go-libp2p-peerstore", "github.com/libp2p/go-libp2p-protocol", "github.com/libp2p/go-libp2p-pubsub", + "github.com/libp2p/go-libp2p-routing", "github.com/multiformats/go-multiaddr", "github.com/multiformats/go-multiaddr-dns", "github.com/ocdogan/rbt", diff --git a/cmd/mesh-bootstrap/main.go b/cmd/mesh-bootstrap/main.go index c88ac2528..b637061d9 100644 --- a/cmd/mesh-bootstrap/main.go +++ b/cmd/mesh-bootstrap/main.go @@ -16,10 +16,14 @@ import ( "github.com/0xProject/0x-mesh/p2p" libp2p "github.com/libp2p/go-libp2p" autonat "github.com/libp2p/go-libp2p-autonat-svc" + relay "github.com/libp2p/go-libp2p-circuit" connmgr "github.com/libp2p/go-libp2p-connmgr" p2pcrypto "github.com/libp2p/go-libp2p-crypto" + host "github.com/libp2p/go-libp2p-host" + dht "github.com/libp2p/go-libp2p-kad-dht" p2pnet "github.com/libp2p/go-libp2p-net" peer "github.com/libp2p/go-libp2p-peer" + routing "github.com/libp2p/go-libp2p-routing" ma "github.com/multiformats/go-multiaddr" "github.com/plaid/go-envvar/envvar" log "github.com/sirupsen/logrus" @@ -73,6 +77,18 @@ func main() { log.WithField("error", err).Fatal("could not initialize private key") } + // We need to declare the newDHT function ahead of time so we can use it in + // the libp2p.Routing option. + var kadDHT *dht.IpfsDHT + newDHT := func(h host.Host) (routing.PeerRouting, error) { + var err error + kadDHT, err = p2p.NewDHT(ctx, h) + if err != nil { + log.WithField("error", err).Fatal("could not create DHT") + } + return kadDHT, err + } + // Set up the transport and the host. // Note: 0.0.0.0 will use all available addresses. hostAddr, err := ma.NewMultiaddr(fmt.Sprintf("/ip4/0.0.0.0/tcp/%d", config.P2PListenPort)) @@ -84,6 +100,9 @@ func main() { libp2p.ListenAddrs(hostAddr), libp2p.Identity(privKey), libp2p.ConnectionManager(connManager), + libp2p.EnableRelay(relay.OptHop), + libp2p.EnableAutoRelay(), + libp2p.Routing(newDHT), } basicHost, err := libp2p.New(ctx, opts...) if err != nil { @@ -101,12 +120,6 @@ func main() { log.WithField("error", err).Fatal("could not enable AutoNAT service") } - // Set up DHT for peer discovery. - kadDHT, err := p2p.NewDHT(ctx, basicHost) - if err != nil { - log.WithField("error", err).Fatal("could not create DHT") - } - // Initialize the DHT and then connect to the other bootstrap nodes. if err := kadDHT.Bootstrap(ctx); err != nil { log.WithField("error", err).Fatal("could not bootstrap DHT") From b8aa7466e109b0089e08f3bf7c938cd72babcbaa Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 16 Jul 2019 13:30:09 -0700 Subject: [PATCH 2/4] Use AddrsFactory to advertise public IP addresses in mesh-bootstrap --- cmd/mesh-bootstrap/main.go | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/cmd/mesh-bootstrap/main.go b/cmd/mesh-bootstrap/main.go index b637061d9..dd141849c 100644 --- a/cmd/mesh-bootstrap/main.go +++ b/cmd/mesh-bootstrap/main.go @@ -9,6 +9,7 @@ import ( "context" "fmt" "os" + "strings" "time" "github.com/0xProject/0x-mesh/keys" @@ -47,10 +48,12 @@ const ( // Config contains configuration options for a Node. type Config struct { // Verbosity is the logging verbosity: 0=panic, 1=fatal, 2=error, 3=warn, 4=info, 5=debug 6=trace - Verbosity int `envvar:"VERBOSITY" default:"6"` - // P2PListenPort is the port on which to listen for new connections. It can be - // set to 0 to make the OS automatically choose any available port. - P2PListenPort int `envvar:"P2P_LISTEN_PORT" default:"0"` + Verbosity int `envvar:"VERBOSITY" default:"5"` + // P2PListenPort is the port on which to listen for new connections. + P2PListenPort int `envvar:"P2P_LISTEN_PORT"` + // PublicIPAddrs is a comma separated list of public IPv4 addresses at which + // the bootstrap node is accessible. + PublicIPAddrs string `envvar:"PUBLIC_IP_ADDRS"` // PrivateKey path is the path to a private key file which will be used for // signing messages and generating a peer ID. PrivateKeyPath string `envvar:"PRIVATE_KEY_PATH" default:"0x_mesh/keys/privkey"` @@ -88,6 +91,17 @@ func main() { } return kadDHT, err } + // Parse advertiseAddresses from Public IPs + ipAddrs := strings.Split(config.PublicIPAddrs, ",") + advertiseAddrs := make([]ma.Multiaddr, len(ipAddrs)) + for i, ipAddr := range ipAddrs { + maddrString := fmt.Sprintf("/ip4/%s/tcp/%d", ipAddr, config.P2PListenPort) + ma, err := ma.NewMultiaddr(maddrString) + if err != nil { + log.Fatal(err) + } + advertiseAddrs[i] = ma + } // Set up the transport and the host. // Note: 0.0.0.0 will use all available addresses. @@ -103,6 +117,7 @@ func main() { libp2p.EnableRelay(relay.OptHop), libp2p.EnableAutoRelay(), libp2p.Routing(newDHT), + libp2p.AddrsFactory(newAddrsFactory(advertiseAddrs)), } basicHost, err := libp2p.New(ctx, opts...) if err != nil { @@ -143,7 +158,8 @@ func main() { } log.WithFields(map[string]interface{}{ - "addrs": basicHost.Addrs(), + "addrs": basicHost.Addrs(), + "config": config, }).Info("started bootstrap node") // Sleep until stopped @@ -196,3 +212,9 @@ func (n *notifee) OpenedStream(network p2pnet.Network, stream p2pnet.Stream) {} // ClosedStream is called when a stream closed func (n *notifee) ClosedStream(network p2pnet.Network, stream p2pnet.Stream) {} + +func newAddrsFactory(adverticeAddresses []ma.Multiaddr) func([]ma.Multiaddr) []ma.Multiaddr { + return func([]ma.Multiaddr) []ma.Multiaddr { + return adverticeAddresses + } +} From 8ed9620398bf030148ae84c8a9678919974dbe72 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 16 Jul 2019 14:17:33 -0700 Subject: [PATCH 3/4] Fix typo --- cmd/mesh-bootstrap/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/mesh-bootstrap/main.go b/cmd/mesh-bootstrap/main.go index dd141849c..61b4ba0ea 100644 --- a/cmd/mesh-bootstrap/main.go +++ b/cmd/mesh-bootstrap/main.go @@ -213,8 +213,8 @@ func (n *notifee) OpenedStream(network p2pnet.Network, stream p2pnet.Stream) {} // ClosedStream is called when a stream closed func (n *notifee) ClosedStream(network p2pnet.Network, stream p2pnet.Stream) {} -func newAddrsFactory(adverticeAddresses []ma.Multiaddr) func([]ma.Multiaddr) []ma.Multiaddr { +func newAddrsFactory(advertiseAddrs []ma.Multiaddr) func([]ma.Multiaddr) []ma.Multiaddr { return func([]ma.Multiaddr) []ma.Multiaddr { - return adverticeAddresses + return advertiseAddrs } } From 7b519b9b07bcb49542f60f44b96654fdbec3ff4e Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 16 Jul 2019 16:03:38 -0700 Subject: [PATCH 4/4] Set version to 1.0.3-beta --- DEPLOYMENT.md | 2 +- DEVELOPMENT.md | 2 +- README.md | 4 ++-- USAGE.md | 2 +- core/core.go | 2 +- examples/beta_telemetry_node/docker-compose.yml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/DEPLOYMENT.md b/DEPLOYMENT.md index 66dc31247..3f0178de3 100644 --- a/DEPLOYMENT.md +++ b/DEPLOYMENT.md @@ -1,4 +1,4 @@ -[![Version](https://img.shields.io/badge/version-1.0.2--beta-orange.svg)](https://github.com/0xProject/0x-mesh/releases) +[![Version](https://img.shields.io/badge/version-1.0.3--beta-orange.svg)](https://github.com/0xProject/0x-mesh/releases) # 0x Mesh Deployment Guide diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 9f7dbc298..465119a8b 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -1,4 +1,4 @@ -[![Version](https://img.shields.io/badge/version-1.0.2--beta-orange.svg)](https://github.com/0xProject/0x-mesh/releases) +[![Version](https://img.shields.io/badge/version-1.0.3--beta-orange.svg)](https://github.com/0xProject/0x-mesh/releases) # 0x Mesh Development Guide diff --git a/README.md b/README.md index ea90ea4ed..38cd16e10 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Version](https://img.shields.io/badge/version-1.0.2--beta-orange.svg)](https://github.com/0xProject/0x-mesh/releases) +[![Version](https://img.shields.io/badge/version-1.0.3--beta-orange.svg)](https://github.com/0xProject/0x-mesh/releases) [![Chat with us on Discord](https://img.shields.io/badge/chat-Discord-blueViolet.svg)](https://discord.gg/HF7fHwk) [![GoDoc](https://godoc.org/github.com/0xProject/0x-mesh?status.svg)](https://godoc.org/github.com/0xProject/0x-mesh) [![Circle CI](https://img.shields.io/circleci/project/0xProject/0x-mesh/master.svg)](https://circleci.com/gh/0xProject/0x-mesh/tree/master) @@ -12,7 +12,7 @@ ## Versions -You are looking at the documentation for version `1.0.2-beta`. To see the +You are looking at the documentation for version `1.0.3-beta`. To see the documentation for a different version, visit the [Releases Page](https://github.com/0xProject/0x-mesh/releases). diff --git a/USAGE.md b/USAGE.md index 1f5b8e1a2..91a479353 100644 --- a/USAGE.md +++ b/USAGE.md @@ -1,4 +1,4 @@ -[![Version](https://img.shields.io/badge/version-1.0.2--beta-orange.svg)](https://github.com/0xProject/0x-mesh/releases) +[![Version](https://img.shields.io/badge/version-1.0.3--beta-orange.svg)](https://github.com/0xProject/0x-mesh/releases) # 0x Mesh Usage Guide diff --git a/core/core.go b/core/core.go index 01af34220..be95b4407 100644 --- a/core/core.go +++ b/core/core.go @@ -107,7 +107,7 @@ func New(config Config) (*App, error) { log.SetLevel(log.Level(config.Verbosity)) log.WithFields(map[string]interface{}{ "config": config, - "version": "1.0.2-beta", + "version": "1.0.3-beta", }).Info("Initializing new core.App") if config.EthereumRPCMaxContentLength < maxOrderSizeInBytes { diff --git a/examples/beta_telemetry_node/docker-compose.yml b/examples/beta_telemetry_node/docker-compose.yml index a81043460..013a3bb04 100644 --- a/examples/beta_telemetry_node/docker-compose.yml +++ b/examples/beta_telemetry_node/docker-compose.yml @@ -2,7 +2,7 @@ version: '3' services: mesh: - image: 0xorg/mesh:1.0.2-beta + image: 0xorg/mesh:1.0.3-beta restart: always logging: driver: fluentd