Skip to content

Commit

Permalink
feat(rdvp): Add nat & relay service on rdvp
Browse files Browse the repository at this point in the history
  • Loading branch information
gfanton committed Apr 16, 2020
1 parent 09bb2b2 commit f70fb2f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
1 change: 1 addition & 0 deletions go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 10 additions & 9 deletions go/cmd/berty/main.go
Expand Up @@ -52,7 +52,7 @@ import (

// Default ipfs bootstrap & rendezvous point server

const RendezVousServer = "/ip4/163.172.143.28/tcp/4040/p2p/QmeMTMQoLxmMwGZQ5YyuPQn6cE9DbHucwZQk7TaoKodMcY"
const RendezVousServer = "/ip4/167.99.223.55/tcp/4040/p2p/QmTo3RS6Uc8aCS5Cxx8EBHkNCe4C7vKRanbMEboxkA92Cn"

var DefaultBootstrap = ipfs_cfg.DefaultBootstrapAddresses

Expand Down Expand Up @@ -194,14 +194,15 @@ func main() {
monitorPeers(ctx, logger, node.PeerHost, rdvpeer.ID)
}()

for {
if err := node.PeerHost.Connect(ctx, *rdvpeer); err != nil {
logger.Error("cannot dial rendez-vous point: %v", zap.Error(err))
} else {
break
}
time.Sleep(time.Second)
}
// uncomment this to force connection with rdvp
// for {
// if err := node.PeerHost.Connect(ctx, *rdvpeer); err != nil {
// logger.Error("cannot dial rendez-vous point: %v", zap.Error(err))
// } else {
// break
// }
// time.Sleep(time.Second)
// }

routing := <-crouting
defer routing.IpfsDHT.Close()
Expand Down
11 changes: 11 additions & 0 deletions go/cmd/rdvp/main.go
Expand Up @@ -15,6 +15,7 @@ import (
"berty.tech/berty/v2/go/internal/ipfsutil"
"berty.tech/berty/v2/go/pkg/errcode"
libp2p "github.com/libp2p/go-libp2p"
libp2p_cicuit "github.com/libp2p/go-libp2p-circuit"
libp2p_ci "github.com/libp2p/go-libp2p-core/crypto" // nolint:staticcheck
libp2p_host "github.com/libp2p/go-libp2p-core/host"
libp2p_peer "github.com/libp2p/go-libp2p-core/peer"
Expand Down Expand Up @@ -128,9 +129,19 @@ func main() {

// init p2p host
host, err := libp2p.New(ctx,
// default tpt + quic
libp2p.DefaultTransports,
libp2p.Transport(libp2p_quic.NewTransport),

// Nat & Relay service
libp2p.EnableNATService(),
libp2p.DefaultStaticRelays(),
libp2p.EnableRelay(libp2p_cicuit.OptHop),

// swarm listeners
libp2p.ListenAddrs(listeners...),

// identity
libp2p.Identity(priv),
)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions go/internal/ipfsutil/cfg.go
Expand Up @@ -82,6 +82,7 @@ func CreateRepo(dstore ipfs_datastore.Batching, opts *BuildOpts) (ipfs_repo.Repo

fmt.Printf("IPFS listening on %s\n", strings.Join(c.Addresses.Swarm, ", "))

c.Experimental.QUIC = true
c.Identity.PeerID = pid.Pretty()
c.Identity.PrivKey = base64.StdEncoding.EncodeToString(privkeyb)
c.Discovery.MDNS.Enabled = true
Expand All @@ -90,9 +91,7 @@ func CreateRepo(dstore ipfs_datastore.Batching, opts *BuildOpts) (ipfs_repo.Repo
c.Swarm.EnableAutoNATService = true
c.Swarm.EnableAutoRelay = true

if !opts.ClientMode {
c.Swarm.EnableRelayHop = true
}
c.Swarm.EnableRelayHop = false

return &ipfs_repo.Mock{
D: dstore,
Expand Down

0 comments on commit f70fb2f

Please sign in to comment.